Remove sniffing when branching `escapeHTML` and `unescapeHTML`. [#570 state:resolved] (kangax)
This commit is contained in:
parent
4453e62fd5
commit
7833e8c909
|
@ -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)
|
||||
|
|
|
@ -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,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
},
|
||||
unescapeHTML: function() {
|
||||
return this.stripTags().replace(/</g,'<').replace(/>/g,'>').replace(/&/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() !== '<\n') {
|
||||
String.prototype.escapeHTML = function() {
|
||||
return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
}
|
||||
}
|
||||
|
||||
if ('<\n'.unescapeHTML() !== '<\n') {
|
||||
String.prototype.unescapeHTML = function() {
|
||||
return this.stripTags().replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue