Вход Регистрация
Файл: framework/thirdparty/jquery-livequery/jquery.livequery.js
Строк: 285
<?php
/*! 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(typefnfn2) {
        var 
self thisq;

        
// Handle different call patterns
        
if ($.isFunction(type))
            
fn2 fnfn typetype undefined;

        
// See if Live Query already exists
        
$.each( $.livequery.queries, function(iquery) {
            if ( 
self.selector == query.selector && self.context == query.context &&
                
type == query.type && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) )
                    
// Found the query, exit the each loop
                    
return (query) && false;
        });

        
// Create new Live Query if it wasn't found
        
|| new $.livequery(this.selectorthis.contexttypefnfn2);

        
// Make sure it is running
        
q.stopped false;

        
// Run it immediately for the first time
        
q.run();

        
// Contnue the chain
        
return this;
    },

    
expire: function(typefnfn2) {
        var 
self this;

        
// Handle different call patterns
        
if ($.isFunction(type))
            
fn2 fnfn typetype undefined;

        
// Find the Live Query based on arguments and stop it
        
$.each( $.livequery.queries, function(iquery) {
            if ( 
self.selector == query.selector && self.context == query.context &&
                (!
type || type == query.type) && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) && !this.stopped )
                    $.
livequery.stop(query.id);
        });

        
// Continue the chain
        
return this;
    }
});

$.
livequery = function(selectorcontexttypefnfn2) {
    
this.selector selector;
    
this.context  context;
    
this.type     type;
    
this.fn       fn;
    
this.fn2      fn2;
    
this.elements = [];
    
this.stopped  false;

    
// The id is the index of the Live Query in $.livequery.queries
    
this.id = $.livequery.queries.push(this)-1;

    
// Mark the functions for matching later on
    
fn.$lqguid fn.$lqguid || $.livequery.guid++;
    if (
fn2fn2.$lqguid fn2.$lqguid || $.livequery.guid++;

    
// Return the Live Query
    
return this;
};

$.
livequery.prototype = {
    
stop: function() {
        var 
query this;

        if ( 
this.type )
            
// Unbind all bound events
            
this.elements.unbind(this.typethis.fn);
        else if (
this.fn2)
            
// Call the second function for all matched elements
            
this.elements.each(function(iel) {
                
query.fn2.apply(el);
            });

        
// Clear out matched elements
        
this.elements = [];

        
// Stop the Live Query from running until restarted
        
this.stopped true;
    },

    
run: function() {
        
// Short-circuit if stopped
        
if ( this.stopped ) return;
        var 
query this;

        var 
oEls this.elements,
            
els  = $(this.selectorthis.context),
            
nEls els.not(oEls);

        
// Set elements to the latest set of matched elements
        
this.elements els;

        if (
this.type) {
            
// Bind events to newly matched elements
            
nEls.bind(this.typethis.fn);

            
// Unbind events to elements no longer matched
            
if (oEls.length 0)
                $.
each(oEls, function(iel) {
                    if ( $.
inArray(elels) < )
                        $.
event.remove(elquery.typequery.fn);
                });
        }
        else {
            
// Call the first function for newly matched elements
            
nEls.each(function() {
                
query.fn.apply(this);
            });

            
// Call the second function for elements no longer matched
            
if ( this.fn2 && oEls.length )
                $.
each(oEls, function(iel) {
                    if ( $.
inArray(elels) < )
                        
query.fn2.apply(el);
                });
        }
    }
};

$.
extend($.livequery, {
    
guid0,
    
queries: [],
    
queue: [],
    
runningfalse,
    
timeoutnull,

    
checkQueue: function() {
        if ( $.
livequery.running && $.livequery.queue.length ) {
            var 
length = $.livequery.queue.length;
            
// Run each Live Query currently in the queue
            
while ( length-- )
                $.
livequery.queries[ $.livequery.queue.shift() ].run();
        }
    },

    
pause: function() {
        
// Don't run anymore Live Queries until restarted
        
$.livequery.running false;
    },

    
play: function() {
        
// Restart Live Queries
        
$.livequery.running true;
        
// Request a run of the Live Queries
        
$.livequery.run();
    },

    
registerPlugin: function() {
        $.
eacharguments, function(i,n) {
            
// Short-circuit if the method doesn't exist
            
if (!$.fn[n]) return;

            
// Save a reference to the original method
            
var old = $.fn[n];

            
// Create a new method
            
$.fn[n] = function() {
                
// Call the original method
                
var old.apply(thisarguments);

                
// Request a run of the Live Queries
                
$.livequery.run();

                
// Return the original methods result
                
return r;
            }
        });
    },

    
run: function(id) {
        if (
id != undefined) {
            
// Put the particular Live Query in the queue if it doesn't already exist
            
if ( $.inArray(id, $.livequery.queue) < )
                $.
livequery.queue.pushid );
        }
        else
            
// Put each Live Query in the queue if it doesn't already exist
            
$.each( $.livequery.queries, function(id) {
                if ( $.
inArray(id, $.livequery.queue) < )
                    $.
livequery.queue.pushid );
            });

        
// Clear timeout if it already exists
        
if ($.livequery.timeoutclearTimeout($.livequery.timeout);
        
// Create a timeout to check the queue and actually run the Live Queries
        
$.livequery.timeout setTimeout($.livequery.checkQueue20);
    },

    
stop: function(id) {
        if (
id != undefined)
            
// Stop are particular Live Query
            
$.livequery.queriesid ].stop();
        else
            
// Stop all Live Queries
            
$.each( $.livequery.queries, function(id) {
                $.
livequery.queriesid ].stop();
            });
    }
});

// Register core DOM manipulation methods
$.livequery.registerPlugin('append''prepend''after''before''wrap''attr''removeAttr''addClass''removeClass''toggleClass''empty''remove''html');

// Run Live Queries when the Document is ready
$(function() { $.livequery.play(); });

})(
jQuery);
?>
Онлайн: 0
Реклама