aboutsummaryrefslogtreecommitdiffstats
path: root/src/jqLite.js
diff options
context:
space:
mode:
authorMichał Gołębiowski2013-04-30 11:29:07 +0200
committerVojta Jina2013-05-23 11:45:57 -0700
commit815053e403ace666b2383643227ecde5f36742c5 (patch)
tree5b307d2cf6fbdd6f023c9c09c0bc56920f655dca /src/jqLite.js
parent6173abe20bcb99ec4290a513cff43f0c00b74464 (diff)
downloadangular.js-815053e403ace666b2383643227ecde5f36742c5.tar.bz2
fix(jqLite): correctly monkey-patch core jQuery methods
When real jQuery is present, Angular monkey patch it to fire `$destroy` event. This commit fixes two issues in the jQuery patch: - passing a selector to the $.fn.remove method (only fire `$destroy` on the matched elements) - using `$.fn.html` without parameters as a getter (do not fire `$destroy`)
Diffstat (limited to 'src/jqLite.js')
-rw-r--r--src/jqLite.js41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/jqLite.js b/src/jqLite.js
index 65dd3fad..57c12821 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -107,37 +107,38 @@ function camelCase(name) {
/////////////////////////////////////////////
// jQuery mutation patch
//
-// In conjunction with bindJQuery intercepts all jQuery's DOM destruction apis and fires a
+// In conjunction with bindJQuery intercepts all jQuery's DOM destruction apis and fires a
// $destroy event on all DOM nodes being removed.
//
/////////////////////////////////////////////
-function JQLitePatchJQueryRemove(name, dispatchThis) {
+function JQLitePatchJQueryRemove(name, dispatchThis, filterElems, getterIfNoArguments) {
var originalJqFn = jQuery.fn[name];
originalJqFn = originalJqFn.$original || originalJqFn;
removePatch.$original = originalJqFn;
jQuery.fn[name] = removePatch;
- function removePatch() {
- var list = [this],
+ function removePatch(param) {
+ var list = filterElems && param ? [this.filter(param)] : [this],
fireEvent = dispatchThis,
set, setIndex, setLength,
- element, childIndex, childLength, children,
- fns, events;
-
- while(list.length) {
- set = list.shift();
- for(setIndex = 0, setLength = set.length; setIndex < setLength; setIndex++) {
- element = jqLite(set[setIndex]);
- if (fireEvent) {
- element.triggerHandler('$destroy');
- } else {
- fireEvent = !fireEvent;
- }
- for(childIndex = 0, childLength = (children = element.children()).length;
- childIndex < childLength;
- childIndex++) {
- list.push(jQuery(children[childIndex]));
+ element, childIndex, childLength, children;
+
+ if (!getterIfNoArguments || param != null) {
+ while(list.length) {
+ set = list.shift();
+ for(setIndex = 0, setLength = set.length; setIndex < setLength; setIndex++) {
+ element = jqLite(set[setIndex]);
+ if (fireEvent) {
+ element.triggerHandler('$destroy');
+ } else {
+ fireEvent = !fireEvent;
+ }
+ for(childIndex = 0, childLength = (children = element.children()).length;
+ childIndex < childLength;
+ childIndex++) {
+ list.push(jQuery(children[childIndex]));
+ }
}
}
}