Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(jqLite): use getElementsByTagName for dealoc-ing elements, cz of SVG on IE #8136

Merged
merged 3 commits into from
Jul 10, 2014
Merged
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
26 changes: 12 additions & 14 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,16 @@ function jqLiteClone(element) {
return element.cloneNode(true);
}

function jqLiteDealoc(element){
jqLiteRemoveData(element);
var childElement;
for ( var i = 0, children = element.children, l = (children && children.length) || 0; i < l; i++) {
childElement = children[i];
jqLiteDealoc(childElement);
function jqLiteDealoc(element, onlyDescendants){
if (!onlyDescendants) jqLiteRemoveData(element);

if (element.childNodes && element.childNodes.length) {
// we use querySelectorAll because documentFragments don't have getElementsByTagName
var descendants = element.getElementsByTagName ? element.getElementsByTagName('*') :
element.querySelectorAll ? element.querySelectorAll('*') : [];
for (var i = 0, l = descendants.length; i < l; i++) {
jqLiteRemoveData(descendants[i]);
}
}
}

Expand Down Expand Up @@ -430,9 +434,7 @@ function jqLiteInheritedData(element, name, value) {
}

function jqLiteEmpty(element) {
for (var i = 0, childNodes = element.childNodes; i < childNodes.length; i++) {
jqLiteDealoc(childNodes[i]);
}
jqLiteDealoc(element, true);
while (element.firstChild) {
element.removeChild(element.firstChild);
}
Expand Down Expand Up @@ -630,9 +632,7 @@ forEach({
if (isUndefined(value)) {
return element.innerHTML;
}
for (var i = 0, childNodes = element.childNodes; i < childNodes.length; i++) {
jqLiteDealoc(childNodes[i]);
}
jqLiteDealoc(element, true);
element.innerHTML = value;
},

Expand Down Expand Up @@ -752,8 +752,6 @@ function createEventHandler(element, events) {
forEach({
removeData: jqLiteRemoveData,

dealoc: jqLiteDealoc,

on: function onFn(element, type, fn, unsupported){
if (isDefined(unsupported)) throw jqLiteMinErr('onargs', 'jqLite#on() does not support the `selector` or `eventData` parameters');

Expand Down
12 changes: 12 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,18 @@ describe('jqLite', function() {
selected.removeData('prop2');
});

it('should add and remove data on SVGs', function() {
var svg = jqLite('<svg><rect></rect></svg>');

svg.data('svg-level', 1);
expect(svg.data('svg-level')).toBe(1);

svg.children().data('rect-level', 2);
expect(svg.children().data('rect-level')).toBe(2);

svg.remove();
});


it('should not add to the cache if the node is a comment or text node', function() {
var calcCacheSize = function() {
Expand Down
2 changes: 1 addition & 1 deletion test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ describe('browser', function() {
});

afterEach(function() {
if (!jQuery) jqLite(fakeWindow).dealoc();
if (!jQuery) jqLiteDealoc(fakeWindow);
});

it('should return registered callback', function() {
Expand Down