diff --git a/lib/client/dom.js b/lib/client/dom.js index f3caf0a9..cfc4347e 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -958,15 +958,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; if (type !== null) { SelectType = type; - /* if type empty - select all files */ - if (type === '') - type = '*'; - - type = '^' + type; /* search from start of line */ - type = Util.replaceStr(type, '.', '\\.'); - type = Util.replaceStr(type, '*', '.*'); - type = Util.replaceStr(type, '?', '.?\\'); - type += '$'; /* search to end of line */ + type = Util.getRegExp(type); n = files && files.length; for (i = 0; i < n; i++) { diff --git a/lib/util.js b/lib/util.js index 76ddc797..a00ab7dc 100644 --- a/lib/util.js +++ b/lib/util.js @@ -559,6 +559,26 @@ return str; }; + /** + * get regexp from wild card + */ + this.getRegExp = function(wildcard) { + var regExp; + + if (!wildcard) + wildcard = '*'; + + wildcard = '^' + wildcard; /* search from start of line */ + wildcard = Util.replaceStr(wildcard, '.', '\\.'); + wildcard = Util.replaceStr(wildcard, '*', '.*'); + wildcard = Util.replaceStr(wildcard, '?', '.?\\'); + wildcard += '$'; /* search to end of line */ + + regExp = new RegExp(wildcard); + + return regExp; + }; + /** * function render template with view * @templ