refactor(dom) selectByPatter

This commit is contained in:
coderaiser 2014-02-11 07:34:09 -05:00
parent 26bbb9d944
commit 823c8f3930

View file

@ -1193,9 +1193,9 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
};
function selectByPattern(msg, files) {
var allMsg = 'Specify file type for ' + msg + ' selection',
var n,
allMsg = 'Specify file type for ' + msg + ' selection',
i = 0,
n = files && files.length,
arr = [],
type,
matches = 0,
@ -1219,38 +1219,28 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
type = Util.replaceStr(type, '?', '.?\\');
type += '$'; /* search to end of line */
do {
if (shouldSel)
current = files[i++];
else
/* selected files will decrement in
* they own way
*/
current = files[i];
if (current) {
name = DOM.getCurrentName(current);
n = files && files.length;
for (i = 0; i < n; i++) {
current = files[i];
name = DOM.getCurrentName(current);
if (name !== '..') {
isMatch = name.match(new RegExp(type));
if (name !== '..') {
isMatch = name.match(new RegExp(type));
if (isMatch) {
++matches;
if (isMatch) {
++matches;
isSelected = DOM.isSelected(current);
if (shouldSel)
isSelected = !isSelected;
if (isSelected)
DOM.toggleSelectedFile(current);
} else if (!shouldSel)
++i;
}
isSelected = DOM.isSelected(current);
if (shouldSel)
isSelected = !isSelected;
if (isSelected)
DOM.toggleSelectedFile(current);
} else if (!shouldSel)
++i;
}
} while (current);
}
if (!matches)
Dialog.alert('No matches found!');