Remove sniffing when branching `escapeHTML` and `unescapeHTML`. [#570 state:resolved] (kangax)

This commit is contained in:
Andrew Dupont 2009-03-08 18:02:09 -05:00
parent 4453e62fd5
commit 7833e8c909
2 changed files with 14 additions and 10 deletions

View File

@ -1,3 +1,5 @@
* Remove sniffing when branching `escapeHTML` and `unescapeHTML`. [#570 state:resolved] (kangax)
* Redefine Element#down in IE 6-7 to avoid extending all descendants when no selector is given. [#452 state:resolved] (eno, Andrew Dupont)
* Reverse the definitions of Event#pointer(X|Y) and Event#pointer to prevent unnecessary computation. [#403 state:resolved] (Nick Stakenburg, Andrew Dupont)

View File

@ -176,7 +176,7 @@ Object.extend(String.prototype, (function() {
* Strips tags and converts the entity forms of special HTML characters to their normal form.
**/
function unescapeHTML() {
var div = new Element('div');
var div = document.createElement('div');
div.innerHTML = this.stripTags();
return div.childNodes[0] ? (div.childNodes.length > 1 ?
$A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :
@ -437,15 +437,6 @@ Object.extend(String.prototype, (function() {
};
})());
if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
escapeHTML: function() {
return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
},
unescapeHTML: function() {
return this.stripTags().replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
}
});
Object.extend(String.prototype.escapeHTML, {
div: document.createElement('div'),
text: document.createTextNode('')
@ -453,3 +444,14 @@ Object.extend(String.prototype.escapeHTML, {
String.prototype.escapeHTML.div.appendChild(String.prototype.escapeHTML.text);
if ('<\n'.escapeHTML() !== '&lt;\n') {
String.prototype.escapeHTML = function() {
return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
}
if ('&lt;\n'.unescapeHTML() !== '<\n') {
String.prototype.unescapeHTML = function() {
return this.stripTags().replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
}
}