Skip to content
This repository has been archived by the owner on Aug 6, 2019. It is now read-only.

Added fires also on matching nested elements. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions jquery.livequery.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
},
isStopped: function() {
return this.stopped === true;
},
find: function(element) {
if ( this.isStopped() ) {
return $([]);
}
return $(element, this.context).find(this.selector);
}
};

Expand Down Expand Up @@ -139,6 +145,11 @@
query.added(target);
}, 1);
}
query.find(target).each(function (i, element) {
setTimeout(function() {
query.added(element);
}, 1);
});
});
},
removed: function(target) {
Expand Down
2 changes: 1 addition & 1 deletion jquery.livequery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion test/unit/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test("Fires for existing matched elements", 4, function() {

test("Fires for newly added matched elements (via jQuery)", 1, function() {
stop();
var $li = $('<li id="newli">New</li>');
var $li = $('<li id="newli">New</li>'), n = 0;
this.$target.livequery('li', $.proxy(function(elem) {
if (elem.id === "newli") {
ok( $(elem).is('li'), 'It is an li element' );
Expand All @@ -33,6 +33,19 @@ test("Fires for newly added matched elements (via jQuery)", 1, function() {
this.$target.find('ol').append($li);
});

test("Fires for newly nested added matched elements (via jQuery)", 1, function() {
stop();
var $li = $('<li id="newli"><a id="important">important</a></li>'), n = 0;
this.$target.livequery('a#important', $.proxy(function(elem) {
if (elem.id === "important") {
ok( $(elem).is('a'), 'It is an a element' );
this.$target.expire('a#important');
start();
}
}, this));
this.$target.find('ol').append($li);
});

test("Scope and first argument are the element", 2, function() {
stop();
var _this = this;
Expand Down