refactor(cloudfunc) add Entity

This commit is contained in:
coderaiser 2014-12-30 07:41:45 -05:00
parent 55d382b0c1
commit 32b47b9966
2 changed files with 31 additions and 26 deletions

View file

@ -1215,7 +1215,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
if (link) {
inner = link.innerHTML;
name = CloudFunc.decodeEntities(inner);
name = CloudFunc.Entity.decode(inner);
}
return name;

View file

@ -12,6 +12,7 @@ var Util;
function CloudFuncProto(Util) {
var CloudFunc = this,
Entity = new entityProto(),
check = Util.check,
render = Util.render,
FS;
@ -33,34 +34,38 @@ var Util;
this.CHANNEL_TERMINAL_RESIZE= 'terminal-resize';
this.MAX_FILE_SIZE = 500 * 1024;
var Entities = {
' ': ' ',
'&lt;' : '<',
'&gt' : '>',
'&amp;' : '&'
};
this.Entity = Entity;
this.encodeEntities = function(str) {
Object.keys(Entities).forEach(function(code) {
var char = Entities[code],
reg = RegExp(char, 'g');
str = str.replace(reg, code);
});
function entityProto() {
var Entities = {
'&nbsp;': ' ',
'&lt;' : '<',
'&gt' : '>',
'&amp;' : '&'
};
return str;
};
this.decodeEntities = function(str) {
Object.keys(Entities).forEach(function(code) {
var char = Entities[code],
reg = RegExp(code, 'g');
this.encode = function(str) {
Object.keys(Entities).forEach(function(code) {
var char = Entities[code],
reg = RegExp(char, 'g');
str = str.replace(reg, code);
});
str = str.replace(reg, char);
});
return str;
};
return str;
};
this.decode = function(str) {
Object.keys(Entities).forEach(function(code) {
var char = Entities[code],
reg = RegExp(code, 'g');
str = str.replace(reg, char);
});
return str;
};
}
this.formatMsg = function(msg, name, status) {
if (!status)
@ -251,7 +256,7 @@ var Util;
linkResult = render(templateLink, {
link : link,
name : CloudFunc.encodeEntities(file.name),
name : Entity.encode(file.name),
attribute : attribute
});