mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
refactor(cloudfunc) add Entity
This commit is contained in:
parent
55d382b0c1
commit
32b47b9966
2 changed files with 31 additions and 26 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
' ': ' ',
|
||||
'<' : '<',
|
||||
'>' : '>',
|
||||
'&' : '&'
|
||||
};
|
||||
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 = {
|
||||
' ': ' ',
|
||||
'<' : '<',
|
||||
'>' : '>',
|
||||
'&' : '&'
|
||||
};
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue