diff --git a/lib/client/dom.js b/lib/client/dom.js index 530d79b4..3a317ffe 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -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; diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index 1c545418..68fdc79c 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -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 });