diff --git a/src/Angular.js b/src/Angular.js index 57f478b5b944..a3117ee435f2 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1430,8 +1430,10 @@ function snake_case(name, separator){ } function bindJQuery() { + var originalCleanData; // bind to jQuery if present; jQuery = window.jQuery; + // reset to jQuery or default to us. if (jQuery) { jqLite = jQuery; @@ -1442,14 +1444,22 @@ function bindJQuery() { injector: JQLitePrototype.injector, inheritedData: JQLitePrototype.inheritedData }); - // Method signature: - // jqLitePatchJQueryRemove(name, dispatchThis, filterElems, getterIfNoArguments) - jqLitePatchJQueryRemove('remove', true, true, false); - jqLitePatchJQueryRemove('empty', false, false, false); - jqLitePatchJQueryRemove('html', false, false, true); + + originalCleanData = jQuery.cleanData; + // Prevent double-proxying. + originalCleanData = originalCleanData.$$original || originalCleanData; + + jQuery.cleanData = function(elems) { + for (var i = 0, elem; (elem = elems[i]) != null; i++) { + jQuery(elem).triggerHandler('$destroy'); + } + originalCleanData(elems); + }; + jQuery.cleanData.$$original = originalCleanData; } else { jqLite = JQLite; } + angular.element = jqLite; } diff --git a/src/jqLite.js b/src/jqLite.js index d03ea67b4676..771c4312432d 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -136,49 +136,6 @@ function camelCase(name) { replace(MOZ_HACK_REGEXP, 'Moz$1'); } -///////////////////////////////////////////// -// jQuery mutation patch -// -// 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, filterElems, getterIfNoArguments) { - var originalJqFn = jQuery.fn[name]; - originalJqFn = originalJqFn.$original || originalJqFn; - removePatch.$original = originalJqFn; - jQuery.fn[name] = removePatch; - - function removePatch(param) { - // jshint -W040 - var list = filterElems && param ? [this.filter(param)] : [this], - fireEvent = dispatchThis, - set, setIndex, setLength, - 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])); - } - } - } - } - return originalJqFn.apply(this, arguments); - } -} - var SINGLE_TAG_REGEXP = /^<(\w+)\s*\/?>(?:<\/\1>|)$/; var HTML_REGEXP = /<|&#?\w+;/; var TAG_NAME_REGEXP = /<([\w:]+)/; diff --git a/test/jQueryPatchSpec.js b/test/jQueryPatchSpec.js index 10e46be8a499..4c588092dc57 100644 --- a/test/jQueryPatchSpec.js +++ b/test/jQueryPatchSpec.js @@ -30,10 +30,6 @@ if (window.jQuery) { describe('$detach event', function() { - it('should fire on detach()', function() { - doc.find('span').detach(); - }); - it('should fire on remove()', function() { doc.find('span').remove(); }); @@ -83,12 +79,6 @@ if (window.jQuery) { describe('$detach event is not invoked in too many cases', function() { - it('should fire only on matched elements on detach(selector)', function() { - doc.find('span').detach('.second'); - expect(spy2).toHaveBeenCalled(); - expect(spy2.callCount).toEqual(1); - }); - it('should fire only on matched elements on remove(selector)', function() { doc.find('span').remove('.second'); expect(spy2).toHaveBeenCalled();