diff --git a/js/commands/archive.js b/js/commands/archive.js index 92559ecf0f..b66df77616 100644 --- a/js/commands/archive.js +++ b/js/commands/archive.js @@ -33,12 +33,12 @@ elFinder.prototype.commands.archive = function() { this.getstate = function(select) { var sel = this.files(select), cnt = sel.length, - chk = (cnt && ! fm.isRoot(sel[0]) && (fm.file(sel[0].phash) || {}).write && ! $.map(sel, function(f){ return f.read ? null : true; }).length), + chk = (cnt && ! fm.isRoot(sel[0]) && (fm.file(sel[0].phash) || {}).write && ! $.grep(sel, function(f){ return f.read ? false : true; }).length), cwdId; if (chk && fm.searchStatus.state > 1) { cwdId = fm.cwd().volumeid; - chk = (cnt === $.map(sel, function(f) { return f.read && f.hash.indexOf(cwdId) === 0 ? f : null; }).length); + chk = (cnt === $.grep(sel, function(f) { return f.read && f.hash.indexOf(cwdId) === 0 ? true : false; }).length); } return chk && !this._disabled && mimes.length && (cnt || (dfrd && dfrd.state() == 'pending')) ? 0 : -1; diff --git a/js/commands/chmod.js b/js/commands/chmod.js index 8896bf8ccd..a63526eed9 100644 --- a/js/commands/chmod.js +++ b/js/commands/chmod.js @@ -55,8 +55,8 @@ elFinder.prototype.commands.chmod = function() { this.checkstate = function(sel) { var cnt = sel.length; if (!cnt) return false; - var chk = $.map(sel, function(f) { - return (f.isowner && f.perm && isPerm(f.perm) && (cnt == 1 || f.mime != 'directory')) ? f : null; + var chk = $.grep(sel, function(f) { + return (f.isowner && f.perm && isPerm(f.perm) && (cnt == 1 || f.mime != 'directory')) ? true : false; }).length; return (cnt == chk)? true : false; }; diff --git a/js/commands/copy.js b/js/commands/copy.js index a757298e70..a2072dcbf3 100644 --- a/js/commands/copy.js +++ b/js/commands/copy.js @@ -15,7 +15,7 @@ elFinder.prototype.commands.copy = function() { var sel = this.files(select), cnt = sel.length; - return cnt && $.map(sel, function(f) { return f.read ? f : null; }).length == cnt ? 0 : -1; + return cnt && $.grep(sel, function(f) { return f.read ? true : false; }).length == cnt ? 0 : -1; }; this.exec = function(hashes) { diff --git a/js/commands/cut.js b/js/commands/cut.js index 323177c0c8..2f00f3ea85 100644 --- a/js/commands/cut.js +++ b/js/commands/cut.js @@ -17,7 +17,7 @@ elFinder.prototype.commands.cut = function() { var sel = this.files(select), cnt = sel.length; - return cnt && $.map(sel, function(f) { return f.read && ! f.locked && ! fm.isRoot(f) ? f : null; }).length == cnt ? 0 : -1; + return cnt && $.grep(sel, function(f) { return f.read && ! f.locked && ! fm.isRoot(f) ? true : false; }).length == cnt ? 0 : -1; }; this.exec = function(hashes) { diff --git a/js/commands/download.js b/js/commands/download.js index c6efca0b4d..e362f9a0e4 100644 --- a/js/commands/download.js +++ b/js/commands/download.js @@ -33,9 +33,9 @@ elFinder.prototype.commands.download = function() { if (mixed) { mixedCmd = czipdl? 'zipdl' : 'download'; - hashes = $.map(hashes, function(h) { + hashes = $.grep(hashes, function(h) { var f = fm.file(h), - res = (! f || (! czipdl && f.mime === 'directory') || ! fm.isCommandEnabled(mixedCmd, h))? null : h; + res = (! f || (! czipdl && f.mime === 'directory') || ! fm.isCommandEnabled(mixedCmd, h))? false : true; if (f && inExec && ! res) { $('#' + fm.cwdHash2Id(f.hash)).trigger('unselect'); } @@ -50,8 +50,8 @@ elFinder.prototype.commands.download = function() { } } - return $.map(self.files(hashes), function(f) { - var res = (! f.read || (! zipOn && f.mime == 'directory')) ? null : f; + return $.grep(self.files(hashes), function(f) { + var res = (! f.read || (! zipOn && f.mime == 'directory')) ? false : true; if (inExec && ! res) { $('#' + fm.cwdHash2Id(f.hash)).trigger('unselect'); } @@ -317,7 +317,7 @@ elFinder.prototype.commands.download = function() { return dfrd.reject(); } - fileCnt = $.map(files, function(f) { return f.mime === 'directory'? null : true; }).length; + fileCnt = $.grep(files, function(f) { return f.mime === 'directory'? false : true; }).length; link = $('').hide().appendTo('body'); html5dl = (typeof link.get(0).download === 'string'); diff --git a/js/commands/duplicate.js b/js/commands/duplicate.js index 98d5652cfe..2905b4a343 100644 --- a/js/commands/duplicate.js +++ b/js/commands/duplicate.js @@ -13,7 +13,7 @@ elFinder.prototype.commands.duplicate = function() { var sel = this.files(select), cnt = sel.length; - return cnt && fm.cwd().write && $.map(sel, function(f) { return f.read && f.phash === fm.cwd().hash && ! fm.isRoot(f)? f : null; }).length == cnt ? 0 : -1; + return cnt && fm.cwd().write && $.grep(sel, function(f) { return f.read && f.phash === fm.cwd().hash && ! fm.isRoot(f)? true : false; }).length == cnt ? 0 : -1; }; this.exec = function(hashes) { diff --git a/js/commands/edit.js b/js/commands/edit.js index f2d080790e..e01c87fed7 100644 --- a/js/commands/edit.js +++ b/js/commands/edit.js @@ -43,16 +43,16 @@ elFinder.prototype.commands.edit = function() { mime = files[0].mime; ext = files[0].name.replace(/^.*(\.[^.]+)$/, '$1'); } - return $.map(files, function(file) { + return $.grep(files, function(file) { var res; if (skip) { - return null; + return false; } res = (fm.mimeIsText(file.mime) || $.inArray(file.mime, cnt === 1? mimesSingle : mimes) !== -1) && (!self.onlyMimes.length || $.inArray(file.mime, self.onlyMimes) !== -1) && file.read && file.write && (cnt === 1 || (file.mime === mime && file.name.substr(ext.length * -1) === ext)) - && fm.uploadMimeCheck(file.mime, file.phash)? file : null; + && fm.uploadMimeCheck(file.mime, file.phash)? true : false; if (!res) { skip = true; } @@ -670,11 +670,11 @@ elFinder.prototype.commands.edit = function() { dfd.always(function() { if (ccData) { - opts.editors = $.map(opts.editors, function(e) { + opts.editors = $.grep(opts.editors, function(e) { if (e.info && e.info.cmdCheck) { - return ccData[e.info.cmdCheck]? e : null; + return ccData[e.info.cmdCheck]? true : false; } else { - return e; + return true; } }); } @@ -695,8 +695,8 @@ elFinder.prototype.commands.edit = function() { mimesSingle = ($.uniqueSort || $.unique)(mimesSingle); mimes = ($.uniqueSort || $.unique)(mimes); - opts.editors = $.map(opts.editors, function(e) { - return e.disabled? null : e; + opts.editors = $.grep(opts.editors, function(e) { + return e.disabled? false : true; }); }); } diff --git a/js/commands/empty.js b/js/commands/empty.js index 87f5ee2b02..c8f26b084a 100644 --- a/js/commands/empty.js +++ b/js/commands/empty.js @@ -24,7 +24,7 @@ elFinder.prototype.commands.empty = function() { cnt; cnt = sel.length; - return $.map(sel, function(f) { return f.write && f.mime === 'directory' ? f : null; }).length == cnt ? 0 : -1; + return $.grep(sel, function(f) { return f.write && f.mime === 'directory' ? true : false; }).length == cnt ? 0 : -1; }; this.exec = function(hashes) { diff --git a/js/commands/extract.js b/js/commands/extract.js index 0166e6f115..87fb033b30 100644 --- a/js/commands/extract.js +++ b/js/commands/extract.js @@ -10,8 +10,8 @@ elFinder.prototype.commands.extract = function() { fm = self.fm, mimes = [], filter = function(files) { - return $.map(files, function(file) { - return file.read && $.inArray(file.mime, mimes) !== -1 ? file : null; + return $.grep(files, function(file) { + return file.read && $.inArray(file.mime, mimes) !== -1 ? true : false; }); }; @@ -50,7 +50,10 @@ elFinder.prototype.commands.extract = function() { var names = $.map(fm.files(hashes), function(file) { return file.name; }); var map = {}; - $.map(fm.files(hashes), function(file) { map[file.name] = file; }); + $.grep(fm.files(hashes), function(file) { + map[file.name] = file; + return false; + }); var decide = function(decision) { switch (decision) { diff --git a/js/commands/getfile.js b/js/commands/getfile.js index c5357bdf58..deab0edc44 100644 --- a/js/commands/getfile.js +++ b/js/commands/getfile.js @@ -12,8 +12,8 @@ filter = function(files) { var o = self.options; - files = $.map(files, function(file) { - return (file.mime != 'directory' || o.folders) && file.read ? file : null; + files = $.grep(files, function(file) { + return (file.mime != 'directory' || o.folders) && file.read ? true : false; }); return o.multiple || files.length == 1 ? files : []; diff --git a/js/commands/help.js b/js/commands/help.js index d7b0c3d563..5dec5212ae 100644 --- a/js/commands/help.js +++ b/js/commands/help.js @@ -263,8 +263,8 @@ forms.toolbarPref && (forms.toolbarPref = (function() { var node = $('
'); init(function() { - var pnls = $.map(fm.options.uiOptions.toolbar, function(v) { - return $.isArray(v)? v : null; + var pnls = $.grep(fm.options.uiOptions.toolbar, function(v) { + return $.isArray(v)? true : false; }), tags = [], hides = fm.storage('toolbarhides') || {}; diff --git a/js/commands/info.js b/js/commands/info.js index 479e623ece..2997ad9c85 100644 --- a/js/commands/info.js +++ b/js/commands/info.js @@ -191,7 +191,7 @@ if (o.custom) { $.each(o.custom, function(name, details) { if ( - (!details.mimes || $.map(details.mimes, function(m){return (file.mime === m || file.mime.indexOf(m+'/') === 0)? true : null;}).length) + (!details.mimes || $.grep(details.mimes, function(m){return (file.mime === m || file.mime.indexOf(m+'/') === 0)? true : false;}).length) && (!details.hashRegex || file.hash.match(details.hashRegex)) ) { @@ -207,7 +207,7 @@ } else { view = view.replace('{class}', 'elfinder-cwd-icon-group'); title = tpl.groupTitle.replace('{items}', msg.items).replace('{num}', cnt); - dcnt = $.map(files, function(f) { return f.mime == 'directory' ? 1 : null ; }).length; + dcnt = $.grep(files, function(f) { return f.mime == 'directory' ? true : false ; }).length; if (!dcnt) { size = 0; $.each(files, function(h, f) { @@ -222,7 +222,7 @@ content.push(row.replace(l, msg.kind).replace(v, msg.files)); content.push(row.replace(l, msg.size).replace(v, fm.formatSize(size))); } else { - rdcnt = $.map(files, function(f) { return f.mime === 'directory' && (! f.phash || f.isroot)? 1 : null ; }).length; + rdcnt = $.grep(files, function(f) { return f.mime === 'directory' && (! f.phash || f.isroot)? true : false ; }).length; dcnt -= rdcnt; content.push(row.replace(l, msg.kind).replace(v, (rdcnt === cnt || dcnt === cnt)? msg[rdcnt? 'roots' : 'folders'] : $.map({roots: rdcnt, folders: dcnt, files: cnt - rdcnt - dcnt}, function(c, t) { return c? msg[t]+' '+c : null; }).join(', '))); content.push(row.replace(l, msg.size).replace(v, tpl.spinner.replace('{text}', msg.calc).replace('{name}', 'size'))); diff --git a/js/commands/mkdir.js b/js/commands/mkdir.js index 67f9ab472d..a786a7383f 100644 --- a/js/commands/mkdir.js +++ b/js/commands/mkdir.js @@ -64,7 +64,7 @@ elFinder.prototype.commands.mkdir = function() { if (curOrg === 'navbar') { return cnt && sel[0].write && sel[0].read? 0 : -1; } else { - return cwd.write && (!cnt || $.map(sel, function(f) { return f.read && ! f.locked? f : null; }).length == cnt)? 0 : -1; + return cwd.write && (!cnt || $.grep(sel, function(f) { return f.read && ! f.locked? true : false; }).length == cnt)? 0 : -1; } }; diff --git a/js/commands/open.js b/js/commands/open.js index 4cbbd2f027..5b28a58de9 100644 --- a/js/commands/open.js +++ b/js/commands/open.js @@ -24,7 +24,7 @@ return cnt == 1 ? (sel[0].read? 0 : -1) - : (cnt && !this.fm.UA.Mobile) ? ($.map(sel, function(file) { return file.mime == 'directory' || ! file.read ? null : file;}).length == cnt ? 0 : -1) : -1; + : (cnt && !this.fm.UA.Mobile) ? ($.grep(sel, function(file) { return file.mime == 'directory' || ! file.read ? false : true;}).length == cnt ? 0 : -1) : -1; }; this.exec = function(hashes, cOpts) { @@ -55,7 +55,7 @@ }); } - files = $.map(files, function(file) { return file.mime != 'directory' ? file : null; }); + files = $.grep(files, function(file) { return file.mime != 'directory' ? true : false; }); // nothing to open or files and folders selected - do nothing if (cnt != files.length) { diff --git a/js/commands/paste.js b/js/commands/paste.js index d05c0c6657..99eaa2c6c0 100644 --- a/js/commands/paste.js +++ b/js/commands/paste.js @@ -161,13 +161,13 @@ elFinder.prototype.commands.paste = function() { } } else { existedArr = []; - existed = $.map(names, function(n) { + existed = $.grep(names, function(n) { if (typeof n === 'string') { - return n; + return true; } else { // support to >=2.1.11 plugin Normalizer, Sanitizer existedArr = existedArr.concat(n); - return null; + return false; } }); if (existedArr.length) { @@ -181,11 +181,11 @@ elFinder.prototype.commands.paste = function() { }, paste = function(selFiles) { var renames = [], - files = $.map(selFiles, function(file) { + files = $.grep(selFiles, function(file) { if (file.rename) { renames.push(file.name); } - return !file.remove ? file : null; + return !file.remove ? true : false; }), cnt = files.length, groups = {}, @@ -338,7 +338,7 @@ elFinder.prototype.commands.paste = function() { fparents.pop(); if ($.inArray(dst.hash, fparents) !== -1) { - if ($.map(fparents, function(h) { var d = fm.file(h); return d.phash == dst.hash && d.name == file.name ? d : null; }).length) { + if ($.grep(fparents, function(h) { var d = fm.file(h); return d.phash == dst.hash && d.name == file.name ? true : false; }).length) { return !dfrd.reject(['errReplByChild', file.name]); } } diff --git a/js/commands/places.js b/js/commands/places.js index cadbd15010..27bf1d6393 100644 --- a/js/commands/places.js +++ b/js/commands/places.js @@ -9,7 +9,7 @@ elFinder.prototype.commands.places = function() { var self = this, fm = this.fm, filter = function(hashes) { - return $.map(self.files(hashes), function(f) { return f.mime == 'directory' ? f : null; }); + return $.grep(self.files(hashes), function(f) { return f.mime == 'directory' ? true : false; }); }, places = null; diff --git a/js/commands/rename.js b/js/commands/rename.js index 0cb183a667..8f135d66e4 100644 --- a/js/commands/rename.js +++ b/js/commands/rename.js @@ -221,12 +221,12 @@ elFinder.prototype.commands.rename = function() { mime = sel[0].mime; } - state = ((cnt === 1 && !sel[0].locked && !fm.isRoot(sel[0])) || (fm.api > 2.1030 && cnt === $.map(sel, function(f) { + state = ((cnt === 1 && !sel[0].locked && !fm.isRoot(sel[0])) || (fm.api > 2.1030 && cnt === $.grep(sel, function(f) { if (!brk && !f.locked && f.phash === phash && !fm.isRoot(f) && (mime === f.mime || ext === fm.splitFileExtention(f.name)[1].toLowerCase())) { - return f; + return true; } else { - brk = true; - return null; + brk && (brk = true); + return false; } }).length)) ? 0 : -1; diff --git a/js/commands/restore.js b/js/commands/restore.js index 5dea47a5d2..fa07aefd67 100644 --- a/js/commands/restore.js +++ b/js/commands/restore.js @@ -246,7 +246,7 @@ this.getstate = function(sel, e) { sel = sel || fm.selected(); - return sel.length && $.map(sel, function(h) {var f = fm.file(h); return f && ! f.locked && ! fm.isRoot(f)? h : null; }).length == sel.length + return sel.length && $.grep(sel, function(h) {var f = fm.file(h); return f && ! f.locked && ! fm.isRoot(f)? true : false; }).length == sel.length ? 0 : -1; }; diff --git a/js/commands/rm.js b/js/commands/rm.js index abcf7fa7c9..ee3d64d5e0 100644 --- a/js/commands/rm.js +++ b/js/commands/rm.js @@ -278,8 +278,8 @@ elFinder.prototype.commands.rm = function() { if (Object.keys(res).length) { if (err.length > 1) { if (res.removed || res.removed.length) { - hashes = $.map(targets, function(h) { - return $.inArray(h, res.removed) === -1? h : null; + hashes = $.grep(targets, function(h) { + return $.inArray(h, res.removed) === -1? true : false; }); } if (hashes.length) { @@ -350,7 +350,7 @@ elFinder.prototype.commands.rm = function() { if (targets && targets.length) { if (targets.length > 1 && fm.searchStatus.state === 2) { root1st = fm.file(fm.root(targets[0])).volumeid; - if (!$.map(targets, function(h) { return h.indexOf(root1st) !== 0? 1 : null ; }).length) { + if (!$.grep(targets, function(h) { return h.indexOf(root1st) !== 0? true : false ; }).length) { thash = fm.option('trashHash', targets[0]); } } else { @@ -406,7 +406,7 @@ elFinder.prototype.commands.rm = function() { this.getstate = function(select) { var sel = this.hashes(select); - return sel.length && $.map(sel, function(h) { var f = fm.file(h); return f && ! f.locked && ! fm.isRoot(f)? h : null; }).length == sel.length + return sel.length && $.grep(sel, function(h) { var f = fm.file(h); return f && ! f.locked && ! fm.isRoot(f)? true : false; }).length == sel.length ? 0 : -1; }; diff --git a/js/commands/search.js b/js/commands/search.js index be8971f85c..ada7fe354f 100644 --- a/js/commands/search.js +++ b/js/commands/search.js @@ -45,7 +45,7 @@ elFinder.prototype.commands.search = function() { mime = $.map(mime, function(m){ m = $.trim(m); return m && ($.inArray(m, onlyMimes) !== -1 - || $.map(onlyMimes, function(om) { return m.indexOf(om) === 0? true : null; }).length + || $.grep(onlyMimes, function(om) { return m.indexOf(om) === 0? true : false; }).length )? m : null; }); } diff --git a/js/commands/upload.js b/js/commands/upload.js index 739e1595c5..727221f6a7 100644 --- a/js/commands/upload.js +++ b/js/commands/upload.js @@ -95,8 +95,8 @@ elFinder.prototype.commands.upload = function() { }, getSelector = function() { var hash = targetDir.hash, - dirs = $.map(fm.files(hash), function(f) { - return (f.mime === 'directory' && f.write)? f : null; + dirs = $.grep(fm.files(hash), function(f) { + return (f.mime === 'directory' && f.write)? true : false; }); if (! dirs.length) { diff --git a/js/elFinder.command.js b/js/elFinder.command.js index 2b7d98e378..ec5f490e60 100644 --- a/js/elFinder.command.js +++ b/js/elFinder.command.js @@ -326,7 +326,7 @@ elFinder.prototype.command = function(fm) { */ this.hashes = function(hashes) { return hashes - ? $.map(Array.isArray(hashes) ? hashes : [hashes], function(hash) { return fm.file(hash) ? hash : null; }) + ? $.grep(Array.isArray(hashes) ? hashes : [hashes], function(hash) { return fm.file(hash) ? true : false; }) : fm.selected(); }; diff --git a/js/elFinder.js b/js/elFinder.js index 9d45209411..fb993fdc43 100644 --- a/js/elFinder.js +++ b/js/elFinder.js @@ -1200,7 +1200,7 @@ var elFinder = function(elm, opts, bootCallback) { autoDisable: true, // elFinder original, see jquery.elfinder.js drop : function(e, ui) { var dst = $(this), - targets = $.map(ui.helper.data('files')||[], function(h) { return h || null; }), + targets = $.grep(ui.helper.data('files')||[], function(h) { return h? true : false; }), result = [], dups = [], faults = [], @@ -2142,8 +2142,8 @@ var elFinder = function(elm, opts, bootCallback) { // unset this cmd queue when user canceling if (error === 0) { if (requestQueue.length) { - requestQueue = $.map(requestQueue, function(req) { - return (req('cmd') === cmd) ? null : req; + requestQueue = $.grep(requestQueue, function(req) { + return (req('cmd') === cmd) ? false : true; }); } } @@ -3672,12 +3672,12 @@ var elFinder = function(elm, opts, bootCallback) { .select(function(e) { var cnt = 0, unselects = []; - selected = $.map(e.data.selected || e.data.value|| [], function(hash) { + selected = $.grep(e.data.selected || e.data.value|| [], function(hash) { if (unselects.length || (self.maxTargets && ++cnt > self.maxTargets)) { unselects.push(hash); - return null; + return false; } else { - return files[hash] ? hash : null; + return files[hash] ? true : false; } }); if (unselects.length) { @@ -4102,12 +4102,12 @@ var elFinder = function(elm, opts, bootCallback) { scroll : false, start : function(e, ui) { var helper = ui.helper, - targets = $.map(helper.data('files')||[], function(h) { + targets = $.grep(helper.data('files')||[], function(h) { if (h) { remember[h] = true; - return h; + return true; } - return null; + return false; }), locked = false, cnt, h; @@ -4190,7 +4190,7 @@ var elFinder = function(elm, opts, bootCallback) { self.draggingUiHelper = null; self.trigger('focus').trigger('dragstop'); if (! helper.data('droped')) { - files = $.map(helper.data('files')||[], function(h) { return h || null ;}); + files = $.grep(helper.data('files')||[], function(h) { return h? true : false ;}); self.trigger('unlockfiles', {files : files}); self.trigger('selectfiles', {files : files}); } @@ -5206,13 +5206,13 @@ elFinder.prototype = { existed = data.list || []; } else { existedArr = []; - existed = $.map(data.list, function(n) { + existed = $.grep(data.list, function(n) { if (typeof n === 'string') { - return n; + return true; } else { // support to >=2.1.11 plugin Normalizer, Sanitizer existedArr = existedArr.concat(n); - return null; + return false; } }); if (existedArr.length) { @@ -5220,13 +5220,13 @@ elFinder.prototype = { } hashes = data.list; } - exists = $.map(names, function(name){ - return $.inArray(name.name, existed) !== -1 ? name : null ; + exists = $.grep(names, function(name){ + return $.inArray(name.name, existed) !== -1 ? true : false ; }); if (exists.length && existed.length && target == fm.cwd().hash) { cwdItems = $.map(fm.files(target), function(file) { return file.name; } ); - if ($.map(existed, function(n) { - return $.inArray(n, cwdItems) === -1? true : null; + if ($.grep(existed, function(n) { + return $.inArray(n, cwdItems) === -1? true : false; }).length){ fm.sync(); } @@ -5342,7 +5342,7 @@ elFinder.prototype = { data.overwrite = 0; renames = []; } - items = $.map(items, function(item){ + items = $.grep(items, function(item){ var i, bak, hash, dfd, hi; if (item.isDirectory && renames.length) { i = $.inArray(item.name, renames); @@ -5373,7 +5373,7 @@ elFinder.prototype = { dfds.push(dfd); } } - return !item._remove? item : null; + return !item._remove? true : false; }); } $.when.apply($, dfds).done(function(){ @@ -5661,10 +5661,10 @@ elFinder.prototype = { } else { // ff bug while send zero sized file // for safari - send directory - if (!isDataType && data.files && $.map(data.files, function(f){return ! f.type && f.size === (self.UA.Safari? 1802 : 0)? f : null;}).length) { + if (!isDataType && data.files && $.grep(data.files, function(f){return ! f.type && f.size === (self.UA.Safari? 1802 : 0)? true : false;}).length) { errors.push('errFolderUpload'); dfrd.reject(['errAbort', 'errFolderUpload']); - } else if (data.input && $.map(data.input.files, function(f){return ! f.type && f.size === (self.UA.Safari? 1802 : 0)? f : null;}).length) { + } else if (data.input && $.grep(data.input.files, function(f){return ! f.type && f.size === (self.UA.Safari? 1802 : 0)? true : false;}).length) { dfrd.reject(['errUploadNoFiles']); } else { doRetry(); @@ -6181,7 +6181,7 @@ elFinder.prototype = { var dfds = [], dfd, bak, hash; if (fm.options.overwriteUploadConfirm && fm.option('uploadOverwrite', target)) { cancelDirs = $.map(checkDirs, function(dir) { return dir._remove? dir.name : null ;} ); - checkDirs = $.map(checkDirs, function(dir) { return !dir._remove? dir : null ;} ); + checkDirs = $.grep(checkDirs, function(dir) { return !dir._remove? true : false ;} ); } if (cancelDirs.length) { $.each(paths.concat(), function(i, path) { @@ -6191,8 +6191,8 @@ elFinder.prototype = { } }); } - files = $.map(files, function(file) { return file._remove? null : file; }); - paths = $.map(paths, function(path) { return path === void 0 ? null : path; }); + files = $.grep(files, function(file) { return file._remove? false : true; }); + paths = $.grep(paths, function(path) { return path === void 0 ? false : true; }); if (checkDirs.length) { dfd = $.Deferred(); if (res.length) { @@ -6279,7 +6279,7 @@ elFinder.prototype = { } else { renames = res; } - files = $.map(files, function(file){return !file._remove? file : null ;}); + files = $.grep(files, function(file){return !file._remove? true : false ;}); } cnt = files.length; if (cnt > 0) { @@ -6434,7 +6434,7 @@ elFinder.prototype = { data.overwrite = 0; } else{ renames = res; - cnt = $.map(names, function(file){return !file._remove? file : null ;}).length; + cnt = $.grep(names, function(file){return !file._remove? true : false ;}).length; if (cnt != names.length) { cnt = 0; } @@ -6735,8 +6735,10 @@ elFinder.prototype = { }); return opts; }, - filter = function(file) { - var vid, targetOptions, isRoot; + filter = function(file, asMap) { + var res = asMap? file : true, + ign = asMap? null : false, + vid, targetOptions, isRoot; if (file && file.hash && file.name && file.mime) { if (file.mime == 'application/x-empty') { @@ -6752,11 +6754,11 @@ elFinder.prototype = { if (file.phash) { if (file.phash === file.hash) { error = error.concat(['Parent folder of "$1" is itself.', file.name]); - return null; + return ign; } if (isRoot && file.volumeid && file.phash.indexOf(file.volumeid) === 0) { error = error.concat(['Parent folder of "$1" is inner itself.', file.name]); - return null; + return ign; } } @@ -6855,7 +6857,7 @@ elFinder.prototype = { } else if (fileFilter) { try { if (! fileFilter(file)) { - return null; + return ign; } } catch(e) { self.debug(e); @@ -6868,9 +6870,9 @@ elFinder.prototype = { delete file.options; - return file; + return res; } - return null; + return ign; }, getDescendants = function(hashes) { var res = []; @@ -6896,19 +6898,19 @@ elFinder.prototype = { if (data.cwd.volumeid && data.options && Object.keys(data.options).length && self.isRoot(data.cwd)) { self.volOptions[data.cwd.volumeid] = data.options; } - data.cwd = filter(data.cwd); + data.cwd = filter(data.cwd, true); } if (data.files) { - data.files = $.map(data.files, filter); + data.files = $.grep(data.files, filter); } if (data.tree) { - data.tree = $.map(data.tree, filter); + data.tree = $.grep(data.tree, filter); } if (data.added) { - data.added = $.map(data.added, filter); + data.added = $.grep(data.added, filter); } if (data.changed) { - data.changed = $.map(data.changed, filter); + data.changed = $.grep(data.changed, filter); } if (data.removed && data.removed.length && self.searchStatus.state === 2) { data.removed = data.removed.concat(getDescendants(data.removed)); @@ -7468,7 +7470,7 @@ elFinder.prototype = { input[i] = m; } - return $.map(input, function(m, i) { return $.inArray(i, ignore) === -1 ? m : null; }).join('
'); + return $.grep(input, function(m, i) { return $.inArray(i, ignore) === -1 ? true : false; }).join('
'); }, /** diff --git a/js/proxy/elFinderSupportVer1.js b/js/proxy/elFinderSupportVer1.js index 9015d1e559..2a118437be 100644 --- a/js/proxy/elFinderSupportVer1.js +++ b/js/proxy/elFinderSupportVer1.js @@ -166,8 +166,8 @@ window.elFinderSupportVer1 = function(upload) { files = {}, filter = function(file) { return file && file.hash && file.name && file.mime ? file : null; }, getDirs = function(items) { - return $.map(items, function(i) { - return i && i.mime && i.mime === 'directory'? i : null; + return $.grep(items, function(i) { + return i && i.mime && i.mime === 'directory'? true : false; }); }, getTreeDiff = function(files) { diff --git a/js/ui/cwd.js b/js/ui/cwd.js index c55df37bc8..46ef6c7b7a 100644 --- a/js/ui/cwd.js +++ b/js/ui/cwd.js @@ -2140,8 +2140,8 @@ $.fn.elfindercwd = function(fm, options) { // setup costomCols if (customCols = fm.storage('cwdCols')) { - customCols = $.map(customCols, function(n) { - return (options.listView.columns.indexOf(n) !== -1)? n : null; + customCols = $.grep(customCols, function(n) { + return (options.listView.columns.indexOf(n) !== -1)? true : false; }); if (options.listView.columns.length > customCols.length) { $.each(options.listView.columns, function(i, n) { @@ -2307,9 +2307,9 @@ $.fn.elfindercwd = function(fm, options) { fst = '^'; } regex = new RegExp(fst + q.replace(/([\\*\;\.\?\[\]\{\}\(\)\^\$\-\|])/g, '\\$1'), 'i'); - incHashes = $.map(cwdHashes, function(hash) { + incHashes = $.grep(cwdHashes, function(hash) { var file = fm.file(hash); - return (file && (file.name.match(regex) || (file.i18 && file.i18.match(regex))))? file.hash : null; + return (file && (file.name.match(regex) || (file.i18 && file.i18.match(regex))))? true : false; }); fm.trigger('incsearch', { hashes: incHashes, query: q }) .searchStatus.ininc = true; @@ -2420,7 +2420,7 @@ $.fn.elfindercwd = function(fm, options) { path = f.path || fm.path(f.hash); res = (curPath && path.indexOf(curPath) === 0); if (! res && fm.searchStatus.mixed) { - res = $.map(fm.searchStatus.mixed, function(vid) { return f.hash.indexOf(vid) === 0? true : null; }).length? true : false; + res = $.grep(fm.searchStatus.mixed, function(vid) { return f.hash.indexOf(vid) === 0? true : false; }).length? true : false; } } if (res && inSearch) { @@ -2432,7 +2432,7 @@ $.fn.elfindercwd = function(fm, options) { } return res; }, - files = $.map(e.data.added || [], function(f) { return inTarget(f)? f : null ;}); + files = $.grep(e.data.added || [], function(f) { return inTarget(f)? true : false ;}); add(files); if (fm.searchStatus.state === 2) { $.each(files, function(i, f) { @@ -2460,7 +2460,7 @@ $.fn.elfindercwd = function(fm, options) { } }); } else { - $.each($.map(e.data.changed || [], function(f) { return f.phash == phash ? f : null; }), function(i, file) { + $.each($.grep(e.data.changed || [], function(f) { return f.phash == phash ? true : false; }), function(i, file) { remove([file.hash]); add([file], 'change'); $.inArray(file.hash, sel) !== -1 && selectFile(file.hash); diff --git a/js/ui/navbar.js b/js/ui/navbar.js index cf245a6806..1da8dee655 100644 --- a/js/ui/navbar.js +++ b/js/ui/navbar.js @@ -37,7 +37,7 @@ $.fn.elfindernavbar = function(fm, opts) { if (fm.UA.Touch) { autoHide = fm.storage('autoHide') || {}; if (typeof autoHide.navbar === 'undefined') { - autoHide.navbar = (opts.autoHideUA && opts.autoHideUA.length > 0 && $.map(opts.autoHideUA, function(v){ return fm.UA[v]? true : null; }).length); + autoHide.navbar = (opts.autoHideUA && opts.autoHideUA.length > 0 && $.grep(opts.autoHideUA, function(v){ return fm.UA[v]? true : false; }).length); fm.storage('autoHide', autoHide); } diff --git a/js/ui/places.js b/js/ui/places.js index a58aff6b0d..eecbec8aa6 100644 --- a/js/ui/places.js +++ b/js/ui/places.js @@ -69,7 +69,7 @@ $.fn.elfinderplaces = function(fm, opts) { dat = fm.storage(key); if (typeof dat === 'string') { // old data type elFinder <= 2.1.12 - dat = $.map(dat.split(','), function(hash) { return hash || null;}); + dat = $.grep(dat.split(','), function(hash) { return hash? true : false;}); $.each(dat, function(i, d) { var dir = d.split('#'); dirs[dir[0]] = dir[1]? dir[1] : dir[0]; @@ -384,7 +384,7 @@ $.fn.elfinderplaces = function(fm, opts) { }, over : function(e, ui) { var helper = ui.helper, - dir = $.map(helper.data('files'), function(h) { return (fm.file(h).mime === 'directory' && !dirs[h])? h : null; }); + dir = $.grep(helper.data('files'), function(h) { return (fm.file(h).mime === 'directory' && !dirs[h])? true : false; }); e.stopPropagation(); helper.data('dropover', helper.data('dropover') + 1); if (fm.insideWorkzone(e.pageX, e.pageY)) { diff --git a/js/ui/toolbar.js b/js/ui/toolbar.js index 6f3492e185..ba41a663ac 100644 --- a/js/ui/toolbar.js +++ b/js/ui/toolbar.js @@ -16,12 +16,12 @@ $.fn.elfindertoolbar = function(fm, opts) { showPreferenceButton: 'none' }, filter = function(opts) { - return $.map(opts, function(v) { + return $.grep(opts, function(v) { if ($.isPlainObject(v)) { options = Object.assign(options, v); - return null; + return false; } - return [v]; + return true; }); }, render = function(disabled){ @@ -83,7 +83,7 @@ $.fn.elfindertoolbar = function(fm, opts) { // correction of options.displayTextLabel textLabel = fm.storage('toolbarTextLabel'); if (textLabel === null) { - textLabel = (options.displayTextLabel && (! options.labelExcludeUA || ! options.labelExcludeUA.length || ! $.map(options.labelExcludeUA, function(v){ return fm.UA[v]? true : null; }).length)); + textLabel = (options.displayTextLabel && (! options.labelExcludeUA || ! options.labelExcludeUA.length || ! $.grep(options.labelExcludeUA, function(v){ return fm.UA[v]? true : false; }).length)); } else { textLabel = (textLabel == 1); } @@ -235,7 +235,7 @@ $.fn.elfindertoolbar = function(fm, opts) { if (fm.UA.Touch) { autoHide = fm.storage('autoHide') || {}; if (typeof autoHide.toolbar === 'undefined') { - autoHide.toolbar = (options.autoHideUA && options.autoHideUA.length > 0 && $.map(options.autoHideUA, function(v){ return fm.UA[v]? true : null; }).length); + autoHide.toolbar = (options.autoHideUA && options.autoHideUA.length > 0 && $.grep(options.autoHideUA, function(v){ return fm.UA[v]? true : false; }).length); fm.storage('autoHide', autoHide); } diff --git a/js/ui/tree.js b/js/ui/tree.js index 7a51bcf548..85413a3b62 100644 --- a/js/ui/tree.js +++ b/js/ui/tree.js @@ -442,7 +442,7 @@ $.fn.elfindertree = function(fm, opts) { * @return Array */ filter = function(files) { - return $.map(files||[], function(f) { return f.mime == 'directory' ? f : null; }); + return $.grep(files||[], function(f) { return f.mime == 'directory' ? true : false; }); }, /** @@ -528,23 +528,23 @@ $.fn.elfindertree = function(fm, opts) { } if (data.removed && data.removed.length) { - dirs = $.map(dirs, function(d) { + dirs = $.grep(dirs, function(d) { if (data.removed.indexOf(d.hash) === -1) { - return d; + return true; } else { - changed = true; - return null; + !changed && (changed = true); + return false; } }); } if (data.added && data.added.length) { - dirs = dirs.concat($.map(data.added, function(d) { + dirs = dirs.concat($.grep(data.added, function(d) { if (hashes[d.hash] === void(0)) { - changed = true; - return d; + !changed && (changed = true); + return true; } else { - return null; + return false; } })); } @@ -1056,8 +1056,8 @@ $.fn.elfindertree = function(fm, opts) { $.each(dirs, function(i, dir) { $('#'+fm.navHash2Id(dir.phash)+sel) - .filter(function() { return $.map($(this).next('.'+subtree).children(), function(n) { - return ($(n).children().hasClass(root))? null : n; + .filter(function() { return $.grep($(this).next('.'+subtree).children(), function(n) { + return ($(n).children().hasClass(root))? false : true; }).length > 0; }) .addClass(cls); }); @@ -1412,9 +1412,9 @@ $.fn.elfindertree = function(fm, opts) { var lock = e.type == 'lockfiles', helperLocked = e.data.helper? e.data.helper.data('locked') : false, act = (lock && !helperLocked) ? 'disable' : 'enable', - dirs = $.map(e.data.files||[], function(h) { + dirs = $.grep(e.data.files||[], function(h) { var dir = fm.file(h); - return dir && dir.mime == 'directory' ? h : null; + return dir && dir.mime == 'directory' ? true : false; }); $.each(dirs, function(i, hash) {