/*!
 * Edit Row Form v1.0
 * Docs & License: http://coreleo.com/editrowform/
 * (c) 2015 Leon Samaroo
 */

!function(root, factory) {
	if (typeof define === 'function' && define.amd) {
		define([ 'jquery' ], factory);
	} 
	else {
		factory(root.jQuery);
	}
}( this, 

		function($){
		    $.editrowform = function(el, options){
		    	var editrowform
		    	
		        // To avoid scope issues, use 'base' instead of 'this'
		        // to reference this class from internal events and functions.
		        var base = this;
		        
		        // Access to jQuery and DOM versions of element
		        base.$el = $(el);
		        base.el = el;

		        // Add a reverse reference to the DOM object
		        base.$el.data("editrowform", base);
	
		        
		        base.init = function(){
		            base.options = $.extend({},$.editrowform.defaultOptions, options);
		            console.log( "init");
		        };
		        
		        
				base.getName = function(){
					 return "editrowform";
				};
				
				
				base.showForm = function(rowIndex){
					var row = _getRow( rowIndex );	
					$( 'td', row ).each( function( i, td) {
						var cellValue = _getCellValue( row, i );
						console.log( cellValue );
					});

				};
				 
				base.destroy = function(){
					 console.log( "destroy");
					 base.$el.removeData( "editrowform" );				 
				};
				
				base.getCellValue = function( cell ){
					return $(cell).html().trim();			 
				};
				
				
				function _getRow( rowIndex ){
					return $( 'tbody tr', base.el ).eq( rowIndex );
				};
				
				function _getCellValue( row, colIndex ){
					var cell = $( 'td', row )[colIndex];
					return base.getCellValue( cell );
				};
				
				base.template = "<div>leon</div>";

		    };
		    
		    
		    $.editrowform.defaultOptions = {
		    		getRowValue: ""
		    };
		    
		    
		    $.fn.editrowform = function(options){
		    	var args = Array.prototype.slice.call(arguments, 1); // for a possible method call
		    	var ret = this; // what this function will return (this jQuery object by default)
		    	var singleRes; // the returned value of this single method call

		        this.each(function(i, el){
		        	var element = $(el);
			    	var thisplugin = element.data('editrowform'); // get the existing plugin object (if any)
									
					// a method call
					if (typeof options === 'string') {
						if (thisplugin && $.isFunction(thisplugin[options])) {
							singleRes = thisplugin[options].apply(thisplugin, args);
							if (!i) {
								ret = singleRes; // record the first method call result
							}
						}					
					}
					// a new plugin initialization
					else {
						thisplugin = (new $.editrowform(el, options));
						thisplugin.init();
					}
		        });
		        
		        return ret;
		    };
		    
		}

);
@@ -539,16 +539,74 @@
  this;%0D%0A
+%09%09        var rowCount = 0;%0D%0A%09%09        var colCount = 0;%0D%0A
 %09%09      
@@ -601,32 +601,32 @@
 0;%0D%0A%09%09        %0D%0A
-
 %09%09        // Acc
@@ -721,16 +721,28 @@
 l = el;%0D
+%0A%09%09        %0D
 %0A%0D%0A%09%09   
@@ -989,29 +989,165 @@
     
-console.log( %22init%22);
+rowCount =  _getRowCount();%0D%0A%09%09            colCount =  _getColumnCount();%09%09            %0D%0A%09%09            console.log( %22rows=%22 + rowCount + %22 cols=%22 + colCount)
 %0D%0A%09%09
@@ -1532,40 +1532,8 @@
 )%7B%0D%0A
-%09%09%09%09%09 console.log( %22destroy%22);%0D%0A
 %09%09%09%09
@@ -1689,24 +1689,44 @@
 %0D%0A%09%09%09%09%0D%0A%09%09%09%09
+// private functions
 %0D%0A%09%09%09%09functi
@@ -1969,24 +1969,212 @@
 %09%09%09%09
-base.template = 
+function _getColumnCount()%7B%0D%0A%09%09%09%09%09return _getRow(0).length;%0D%0A%09%09%09%09%7D;%0D%0A%09%09%09%09%0D%0A%09%09%09%09function _getRowCount()%7B%0D%0A%09%09%09%09%09return $( 'tbody tr', base.el ).length;%0D%0A%09%09%09%09%7D;%0D%0A%09%09%09%09%0D%0A%09%09%09%09function _getFormTemplate()%7B%0D%0A%09%09%09%09%09
 %22%3Cdi
@@ -2188,16 +2188,23 @@
 /div%3E%22;%0D
+%0A%09%09%09%09%7D%0D
 %0A%0D%0A%09%09   

Store row and column count