;(function ($, window, document, undefined) { "use strict"; Edge.libs.collect = { name : "collect", version : "1.0", settings : { ignoreIfBlank : true, debug : false, formula : {}, }, init: function( scope, method, options ) { console.log("collect"); // If scope isn't `document`, fetch the data if($(scope)[0] !== $(document)[0] ) { $.extend(true, this.settings, method); this.scope = scope; this.bundle = {}; this.fetch(); if(this.settings.debug) { console.log(this.bundle); } } }, fetch: function() { console.log("fetch"); var self = this; var $inputs = $(this.scope).find("input, select, textarea"); $inputs.each(function( index ){ var $this = $(this); var type = $this.attr("type"); var name = $this.attr("name"); // Split the name and create the object var table = name.split("_")[0]; var column = name.split("_")[1].split(/(?=[A-Z])/); column = column.join("_").toLowerCase(); // If doesn't exists, initialize it if(!self.bundle[table] ) { self.bundle[table] = {}; } // If checkbox or radio if(type==="checkbox" || type==="radio") { if($this.attr("checked") ) { //console.log($this.val() ); } } else { self.bundle[table][column] = $this.val(); } }); } } }(jQuery, this, this.document) );