-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.livequery.min.js
9 lines (9 loc) · 2.93 KB
/
jquery.livequery.min.js
1
2
3
4
5
6
7
8
9
/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
* Dual licensed under the MIT (MIT_LICENSE.txt)
* and GPL Version 2 (GPL_LICENSE.txt) licenses.
*
* Version: 1.1.1
* Requires jQuery 1.3+
* Docs: http://docs.jquery.com/Plugins/livequery
*/
(function($){$.extend($.fn,{livequery:function(b,c,d){var e=this,q;if($.isFunction(b))d=c,c=b,b=undefined;$.each($.livequery.queries,function(i,a){if(e.selector==a.selector&&e.context==a.context&&b==a.type&&(!c||c.$lqguid==a.fn.$lqguid)&&(!d||d.$lqguid==a.fn2.$lqguid))return(q=a)&&false});q=q||new $.livequery(this.selector,this.context,b,c,d);q.stopped=false;q.run();return this},expire:function(b,c,d){var e=this;if($.isFunction(b))d=c,c=b,b=undefined;$.each($.livequery.queries,function(i,a){if(e.selector==a.selector&&e.context==a.context&&(!b||b==a.type)&&(!c||c.$lqguid==a.fn.$lqguid)&&(!d||d.$lqguid==a.fn2.$lqguid)&&!this.stopped)$.livequery.stop(a.id)});return this}});$.livequery=function(a,b,c,d,e){this.selector=a;this.context=b;this.type=c;this.fn=d;this.fn2=e;this.elements=[];this.stopped=false;this.id=$.livequery.queries.push(this)-1;d.$lqguid=d.$lqguid||$.livequery.guid++;if(e)e.$lqguid=e.$lqguid||$.livequery.guid++;return this};$.livequery.prototype={stop:function(){var b=this;if(this.type)this.elements.unbind(this.type,this.fn);else if(this.fn2)this.elements.each(function(i,a){b.fn2.apply(a)});this.elements=[];this.stopped=true},run:function(){if(this.stopped)return;var b=this;var c=this.elements,els=$(this.selector,this.context),nEls=els.not(c);this.elements=els;if(this.type){nEls.bind(this.type,this.fn);if(c.length>0)$.each(c,function(i,a){if($.inArray(a,els)<0)$.event.remove(a,b.type,b.fn)})}else{nEls.each(function(){b.fn.apply(this)});if(this.fn2&&c.length>0)$.each(c,function(i,a){if($.inArray(a,els)<0)b.fn2.apply(a)})}}};$.extend($.livequery,{guid:0,queries:[],queue:[],running:false,timeout:null,checkQueue:function(){if($.livequery.running&&$.livequery.queue.length){var a=$.livequery.queue.length;while(a--)$.livequery.queries[$.livequery.queue.shift()].run()}},pause:function(){$.livequery.running=false},play:function(){$.livequery.running=true;$.livequery.run()},registerPlugin:function(){$.each(arguments,function(i,n){if(!$.fn[n])return;var a=$.fn[n];$.fn[n]=function(){var r=a.apply(this,arguments);$.livequery.run();return r}})},run:function(b){if(b!=undefined){if($.inArray(b,$.livequery.queue)<0)$.livequery.queue.push(b)}else $.each($.livequery.queries,function(a){if($.inArray(a,$.livequery.queue)<0)$.livequery.queue.push(a)});if($.livequery.timeout)clearTimeout($.livequery.timeout);$.livequery.timeout=setTimeout($.livequery.checkQueue,20)},stop:function(b){if(b!=undefined)$.livequery.queries[b].stop();else $.each($.livequery.queries,function(a){$.livequery.queries[a].stop()})}});$.livequery.registerPlugin('append','prepend','after','before','wrap','attr','removeAttr','addClass','removeClass','toggleClass','empty','remove','html');$(function(){$.livequery.play()})})(jQuery);