mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(util) rm isContainStr
This commit is contained in:
parent
ad87145c42
commit
5d4db87a96
5 changed files with 10 additions and 46 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
34
lib/util.js
34
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue