mirror of
https://github.com/twitter/twemoji.git
synced 2025-03-28 19:20:28 +00:00
do not change nodes if not needed
This commit is contained in:
parent
39a091da4b
commit
92d5bea1ab
5
test.js
5
test.js
@ -146,10 +146,7 @@ wru.test([{
|
||||
div = document.createElement('div');
|
||||
div.appendChild(document.createTextNode('I \u2764\uFE0E emoji!'));
|
||||
twemoji.parse(div);
|
||||
wru.assert('default parsing created 3 nodes anyway', div.childNodes.length === 3);
|
||||
wru.assert('first child is the expected one', div.removeChild(div.firstChild).nodeValue === 'I ');
|
||||
wru.assert('emoji child is unchanged', div.removeChild(div.firstChild).nodeValue === '\u2764\uFE0E');
|
||||
wru.assert('last child is the expected one', div.removeChild(div.firstChild).nodeValue === ' emoji!');
|
||||
wru.assert('default parsing did NOT create 3 nodes anyway', div.childNodes.length === 1);
|
||||
}
|
||||
},{
|
||||
name: 'DOM parsing + size',
|
||||
|
@ -604,6 +604,7 @@ function createTwemoji(re) {
|
||||
var
|
||||
allText = grabAllTextNodes(node, []),
|
||||
length = allText.length,
|
||||
modified = false,
|
||||
fragment,
|
||||
subnode,
|
||||
text,
|
||||
@ -644,13 +645,15 @@ function createTwemoji(re) {
|
||||
img.setAttribute('draggable', 'false');
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
modified = true;
|
||||
fragment.appendChild(img);
|
||||
}
|
||||
}
|
||||
fragment.appendChild(img || createText(alt));
|
||||
if (!img) fragment.appendChild(createText(alt));
|
||||
img = null;
|
||||
}
|
||||
// is there actually anything to replace in here ?
|
||||
if (0 < i) {
|
||||
if (modified) {
|
||||
// any text left to be added ?
|
||||
if (i < text.length) {
|
||||
fragment.appendChild(
|
||||
|
@ -327,6 +327,7 @@ define(function () {
|
||||
var
|
||||
allText = grabAllTextNodes(node, []),
|
||||
length = allText.length,
|
||||
modified = false,
|
||||
fragment,
|
||||
subnode,
|
||||
text,
|
||||
@ -367,13 +368,15 @@ define(function () {
|
||||
img.setAttribute('draggable', 'false');
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
modified = true;
|
||||
fragment.appendChild(img);
|
||||
}
|
||||
}
|
||||
fragment.appendChild(img || createText(alt));
|
||||
if (!img) fragment.appendChild(createText(alt));
|
||||
img = null;
|
||||
}
|
||||
// is there actually anything to replace in here ?
|
||||
if (0 < i) {
|
||||
if (modified) {
|
||||
// any text left to be added ?
|
||||
if (i < text.length) {
|
||||
fragment.appendChild(
|
||||
|
@ -326,6 +326,7 @@ var twemoji = (function (
|
||||
var
|
||||
allText = grabAllTextNodes(node, []),
|
||||
length = allText.length,
|
||||
modified = false,
|
||||
fragment,
|
||||
subnode,
|
||||
text,
|
||||
@ -366,13 +367,15 @@ var twemoji = (function (
|
||||
img.setAttribute('draggable', 'false');
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
modified = true;
|
||||
fragment.appendChild(img);
|
||||
}
|
||||
}
|
||||
fragment.appendChild(img || createText(alt));
|
||||
if (!img) fragment.appendChild(createText(alt));
|
||||
img = null;
|
||||
}
|
||||
// is there actually anything to replace in here ?
|
||||
if (0 < i) {
|
||||
if (modified) {
|
||||
// any text left to be added ?
|
||||
if (i < text.length) {
|
||||
fragment.appendChild(
|
||||
|
@ -327,6 +327,7 @@ var twemoji = (function (
|
||||
var
|
||||
allText = grabAllTextNodes(node, []),
|
||||
length = allText.length,
|
||||
modified = false,
|
||||
fragment,
|
||||
subnode,
|
||||
text,
|
||||
@ -367,13 +368,15 @@ var twemoji = (function (
|
||||
img.setAttribute('draggable', 'false');
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
modified = true;
|
||||
fragment.appendChild(img);
|
||||
}
|
||||
}
|
||||
fragment.appendChild(img || createText(alt));
|
||||
if (!img) fragment.appendChild(createText(alt));
|
||||
img = null;
|
||||
}
|
||||
// is there actually anything to replace in here ?
|
||||
if (0 < i) {
|
||||
if (modified) {
|
||||
// any text left to be added ?
|
||||
if (i < text.length) {
|
||||
fragment.appendChild(
|
||||
|
Loading…
x
Reference in New Issue
Block a user