diff --git a/lib/client/dom.js b/lib/client/dom.js index 5628b503..e8339cf9 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1264,7 +1264,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; parallel([loadHash, getStoreHash], function(error, loadHash, storeHash) { var equal, - isContain = Util.isContainStr(loadHash, 'error'); + isContain = /error/.test(loadHash); if (isContain) error = loadHash; diff --git a/lib/client/load.js b/lib/client/load.js index ac197358..02cce63b 100644 --- a/lib/client/load.js +++ b/lib/client/load.js @@ -194,7 +194,7 @@ var Util, DOM; }); Events.add('readystatechange', xhr, function(event) { - var TYPE_JSON, type, data, isContain, + var TYPE_JSON, type, data, isContain, notText, xhr = event.target; if (xhr.readyState === 4 /* Complete */) { @@ -204,14 +204,13 @@ var Util, DOM; if (xhr.status === 200 /* OK */) { data = xhr.response; - isContain = Util.isContainStr(type, TYPE_JSON); + notText = p.dataType !== 'text', + isContain = ~type.indexOf(TYPE_JSON); - if (p.dataType !== 'text') - /* If it's json - parse it as json */ - if (type && isContain) - data = Util.json.parse(xhr.response) || xhr.response; + if (type && isContain && notText) + data = Util.json.parse(xhr.response) || xhr.response; - Util.exec(p.success, data, xhr.statusText, xhr); + Util.exec(p.success, data, xhr.statusText, xhr); } /* file not found or connection lost */ else { diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index 1d2624de..afc9e385 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -62,7 +62,7 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb; if (!code) code = window.location.search; - isContain = Util.isContainStr(code, '?code='); + isContain = ~code.indexOf('?code='); if (!isContain) DOM.openWindow(URL); diff --git a/lib/server/ponse.js b/lib/server/ponse.js index d31b960a..2bb08cfd 100644 --- a/lib/server/ponse.js +++ b/lib/server/ponse.js @@ -106,12 +106,11 @@ type = ext[extension] || 'text/plain', encoding = ''; - /* if type of file any, but img - then we shoud specify charset */ - isContain = Util.isContainStr(type, ['img', 'image', 'audio']); + isContain = /img|image|audio/.test(type); if (!isContain) encoding = '; charset=UTF-8'; - isContain = Util.isContainStr(p.query, 'download'); + isContain = /download/.test(p.query); if (isContain) type = 'application/octet-stream'; diff --git a/lib/util.js b/lib/util.js index bbd7557b..77463026 100644 --- a/lib/util.js +++ b/lib/util.js @@ -235,40 +235,6 @@ return ret; }; - /** - * function returns is str1 contains str2 - * @param str1 - * @param str2 - */ - - this.isContainStr = function(str1, str2) { - var i, n, str, is, index, - isStr = Util.type.string(str1), - type = Util.type(str2); - - if (isStr) - switch (type) { - case 'array': - n = str2.length; - - for (i = 0; i < n; i++) { - str = str2[i]; - is = Util.isContainStr(str1, str); - - if (is) - break; - } - break; - - case 'string': - index = str1.indexOf(str2); - is = index >= 0; - break; - } - - return is; - }; - /** * function log pArg if it's not empty * @param pArg