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

Commit

Permalink
Added fires also on matching nested elements.
Browse files Browse the repository at this point in the history
The "added" event now fires also on nested elments that match the selector.

Passed on:

* Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36
  (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
* Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/604.4.7
  (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7
  • Loading branch information
mperrando committed Feb 8, 2018
1 parent 70a3060 commit f384b73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
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

0 comments on commit f384b73

Please sign in to comment.