Roo/htmleditor/TidyEntities.js
[roojs1] / Roo / htmleditor / TidyEntities.js
index 82c8fe5..1ecb9b3 100644 (file)
@@ -12,15 +12,9 @@ Roo.htmleditor.TidyEntities = {
      */
     init : function (){
     
-        
-       // Decodes text by using the browser
-       
-       // Build a two way lookup table for the entities
-       
-       // Unpack entities lookup where the numbers are in radix 32 to reduce the size
        
       
-       this.namedEntities = buildEntitiesLookup(this.namedEntitiesData, 32);
+       this.namedEntities = buildEntitiesLookup(this.namedEntitiesData.join(','), 32);
        
     },
 
@@ -623,8 +617,9 @@ Roo.htmleditor.TidyEntities = {
      * @return {String} Entity encoded text.
      */
     encodeAllRaw: function(text) {
-        return ('' + text).replace(rawCharsRegExp, function(chr) {
-            return baseEntities[chr] || chr;
+        var t = this;
+        return ('' + text).replace(this.rawCharsRegExp, function(chr) {
+            return t.baseEntities[chr] || chr;
         });
     },
     /**
@@ -637,12 +632,13 @@ Roo.htmleditor.TidyEntities = {
      * @return {String} Entity encoded text.
      */
     encodeNumeric: function(text, attr) {
-        return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
+        var t = this;
+        return text.replace(attr ? this.attrsCharsRegExp : this.textCharsRegExp, function(chr) {
             // Multi byte sequence convert it to a single entity
             if (chr.length > 1) {
                 return '&#' + (1024 * (chr.charCodeAt(0) - 55296) + (chr.charCodeAt(1) - 56320) + 65536) + ';';
             }
-            return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
+            return t.baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
         });
     },
     /**
@@ -656,9 +652,10 @@ Roo.htmleditor.TidyEntities = {
      * @return {String} Entity encoded text.
      */
     encodeNamed: function(text, attr, entities) {
-        entities = entities || namedEntities;
-        return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
-            return baseEntities[chr] || entities[chr] || chr;
+        var t = this;
+        entities = entities || this.namedEntities;
+        return text.replace(attr ? this.attrsCharsRegExp : this.textCharsRegExp, function(chr) {
+            return t.baseEntities[chr] || entities[chr] || chr;
         });
     },
     /**
@@ -670,22 +667,22 @@ Roo.htmleditor.TidyEntities = {
      * @return {function} Encode function to be used.
      */
     getEncodeFunc: function(name, entities) {
-        entities = buildEntitiesLookup(entities) || namedEntities;
-
+        entities = this.buildEntitiesLookup(entities) || this.namedEntities;
+        var t = this;
         function encodeNamedAndNumeric(text, attr) {
-            return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
-                return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
+            return text.replace(attr ? t.attrsCharsRegExp : t.textCharsRegExp, function(chr) {
+                return t.baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
             });
         }
 
         function encodeCustomNamed(text, attr) {
-            return Entities.encodeNamed(text, attr, entities);
+            return t.encodeNamed(text, attr, entities);
         }
         // Replace + with , to be compatible with previous TinyMCE versions
-        name = makeMap(name.replace(/\+/g, ','));
+        name = this.makeMap(name.replace(/\+/g, ','));
         // Named and numeric encoder
         if (name.named && name.numeric) {
-            return encodeNamedAndNumeric;
+            return this.encodeNamedAndNumeric;
         }
         // Named encoder
         if (name.named) {
@@ -693,14 +690,14 @@ Roo.htmleditor.TidyEntities = {
             if (entities) {
                 return encodeCustomNamed;
             }
-            return Entities.encodeNamed;
+            return this.encodeNamed;
         }
         // Numeric
         if (name.numeric) {
-            return Entities.encodeNumeric;
+            return this.encodeNumeric;
         }
         // Raw encoder
-        return Entities.encodeRaw;
+        return this.encodeRaw;
     },
     /**
      * Decodes the specified string, this will replace entities with raw UTF characters.
@@ -709,8 +706,10 @@ Roo.htmleditor.TidyEntities = {
      * @param {String} text Text to entity decode.
      * @return {String} Entity decoded string.
      */
-    decode: function(text) {
-        return text.replace(entityRegExp, function(all, numeric) {
+    decode: function(text)
+    {
+        var  t = this;
+        return text.replace(this.entityRegExp, function(all, numeric) {
             if (numeric) {
                 numeric = 'x' === numeric.charAt(0).toLowerCase() ? parseInt(numeric.substr(1), 16) : parseInt(numeric, 10);
                 // Support upper UTF
@@ -718,15 +717,28 @@ Roo.htmleditor.TidyEntities = {
                     numeric -= 65536;
                     return String.fromCharCode(55296 + (numeric >> 10), 56320 + (1023 & numeric));
                 }
-                return asciiMap[numeric] || String.fromCharCode(numeric);
+                return t.asciiMap[numeric] || String.fromCharCode(numeric);
             }
-            return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
+            return t.reverseEntities[all] || t.namedEntities[all] || t.nativeDecode(all);
         });
-    }
-    function nativeDecode(text) {
+    },
+    nativeDecode : function (text) {
         return text;
-    }
-
+    },
+    makeMap : function (items, delim, map) {
+               var i;
+               items = items || [];
+               delim = delim || ',';
+               if (typeof items == "string") {
+                       items = items.split(delim);
+               }
+               map = map || {};
+               i = items.length;
+               while (i--) {
+                       map[items[i]] = {};
+               }
+               return map;
+       },