Sha256: 37af9ed4008186b8ff06731be75e2ec6faeb3d4eba413f4a3d8ebf31af6414fb

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

;(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) );

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
edge_framework-0.9.11 assets/js/edge/edge.collect.js
edge_framework-0.9.10 assets/js/edge/edge.collect.js
edge_framework-0.9.9 assets/js/edge/edge.collect.js
edge_framework-0.9.0 assets/js/edge/edge.collect.js
edge_framework-0.8.1 assets/js/edge/edge.collect.js
edge_framework-0.6.1 assets/js/edge/edge.collect.js