From a1daf8e88427d9dc74bed63cc4586cd8c2bd3e95 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 12 Jan 2015 10:36:54 -0500 Subject: [PATCH] feature(util) rm rmStr --- lib/client.js | 10 ++-------- lib/client/dom.js | 7 +++---- lib/client/files.js | 2 +- lib/client/storage/_github.js | 2 +- lib/util.js | 32 -------------------------------- 5 files changed, 7 insertions(+), 46 deletions(-) diff --git a/lib/client.js b/lib/client.js index 5be453b1..79db67ca 100644 --- a/lib/client.js +++ b/lib/client.js @@ -86,7 +86,7 @@ var Util, DOM, CloudFunc, join; * @pParams = {name, path, func, dobefore, arg} */ function loadModule(params) { - var name, path, func, doBefore, slash, afterSlash, + var name, path, func, doBefore, funcName, isContain; if (params) { @@ -98,13 +98,7 @@ var Util, DOM, CloudFunc, join; if (path && !name) { name = getStrBigFirst(path); - name = Util.rmStr(name, '.js'); - - slash = name.indexOf('/'); - if (slash > 0) { - afterSlash = name.substr(slash); - name = Util.rmStr(name, afterSlash); - } + name = name.replace(/.js$/, ''); } isContain = /\.js/.test(path); diff --git a/lib/client/dom.js b/lib/client/dom.js index a2e6f45a..bea0cf63 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -683,13 +683,12 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; */ this.getParentDirPath = function(panel) { var path = DOM.getCurrentDirPath(panel), - dirName = DOM.getCurrentDirName() + '/', - ret = '/'; + dirName = DOM.getCurrentDirName() + '/'; if (path !== '/') - ret = Util.rmStr(path, dirName); + path = path.replace(dirName, ''); - return ret; + return path; }; /** diff --git a/lib/client/files.js b/lib/client/files.js index 79e552e7..43021d2f 100644 --- a/lib/client/files.js +++ b/lib/client/files.js @@ -94,7 +94,7 @@ var Util, DOM, CloudCmd; if (isHTML) { if (isRoot) - path = DIR_HTML + Util.rmStr(name, '-tmpl'); + path = DIR_HTML + name.replace('-tmpl', ''); else path = DIR_HTML_FS + name; diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index 49176025..fa3bc100 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -58,7 +58,7 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb; DOM.load.ajax({ type : 'put', url : apiURL + '/auth', - data : Util.rmStr(code, '?code='), + data : code.replace('?code=', ''), success : function(data) { var token = Util.json.parse(data).data.token; diff --git a/lib/util.js b/lib/util.js index bd025ac4..57b35f4d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -220,38 +220,6 @@ }; } - /** - * function remove substring from string - * @param str - * @param substr - */ - this.rmStr = function(str, substr, isOnce) { - var replace, - strArray = [], - isString = Util.type.string(str), - isArray = Util.type.array(substr), - replaceStr = function(str, strItem) { - var ret = str.replace(strItem, ''); - - return ret; - }; - - replace = isOnce ? replaceStr : Util.replaceStr; - - if (isString && substr) { - if (isArray) - strArray = substr; - else - strArray.push(substr); - - strArray.forEach(function(strItem) { - str = replace(str, strItem, ''); - }); - } - - return str; - }; - /** * function replase pFrom to pTo in pStr * @param str