Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOM]: Don't cache throw away elements. #1773

Merged
merged 3 commits into from Apr 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/dom/js/dom-create.js
Expand Up @@ -22,24 +22,15 @@ var re_tag = /<([a-z]+)/i,
re_tbody = /(?:\/(?:thead|tfoot|tbody|caption|col|colgroup)>)+\s*<tbody/,

TABLE_OPEN = '<table>',
TABLE_CLOSE = '</table>',
TABLE_CLOSE = '</table>',

selectedIndex;

Y.mix(Y.DOM, {
_fragClones: {},

_create: function(html, doc, tag) {
tag = tag || 'div';

var frag = Y_DOM._fragClones[tag];
if (frag) {
frag = frag.cloneNode(false);
} else {
frag = Y_DOM._fragClones[tag] = doc.createElement(tag);
}
frag.innerHTML = html;
return frag;
var element = doc.createElement(tag || 'div');
element.innerHTML = html;
return element;
},

_children: function(node, tag) {
Expand Down Expand Up @@ -103,15 +94,15 @@ Y.mix(Y.DOM, {
tag = creator;
}
}

node = create(html, doc, tag);
nodes = node.childNodes;

if (nodes.length === 1) { // return single node, breaking parentNode ref from "fragment"
ret = node.removeChild(nodes[0]);
} else if (nodes[0] && nodes[0].className === 'yui3-big-dummy') { // using dummy node to preserve some attributes (e.g. OPTION not selected)
selectedIndex = node.selectedIndex;

if (nodes.length === 2) {
ret = nodes[0].nextSibling;
} else {
Expand Down Expand Up @@ -230,7 +221,7 @@ Y.mix(Y.DOM, {
if (node.nodeName == "SELECT" && selectedIndex > 0) {
node.selectedIndex = selectedIndex - 1;
}

return ret;
},

Expand Down
1 change: 0 additions & 1 deletion src/node/tests/unit/node.html
Expand Up @@ -1734,7 +1734,6 @@ <h2>test</h2>
},

'should accept document Node instance': function() {
Y.DOM._fragClones = {};
var node = Y.Node.create('<div/>', Y.one(document));
Assert.areEqual('DIV', node.get('tagName'));
},
Expand Down