Sha256: 335037dca7fb6c237015f4feac936b8c813088273270ef0077b740c8235bab60

Contents?: true

Size: 1.42 KB

Versions: 9

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

9 entries across 9 versions & 1 rubygems

Version Path
edge_framework-0.6.0 assets/js/edge/edge.collect.js
edge_framework-0.5.0 assets/js/edge/edge.collect.js
edge_framework-0.3.0 assets/js/edge/edge.collect.js
edge_framework-0.2.3 assets/js/edge/edge.collect.js
edge_framework-0.2.1 assets/js/edge/edge.collect.js
edge_framework-0.2.0 assets/js/edge/edge.collect.js
edge_framework-0.1.0 assets/js/edge/edge.collect.js
edge_framework-0.0.3 assets/js/edge/edge.collect.js
edge_framework-0.0.2 assets/js/edge/edge.collect.js