Return to Snippet

Revision: 12810
at March 30, 2009 21:24 by sliver


Updated Code
(function($) {
	$.fn.bindIntoStack = function(namespace, func, pos) {
		var evt = namespace.split('.').shift();

		return this
			.each(function() {
				var $this = $(this);

				$this.bind(namespace, func);

				var newOrder = new Array();

				$.each($this.data('events')[evt], function(k) {
					newOrder.push(k);
				});

				if (newOrder.length > pos + 1) {
					newOrder.splice(pos, 0, newOrder.pop());

					var evts = new Object();

					$.each(newOrder, function(k) {
						evts[this] = $this.data('events')[evt][this];
					});

					$this.data('events')[evt] = evts;
				}
			});
	};
})(jQuery);

(function($) {
	$.fn.reverseStack = function(namespace, func, pos) {
		var evt = namespace.split('.').shift();

		return this
			.each(function() {
				var $this = $(this);

				$this.bind(namespace, func);

				var revOrder = new Array();

				$.each($this.data('events')[evt], function(k) {
					revOrder.unshift(k);
				});

				if (revOrder.length > pos + 1) {
					var evts = new Object();

					$.each(revOrder, function(k) {
						evts[this] = $this.data('events')[evt][this];
					});

					$this.data('events')[evt] = evts;
				}
			});
	};
})(jQuery);

Revision: 12809
at March 30, 2009 21:23 by sliver


Updated Code
(function($) {
	$.fn.bindIntoStack = function(namespace, func, pos) {
		var evt = namespace.split('.').shift();

		return this
			.each(function() {
				var $this = $(this);

				$this.bind(namespace, func);

				var newOrder = new Array();

				$.each($this.data('events')[evt], function(k) {
					newOrder.push(k);
				});

				if (newOrder.length > pos + 1) {
					newOrder.splice(pos, 0, newOrder.pop());

					var evts = new Object();

					$.each(newOrder, function(k) {
						evts[this] = $this.data('events')[evt][this];
					});

					$this.data('events')[evt] = evts;
				}
			});
	};
})(jQuery);

Revision: 12808
at March 29, 2009 20:04 by sliver


Updated Code
(function($) {
	$.fn.bindIntoStack = function(namespace, func, pos) {
		var evt = namespace.split(".").shift();

		return this
			.each(function() {
				var $this = $(this);

				$this.bind(namespace, func);

				var newOrder = new Array();
				$.each($this.data('events')[evt], function(k) {
					newOrder.push($this.data('events')[evt][k]);
				});

				if (newOrder.length > pos + 1) {
					newOrder.splice(pos, 0, newOrder.pop());

					var i = 0;                     
					$.each($this.data('events')[evt], function(k) {
						$this.data('events')[evt][k] = newOrder[i++];
					});
				}
			});
	};
})(jQuery);

Revision: 12807
at March 29, 2009 17:21 by sliver


Initial Code
(function($) {
	$.fn.bindIntoStack = function(namespace, func, pos) {
		var evt = namespace.split(".").shift();

		return this
			.each(function() {
				var $this = $(this);

				$this.bind(evt, func);

				var newOrder = new Array()
				$.each($this.data('events')[evt], function(k) {
					newOrder.push($this.data('events')[evt][k]);
				});

				if (newOrder.length > pos + 1) {
					newOrder.splice(pos, 0, newOrder.pop());

					var i = 0;                     
					$.each($this.data('events')[evt], function(k) {
						$this.data('events')[evt][k] = newOrder[i++];
					});
				}
			});
	};
})(jQuery);

Initial URL

                                

Initial Description

                                

Initial Title
jQuery Event Stack Binder

Initial Tags

                                

Initial Language
jQuery