diff --git a/src/jqLite.js b/src/jqLite.js index a3ba66b16cf5..ad59fbd1af2b 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -201,12 +201,6 @@ function jqLiteHasData(node) { return false; } -function jqLiteCleanData(nodes) { - for (var i = 0, ii = nodes.length; i < ii; i++) { - jqLiteRemoveData(nodes[i]); - } -} - function jqLiteBuildFragment(html, context) { var tmp, tag, wrap, fragment = context.createDocumentFragment(), @@ -309,13 +303,10 @@ function jqLiteClone(element) { } function jqLiteDealoc(element, onlyDescendants) { - if (!onlyDescendants) jqLiteRemoveData(element); + if (!onlyDescendants && jqLiteAcceptsData(element)) jqLite.cleanData([element]); if (element.querySelectorAll) { - var descendants = element.querySelectorAll('*'); - for (var i = 0, l = descendants.length; i < l; i++) { - jqLiteRemoveData(descendants[i]); - } + jqLite.cleanData(element.querySelectorAll('*')); } } @@ -613,7 +604,11 @@ forEach({ data: jqLiteData, removeData: jqLiteRemoveData, hasData: jqLiteHasData, - cleanData: jqLiteCleanData + cleanData: function jqLiteCleanData(nodes) { + for (var i = 0, ii = nodes.length; i < ii; i++) { + jqLiteRemoveData(nodes[i]); + } + } }, function(fn, name) { JQLite[name] = fn; }); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index d99d9e9c1826..2d01c4ed5f0c 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2100,28 +2100,26 @@ describe('$compile', function() { it('should work in jqLite and jQuery with jQuery.cleanData last patched by Angular', runTest); - if (jQuery) { - it('should work with another library patching jQuery.cleanData after Angular', function() { - var cleanedCount = 0; - var currentCleanData = jqLite.cleanData; - jqLite.cleanData = function(elems) { - cleanedCount += elems.length; - // Don't return the output and explicitly pass only the first parameter - // so that we're sure we're not relying on either of them. jQuery UI patch - // behaves in this way. - currentCleanData(elems); - }; + it('should work with another library patching jqLite/jQuery.cleanData after Angular', function() { + var cleanedCount = 0; + var currentCleanData = jqLite.cleanData; + jqLite.cleanData = function(elems) { + cleanedCount += elems.length; + // Don't return the output and explicitly pass only the first parameter + // so that we're sure we're not relying on either of them. jQuery UI patch + // behaves in this way. + currentCleanData(elems); + }; - runTest(); + runTest(); - // The initial ng-repeat div is dumped after parsing hence we expect cleanData - // count to be one larger than size of the iterated array. - expect(cleanedCount).toBe(is.length + 1); + // The initial ng-repeat div is dumped after parsing hence we expect cleanData + // count to be one larger than size of the iterated array. + expect(cleanedCount).toBe(is.length + 1); - // Restore the previous cleanData. - jqLite.cleanData = currentCleanData; - }); - } + // Restore the previous cleanData. + jqLite.cleanData = currentCleanData; + }); }); describe('replace and not exactly one root element', function() { @@ -8640,28 +8638,26 @@ describe('$compile', function() { it('should work without external libraries (except jQuery)', testCleanup); - if (jQuery) { - it('should work with another library patching jQuery.cleanData after AngularJS', function() { - var cleanedCount = 0; - var currentCleanData = jqLite.cleanData; - jqLite.cleanData = function(elems) { - cleanedCount += elems.length; - // Don't return the output and explicitly pass only the first parameter - // so that we're sure we're not relying on either of them. jQuery UI patch - // behaves in this way. - currentCleanData(elems); - }; + it('should work with another library patching jqLite/jQuery.cleanData after AngularJS', function() { + var cleanedCount = 0; + var currentCleanData = jqLite.cleanData; + jqLite.cleanData = function(elems) { + cleanedCount += elems.length; + // Don't return the output and explicitly pass only the first parameter + // so that we're sure we're not relying on either of them. jQuery UI patch + // behaves in this way. + currentCleanData(elems); + }; - testCleanup(); + testCleanup(); - // The ng-repeat template is removed/cleaned (the +1) - // and each clone of the ng-repeat template is also removed (xs.length) - expect(cleanedCount).toBe(xs.length + 1); + // The ng-repeat template is removed/cleaned (the +1) + // and each clone of the ng-repeat template is also removed (xs.length) + expect(cleanedCount).toBe(xs.length + 1); - // Restore the previous cleanData. - jqLite.cleanData = currentCleanData; - }); - } + // Restore the previous cleanData. + jqLite.cleanData = currentCleanData; + }); });