livequery

  • Owner: brandonaaron/livequery
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Live Query

This plugin is currently being rewritten. If you are looking for the old version, look at the 1.1.1 tag.

Live Query has been rewritten in version 2 to utilize DOM Mutation Observers or fallback to DOM Mutation Events. This covers a nice range of modern browsers and IE9 up. If you need to support less than IE9 then it will fallback to using behaviors to be notified of added and removed elements. This requires setting the $.livequery.htcPath so that it can load the included behavior file.

In the rewrite the event binding functionality has been removed since jQuery provides really nice event delegation. It now only supports passing in a matched and an optional unmatched function handler. These handlers are fired only when elements are added or removed from the DOM. This is slightly different from the original Live Query in that it would also monitor for slightly smaller changes that might make an element no longer match, such as a class name change.

Here is an example of how to use Live Query.

var $mylist = $('#mylist');
$mylist.livequery(
    'li', // the selector to match against
    function(elem) { // a matched function
        // this = elem = the li element just added to the DOM
    }, function(elem) { // an unmatched/expire function
        // this = elem = the li element just removed from the DOM or the live query was expired
    });

API

livequery

// selector: the selector to match against
// matchedFn: the function to execute when a new element is added to the DOM that matches
$(...).livequery( selector, matchedFn );

// selector: the selector to match against
// matchedFn: the function to execute when a new element is added to the DOM that matches
// unmatchedFn: the function to execute when a previously matched element is removed from the DOM
$(...).livequery( selector, matchedFn, unmatchFn );

expire

The first way will stop/expire all live queries associated with the selector.

// Stop/expire all live queries associated with the selector
$(...).expire( selector );

// Stop/expire all live queries associated with the selector and matchedFn
$(...).expire( selector, matchedFn );

// Stop/expire all live queries associated with the selector, matchedFn, and unmatchedFn
$(...).expire( selector, matchedFn, unmatchFn );

License

The Live Query plugin is licensed under the MIT License (LICENSE.txt).

Copyright (c) 2014 Brandon Aaron

Main metrics

Overview
Name With Ownerbrandonaaron/livequery
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2008-10-15 23:42:18
Pushed At2018-02-08 13:18:47
Last Commit At2014-04-10 09:09:13
Release Count1
Last Release Name1.1.1 (Posted on 2010-02-12 19:23:06)
First Release Name1.1.1 (Posted on 2010-02-12 19:23:06)
用户参与
Stargazers Count475
Watchers Count21
Fork Count195
Commits Count20
Has Issues Enabled
Issues Count23
Issue Open Count10
Pull Requests Count0
Pull Requests Open Count2
Pull Requests Close Count4
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private