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

Commit ba66c4f

Browse files
committed
refactor(jqLite): IE8-support fixes
ddb8081 refactors jqLite, and removes support for IE8. This patch extends this to prevent the CL from breaking IE8, and to remain suitable for the 1.2.x branch. Closes #6963
1 parent 4ea57e7 commit ba66c4f

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/jqLite.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,25 +205,27 @@ function jqLiteIsTextNode(html) {
205205
function jqLiteBuildFragment(html, context) {
206206
var elem, tmp, tag, wrap,
207207
fragment = context.createDocumentFragment(),
208-
nodes = [], i;
208+
nodes = [], i, j, jj;
209209

210210
if (jqLiteIsTextNode(html)) {
211211
// Convert non-html into a text node
212212
nodes.push(context.createTextNode(html));
213213
} else {
214+
tmp = fragment.appendChild(context.createElement('div'));
214215
// Convert html into DOM nodes
215-
tmp = tmp || fragment.appendChild(context.createElement("div"));
216216
tag = (TAG_NAME_REGEXP.exec(html) || ["", ""])[1].toLowerCase();
217217
wrap = wrapMap[tag] || wrapMap._default;
218-
tmp.innerHTML = wrap[1] + html.replace(XHTML_TAG_REGEXP, "<$1></$2>") + wrap[2];
218+
tmp.innerHTML = '<div>&#160;</div>' +
219+
wrap[1] + html.replace(XHTML_TAG_REGEXP, "<$1></$2>") + wrap[2];
220+
tmp.removeChild(tmp.firstChild);
219221

220222
// Descend through wrappers to the right content
221223
i = wrap[0];
222224
while (i--) {
223225
tmp = tmp.lastChild;
224226
}
225227

226-
nodes = concat(nodes, tmp.childNodes);
228+
for (j=0, jj=tmp.childNodes.length; j<jj; ++j) nodes.push(tmp.childNodes[j]);
227229

228230
tmp = fragment.firstChild;
229231
tmp.textContent = "";
@@ -232,11 +234,7 @@ function jqLiteBuildFragment(html, context) {
232234
// Remove wrapper from fragment
233235
fragment.textContent = "";
234236
fragment.innerHTML = ""; // Clear inner HTML
235-
forEach(nodes, function(node) {
236-
fragment.appendChild(node);
237-
});
238-
239-
return fragment;
237+
return nodes;
240238
}
241239

242240
function jqLiteParseHTML(html, context) {
@@ -247,11 +245,7 @@ function jqLiteParseHTML(html, context) {
247245
return [context.createElement(parsed[1])];
248246
}
249247

250-
if ((parsed = jqLiteBuildFragment(html, context))) {
251-
return parsed.childNodes;
252-
}
253-
254-
return [];
248+
return jqLiteBuildFragment(html, context);
255249
}
256250

257251
/////////////////////////////////////////////
@@ -271,6 +265,8 @@ function JQLite(element) {
271265

272266
if (isString(element)) {
273267
jqLiteAddNodes(this, jqLiteParseHTML(element));
268+
var fragment = jqLite(document.createDocumentFragment());
269+
fragment.append(this);
274270
} else {
275271
jqLiteAddNodes(this, element);
276272
}

0 commit comments

Comments
 (0)