Code Monkey home page Code Monkey logo

livequery's Introduction

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

livequery's People

Contributors

brandonaaron avatar whoahbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

livequery's Issues

matchedFn and unmatchedFn order

Consider this code:-

refresh

<script> $(".widget").livequery(aFn,bFn); </script>

If I click the button, bFn should be called first, then aFn but livequery run aFn first.

$lqguid

With jquery 2.1.x I get this after downloading the latest livequery version:
Uncaught TypeError: Cannot read property '$lqguid' of undefined

This error keeps livequery from doing its job. Does livequery work in jquery v2.1.3?

Note working with rating.js

I have been using rating.js and it has been serving me well.
I am also having these ratings inside a tabs list created with ui.jquery.
I am using jquery 1.3 and 1.1 of livequery.
But now I am loading items with ajax and need it to load this jquery function when these items are loaded into the canvas.
When I try to add an item for livequery to look after I get a:
"""
fn is undefined
livequery()()jquery.l...equery.js (line 73)
livequery()()jquery.l...equery.js (line 29)
reverse()()profile (line 63)
F()()jquery.js (line 19)
init()([function(), function(), function(), 1 more...], function(), undefined)jquery.js (line 12)
F()()jquery.js (line 19)
F()()jquery.js (line 19)
[Break on this error] fn.$lqguid = fn.$lqguid || $.livequery.guid++;
"""
in Firebug and my js stops loading.
Any ideas on the issue?
Regards,
Jason

TypeError: d is undefined

Includes:

<script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.livequery.min.js"></script>

The call:

$('.input-mask-cep').livequery(function () {
        $(this).mask("99999-999");
    });

Result in firebug:

...his.id=a.livequery.queries.push(this)-1,d.$lqguid=d.$lqguid||a.livequery.guid++,...

livequery matchedFn executed multiple times for one element

<div class="foo">
this is the one and only foo element
</div>


$('.foo').livequery(function(){
console.log(' we have a NEW foo ');
});
// you see console.log happen

$('.foo').addClass('bar');
// you see console.log happen again, for the same element, even though it is not a new element.

Need a new maintainer?

I'd be happy to continue maintaining this plugin and update it to support the latest jQuery, pass JSLint, etc.

"n items remaining" with Internet Explorer 8 fallback mechanism

With Internet Explorer 8, the HTC fallback mechanism causes a lengthy "N items remaining" countdown in the status bar. The number corresponds to the amount of tags on the page. In my case, it is an admittedly large amount, at 770. It takes minutes before livequery is triggered, long after it should have. This happens even when a livequery isn't set.

With all modern browsers I tested, this plugin works very well. I really hope to be able to use it. It's very unfortunate to have to support Internet Explorer 8, but it is used on every machine at our large institution.

Very slow with jQuery 1.11.1 and livequery 1.3.4?

I was previously using jQuery 1.10.2 and livequery (1.3.4) was always firing instantaneously on my pages. I updated to jQuery 1.11.1 (currently last version of jQuery) and now livequery takes several seconds to fire for dynamically added elements on the same pages (my code hasn't change).

As a result I tried to switch to the last version of livequery, but this one doesn't fire for children of an added element (see #16).

I'm reverting to livequery 1.3.1 and jQuery 1.11.1 but thought could be usefull to report.

'livequery' should be an event

It would be really useful if one could bind livequery callbacks as event handlers. This would allow for namespacing.

An example:

$('div').bind('livequery.foo', function(event){ alert('foo') })
$('div').bind('livequery.bar', function(event){ alert('bar') })
$('

').appendTo(document.body)
// alerts foo, then alerts bar
$('div').unbind('livequery.foo')
$('
').appendTo(document.body)
// alerts only bar

Context not supported

In the following code, jquery should only select items that are children of #contextID.

    $("button, input:submit", "#contextID").livequery(function() {
        $(this).button();
    });

For some reason the context is being ignored by livequery. Everything works as expected if I change the code to

    $("#contextID button, #contextID input:submit").livequery(function() {
        $(this).button();
    });

Use jQuery 1.4 .live() when possible

Would it make sense for livequery to call .live() for events that .live() can support directly, such as click, submit, etc?

Also, would it be more efficient to refactor livequery to use .live() (with custom .bind() events) internally?

Can't seem to get expire to work...

I'm attaching the livequery in the following manner

$('body').livequery( '.clasname', function(){
console.info('Created in DOM');
console.log(arguments);
Sidekick.Events.trigger('expireWaitFor');
},function(){
console.info('Removed from DOM');
console.log(arguments);
});

then when an element is found I trigger the expire event as

$('body').expire( '.clasname' );

I run a test after wards and I continue to get logs firing whenever I add the class classname to anything within the body or take them out... so it seems that I'm not using the expire function properly...

matchedFn and unmatchedFn order

Consider this code:-

refresh

<script> $(".widget").livequery(aFn,bFn); </script>

If I click the button, bFn should be called first, then aFn but livequery run aFn first.

expire with namespace

Is it possible to expire livequery associations using jquery's event namespacing?

$('a').livequery('expire', 'click.namespace');

livequery fails to load in embedded Mozilla browser

I'm using the JWebBrowser embedded browser component (embedding Xulrunner 1-9.2) from the DJ Project. Somehow livequery is unable to load within this browser and my requests for long-lived selector matches therefore fail, although the same code runs on Chrome and Firefox.

I'm running JQuery, JQuery UI and the JQuery Media plugin all successfully within the XULRunner embedded window, giving me a rich browser experience which seems to be equivalent to a native browser environment, sadly with the exception of livequery.

As far as I know on Linux, this project uses XULRunner (i.e. Mozilla Gecko) for its browser component. For testing against this environment (if you have Java installed) there is a Java Webstart Demo which loads a JWebBrowser component at http://djproject.sourceforge.net/ns/index.html Note that Windows, Mac and Linux all load different web rendering engines, though.

Bizarre. Don't know if there's a workaround you might suggest from knowing how livequery loads. Is there a too-conservative user agent verification of some kind, which is failing to detect Firefox, even though it's basically the same thing? I'd expect the same code to work in XULRunner just the same, although it probably identifies itself differently.

On my machine, the code below differentiates between the runtime environments loading the same page. In XULRunner Livequery is alerted as missing whilst in Firefox it is present despite loading from an identical page.

if (jQuery.livequery){
    alert("Livequery is here");     
} 
else{
    alert("No livequery plugin bound");
}

Plugin already defined checks?

I like the usage of livequery together with greasemonkey plugin,
but if i require the plugin in more than one script all the functions get overwritten.
Could you please add some checks, if it is already registered?

does not work for IFRAMEs

>>> AJS.$('#wysiwygTextarea_ifr').contents().find('h6')
<<< [<h6>​test​</h6>​, <h6>​test2​</h6>​]

>>> AJS.$('#wysiwygTextarea_ifr').contents().find('h6').livequery(function() { alert('there'); });
<<< [<h6>​test​</h6>​, <h6>​test2​</h6>​]

>>> AJS.$('#wysiwygTextarea_ifr').contents().find('body').append('<h6>new</h6>');
<<< [<body id=​"tinymce" class=​"mceContentBody wiki-content fullsize" contenteditable=​"true" dir=​"ltr" style=​"min-height:​ 502px;​ ">​…​</body>​]

No alert appeared.

Not working for elements from Ajax Call(?)

Hi,
i've tried using livequery (both, the old and the new version) on Ajax Calls.
Here I'm applying the plugin to Link elements inside an UL:

	ul.livequery("a", function(){
		$(this).click(function(){
                       // do something
		});
	});

I'm doing an Ajax call which adds LI elements to an UL like this:

	var li = "<li value='"+id+"'><a href='#'>"+valu+"</a></li>";
	ul.append(li);

the plugin should recognize it but doesn't .. I need to reapply the events to the elements.
I'm using Chrome. Anything wrong with my code?
Thanks

UPDATE: i found out that there's issues with Jquery - I've tried jquery-3.2.1.min.js - doesn't work - downgraded to jquery-2.2.4.min.js and it works!

Seems to be broken with the latest jQuery 1.4

No test case sorry. For me, in some cases it doesn't work immediately (like an element matching the livequery selector is inserted already in DOM, but until I click inside a field on the page, livequery doesn't notice that), in some cases it works several times on the same element.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.