*/
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);
},
* @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;
});
},
/**
* @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) + ';';
});
},
/**
* @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;
});
},
/**
* @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) {
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.
* @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
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;
+ },