0
@@ -83,14 +83,16 @@ Object.extend(String.prototype, {
0
escapeHTML: function() {
0
var self = arguments.callee;
0
- return self.
div.innerHTML;
0
+ return self.
container.innerHTML;
0
unescapeHTML: function() {
0
var div = new Element('div');
0
- div.innerHTML = this.stripTags();
0
+ // Safari requires the text nested inside another element to render correctly
0
+ div.innerHTML = '<pre>' + this.stripTags() + '</pre>';
0
return div.childNodes[0] ? (div.childNodes.length > 1 ?
0
- $A(div.childNodes).inject('', function(memo, node) { return memo
+node.nodeValue }) :
0
+ $A(div.childNodes).inject('', function(memo, node) { return memo
+ node.nodeValue }) :
0
div.childNodes[0].nodeValue) : '';
0
@@ -211,15 +213,6 @@ Object.extend(String.prototype, {
0
-if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
0
- escapeHTML: function() {
0
- return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
0
- unescapeHTML: function() {
0
- return this.stripTags().replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
0
String.prototype.gsub.prepareReplacement = function(replacement) {
0
if (Object.isFunction(replacement)) return replacement;
0
var template = new Template(replacement);
0
@@ -229,11 +222,39 @@ String.prototype.gsub.prepareReplacement = function(replacement) {
0
String.prototype.parseQuery = String.prototype.toQueryParams;
0
Object.extend(String.prototype.escapeHTML, {
0
-
div: document.createElement('div'),
0
+
container: document.createElement('pre'),
0
text: document.createTextNode('')
0
-String.prototype.escapeHTML.div.appendChild(String.prototype.escapeHTML.text);
0
+String.prototype.escapeHTML.container.appendChild(String.prototype.escapeHTML.text);
0
+if (Prototype.Browser.IE)
0
+ // IE converts all newlines to carriage returns so we swap them back
0
+ String.prototype.unescapeHTML = String.prototype.unescapeHTML.wrap(function(proceed) {
0
+ return proceed().replace(/\r/g, '\n')
0
+if (Prototype.Browser.WebKit && Prototype.BrowserFeatures.SelectorsAPI)
0
+ // Safari 3.x has issues with escaping the ">" character
0
+ var escapeHTML = String.prototype.escapeHTML;
0
+ String.prototype.escapeHTML = escapeHTML.wrap(function(proceed) {
0
+ return proceed().replace(/>/g, ">")
0
+ container: escapeHTML.container,
0
+if ('&'.escapeHTML() !== '&') {
0
+ // Safari 2.x has issues with escaping html inside a "pre" element so we use the deprecated "xmp" element instead
0
+ Object.extend(String.prototype.escapeHTML, {
0
+ container: document.createElement('xmp'),
0
+ text: document.createTextNode('')
0
+ String.prototype.escapeHTML.container.appendChild(String.prototype.escapeHTML.text);
0
var Template = Class.create({
0
initialize: function(template, pattern) {