Opened 10 years ago
Closed 10 years ago
#14309 closed bug (notabug)
chrome 29 slows jquery extension
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.10.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
https://chrome.google.com/webstore/detail/cantonese-romanizer/ippbggfdamglbjjhahfjljnolkigphdl
this extension was instant in chrome version 28, but now takes forever in version 29
i tried using jquery 1.10.2 and 2.0.3 without success
any ideas? main script below: Get all the text nodes in the document, and replace any Chinese characters found with Jyutping. $(getTextNodesIn(document)).each(function(index, el) {
var $el, text, chars, i, len, c, jyutping, frag, match, phonetic, tone; $el = $(el), text = $el.text(), chars = [], frag = document.createDocumentFragment();
Walk through the text in this node one character at a time. for (i = 0, len = text.length; i < len; i++) {
c = text[i], jyutping = _charmap[c];
If the char was in our map (i.e. it's a Chinese char), replace it with Jyutping. if (jyutping) {
if (chars.length) {
frag.appendChild(document.createTextNode(chars.join())); chars = [];
} match = jyutping.match(/(\w+)(\d)$/); if (match && match.length == 3) {
phonetic = document.createTextNode(match[1]); tone = document.createElement('sup'); tone.appendChild(document.createTextNode(match[2])); frag.appendChild(phonetic); frag.appendChild(tone);
} else
chars.push(jyutping);
} else
chars.push(c);
}
Add any remaining chars to the document fragment. if (chars.length)
frag.appendChild(document.createTextNode(chars.join()));
Replace the text node with the fragment we've assembled. $el.replaceWith(frag);
});
Selects all decendent text nodes of an element. http://stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery function getTextNodesIn(node, includeWhitespaceNodes) {
var textNodes = [], whitespace = /\s*$/;
function getTextNodes(node) {
if (node.nodeType == 3) {
if (includeWhitespaceNodes !whitespace.test(node.nodeValue)) { textNodes.push(node);
}
} else {
for (var i = 0, len = node.childNodes.length; i < len; ++i) {
getTextNodes(node.childNodes[i]);
}
}
}
getTextNodes(node); return textNodes;
}
Change History (2)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
Thanks for taking the time to report a ticket, The jQuery Core bug tracker is only for reporting and identifying bugs directly in jQuery core, not in Chrome or any other web browser, nor is it a general programming support forum. It sounds like this should be taken up either with the extension's developers or the Chrome team.
Worth noting, however, is that a documentFragment is not a valid input to replaceWith or any other jQuery method.
#14308 is a duplicate of this ticket.