Edit File by line
/home/barbar84/www/wp-conte.../plugins/file-man.../applicat.../library/js
File: elFinder.js
/**
[0] Fix | Delete
* @class elFinder - file manager for web
[1] Fix | Delete
*
[2] Fix | Delete
* @author Dmitry (dio) Levashov
[3] Fix | Delete
**/
[4] Fix | Delete
var elFinder = function(elm, opts, bootCallback) {
[5] Fix | Delete
"use strict";
[6] Fix | Delete
//this.time('load');
[7] Fix | Delete
var self = this,
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Objects array of jQuery.Deferred that calls before elFinder boot up
[11] Fix | Delete
*
[12] Fix | Delete
* @type Array
[13] Fix | Delete
*/
[14] Fix | Delete
dfrdsBeforeBootup = [],
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Plugin name to check for conflicts with bootstrap etc
[18] Fix | Delete
*
[19] Fix | Delete
* @type Array
[20] Fix | Delete
**/
[21] Fix | Delete
conflictChecks = ['button', 'tooltip'],
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Node on which elfinder creating
[25] Fix | Delete
*
[26] Fix | Delete
* @type jQuery
[27] Fix | Delete
**/
[28] Fix | Delete
node = $(elm),
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Object of events originally registered in this node
[32] Fix | Delete
*
[33] Fix | Delete
* @type Object
[34] Fix | Delete
*/
[35] Fix | Delete
prevEvents = $.extend(true, {}, $._data(node.get(0), 'events')),
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Store node contents.
[39] Fix | Delete
*
[40] Fix | Delete
* @see this.destroy
[41] Fix | Delete
* @type jQuery
[42] Fix | Delete
**/
[43] Fix | Delete
prevContent = $('<div></div>').append(node.contents()).attr('class', node.attr('class') || '').attr('style', node.attr('style') || ''),
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Instance ID. Required to get/set cookie
[47] Fix | Delete
*
[48] Fix | Delete
* @type String
[49] Fix | Delete
**/
[50] Fix | Delete
id = node.attr('id') || node.attr('id', 'elfauto' + $('.elfinder').length).attr('id'),
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Events namespace
[54] Fix | Delete
*
[55] Fix | Delete
* @type String
[56] Fix | Delete
**/
[57] Fix | Delete
namespace = 'elfinder-' + id,
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Mousedown event
[61] Fix | Delete
*
[62] Fix | Delete
* @type String
[63] Fix | Delete
**/
[64] Fix | Delete
mousedown = 'mousedown.'+namespace,
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Keydown event
[68] Fix | Delete
*
[69] Fix | Delete
* @type String
[70] Fix | Delete
**/
[71] Fix | Delete
keydown = 'keydown.'+namespace,
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Keypress event
[75] Fix | Delete
*
[76] Fix | Delete
* @type String
[77] Fix | Delete
**/
[78] Fix | Delete
keypress = 'keypress.'+namespace,
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Keypup event
[82] Fix | Delete
*
[83] Fix | Delete
* @type String
[84] Fix | Delete
**/
[85] Fix | Delete
keyup = 'keyup.'+namespace,
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Is shortcuts/commands enabled
[89] Fix | Delete
*
[90] Fix | Delete
* @type Boolean
[91] Fix | Delete
**/
[92] Fix | Delete
enabled = false,
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Store enabled value before ajax request
[96] Fix | Delete
*
[97] Fix | Delete
* @type Boolean
[98] Fix | Delete
**/
[99] Fix | Delete
prevEnabled = false,
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* List of build-in events which mapped into methods with same names
[103] Fix | Delete
*
[104] Fix | Delete
* @type Array
[105] Fix | Delete
**/
[106] Fix | Delete
events = ['enable', 'disable', 'load', 'open', 'reload', 'select', 'add', 'remove', 'change', 'dblclick', 'getfile', 'lockfiles', 'unlockfiles', 'selectfiles', 'unselectfiles', 'dragstart', 'dragstop', 'search', 'searchend', 'viewchange'],
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* Rules to validate data from backend
[110] Fix | Delete
*
[111] Fix | Delete
* @type Object
[112] Fix | Delete
**/
[113] Fix | Delete
rules = {},
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Current working directory hash
[117] Fix | Delete
*
[118] Fix | Delete
* @type String
[119] Fix | Delete
**/
[120] Fix | Delete
cwd = '',
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Current working directory options default
[124] Fix | Delete
*
[125] Fix | Delete
* @type Object
[126] Fix | Delete
**/
[127] Fix | Delete
cwdOptionsDefault = {
[128] Fix | Delete
path : '',
[129] Fix | Delete
url : '',
[130] Fix | Delete
tmbUrl : '',
[131] Fix | Delete
disabled : [],
[132] Fix | Delete
separator : '/',
[133] Fix | Delete
archives : [],
[134] Fix | Delete
extract : [],
[135] Fix | Delete
copyOverwrite : true,
[136] Fix | Delete
uploadOverwrite : true,
[137] Fix | Delete
uploadMaxSize : 0,
[138] Fix | Delete
jpgQuality : 100,
[139] Fix | Delete
tmbCrop : false,
[140] Fix | Delete
tmbReqCustomData : false,
[141] Fix | Delete
tmb : false // old API
[142] Fix | Delete
},
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Current working directory options
[146] Fix | Delete
*
[147] Fix | Delete
* @type Object
[148] Fix | Delete
**/
[149] Fix | Delete
cwdOptions = {},
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Files/dirs cache
[153] Fix | Delete
*
[154] Fix | Delete
* @type Object
[155] Fix | Delete
**/
[156] Fix | Delete
files = {},
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Hidden Files/dirs cache
[160] Fix | Delete
*
[161] Fix | Delete
* @type Object
[162] Fix | Delete
**/
[163] Fix | Delete
hiddenFiles = {},
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Files/dirs hash cache of each dirs
[167] Fix | Delete
*
[168] Fix | Delete
* @type Object
[169] Fix | Delete
**/
[170] Fix | Delete
ownFiles = {},
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Selected files hashes
[174] Fix | Delete
*
[175] Fix | Delete
* @type Array
[176] Fix | Delete
**/
[177] Fix | Delete
selected = [],
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Events listeners
[181] Fix | Delete
*
[182] Fix | Delete
* @type Object
[183] Fix | Delete
**/
[184] Fix | Delete
listeners = {},
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Shortcuts
[188] Fix | Delete
*
[189] Fix | Delete
* @type Object
[190] Fix | Delete
**/
[191] Fix | Delete
shortcuts = {},
[192] Fix | Delete
[193] Fix | Delete
/**
[194] Fix | Delete
* Buffer for copied files
[195] Fix | Delete
*
[196] Fix | Delete
* @type Array
[197] Fix | Delete
**/
[198] Fix | Delete
clipboard = [],
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Copied/cuted files hashes
[202] Fix | Delete
* Prevent from remove its from cache.
[203] Fix | Delete
* Required for dispaly correct files names in error messages
[204] Fix | Delete
*
[205] Fix | Delete
* @type Object
[206] Fix | Delete
**/
[207] Fix | Delete
remember = {},
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Queue for 'open' requests
[211] Fix | Delete
*
[212] Fix | Delete
* @type Array
[213] Fix | Delete
**/
[214] Fix | Delete
queue = [],
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* Queue for only cwd requests e.g. `tmb`
[218] Fix | Delete
*
[219] Fix | Delete
* @type Array
[220] Fix | Delete
**/
[221] Fix | Delete
cwdQueue = [],
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Commands prototype
[225] Fix | Delete
*
[226] Fix | Delete
* @type Object
[227] Fix | Delete
**/
[228] Fix | Delete
base = new self.command(self),
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* elFinder node width
[232] Fix | Delete
*
[233] Fix | Delete
* @type String
[234] Fix | Delete
* @default "auto"
[235] Fix | Delete
**/
[236] Fix | Delete
width = 'auto',
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* elFinder node height
[240] Fix | Delete
* Number: pixcel or String: Number + "%"
[241] Fix | Delete
*
[242] Fix | Delete
* @type Number | String
[243] Fix | Delete
* @default 400
[244] Fix | Delete
**/
[245] Fix | Delete
height = 400,
[246] Fix | Delete
[247] Fix | Delete
/**
[248] Fix | Delete
* Base node object or selector
[249] Fix | Delete
* Element which is the reference of the height percentage
[250] Fix | Delete
*
[251] Fix | Delete
* @type Object|String
[252] Fix | Delete
* @default null | $(window) (if height is percentage)
[253] Fix | Delete
**/
[254] Fix | Delete
heightBase = null,
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* MIME type list(Associative array) handled as a text file
[258] Fix | Delete
*
[259] Fix | Delete
* @type Object|null
[260] Fix | Delete
*/
[261] Fix | Delete
textMimes = null,
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* elfinder path for sound played on remove
[265] Fix | Delete
* @type String
[266] Fix | Delete
* @default ./sounds/
[267] Fix | Delete
**/
[268] Fix | Delete
soundPath = 'sounds/',
[269] Fix | Delete
[270] Fix | Delete
/**
[271] Fix | Delete
* JSON.stringify of previous fm.sorters
[272] Fix | Delete
* @type String
[273] Fix | Delete
*/
[274] Fix | Delete
prevSorterStr = '',
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Map table of file extention to MIME-Type
[278] Fix | Delete
* @type Object
[279] Fix | Delete
*/
[280] Fix | Delete
extToMimeTable,
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Disabled page unload function
[284] Fix | Delete
* @type Boolean
[285] Fix | Delete
*/
[286] Fix | Delete
diableUnloadCheck = false,
[287] Fix | Delete
[288] Fix | Delete
beeper = $(document.createElement('audio')).hide().appendTo('body')[0],
[289] Fix | Delete
[290] Fix | Delete
syncInterval,
[291] Fix | Delete
autoSyncStop = 0,
[292] Fix | Delete
[293] Fix | Delete
uiCmdMapPrev = '',
[294] Fix | Delete
[295] Fix | Delete
gcJobRes = null,
[296] Fix | Delete
[297] Fix | Delete
open = function(data) {
[298] Fix | Delete
// NOTES: Do not touch data object
[299] Fix | Delete
[300] Fix | Delete
var volumeid, contextmenu, emptyDirs = {}, stayDirs = {},
[301] Fix | Delete
rmClass, hashes, calc, gc, collapsed, prevcwd, sorterStr, diff;
[302] Fix | Delete
[303] Fix | Delete
if (self.api >= 2.1) {
[304] Fix | Delete
// support volume driver option `uiCmdMap`
[305] Fix | Delete
self.commandMap = (data.options.uiCmdMap && Object.keys(data.options.uiCmdMap).length)? data.options.uiCmdMap : {};
[306] Fix | Delete
if (uiCmdMapPrev !== JSON.stringify(self.commandMap)) {
[307] Fix | Delete
uiCmdMapPrev = JSON.stringify(self.commandMap);
[308] Fix | Delete
}
[309] Fix | Delete
} else {
[310] Fix | Delete
self.options.sync = 0;
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
if (data.init) {
[314] Fix | Delete
// init - reset cache
[315] Fix | Delete
files = {};
[316] Fix | Delete
ownFiles = {};
[317] Fix | Delete
} else {
[318] Fix | Delete
// remove only files from prev cwd
[319] Fix | Delete
// and collapsed directory (included 100+ directories) to empty for perfomance tune in DnD
[320] Fix | Delete
prevcwd = cwd;
[321] Fix | Delete
rmClass = 'elfinder-subtree-loaded ' + self.res('class', 'navexpand');
[322] Fix | Delete
collapsed = self.res('class', 'navcollapse');
[323] Fix | Delete
hashes = Object.keys(files);
[324] Fix | Delete
calc = function(i) {
[325] Fix | Delete
if (!files[i]) {
[326] Fix | Delete
return true;
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
var isDir = (files[i].mime === 'directory'),
[330] Fix | Delete
phash = files[i].phash,
[331] Fix | Delete
pnav;
[332] Fix | Delete
[333] Fix | Delete
if (
[334] Fix | Delete
(!isDir
[335] Fix | Delete
|| emptyDirs[phash]
[336] Fix | Delete
|| (!stayDirs[phash]
[337] Fix | Delete
&& self.navHash2Elm(files[i].hash).is(':hidden')
[338] Fix | Delete
&& self.navHash2Elm(phash).next('.elfinder-navbar-subtree').children().length > 100
[339] Fix | Delete
)
[340] Fix | Delete
)
[341] Fix | Delete
&& (isDir || phash !== cwd)
[342] Fix | Delete
&& ! remember[i]
[343] Fix | Delete
) {
[344] Fix | Delete
if (isDir && !emptyDirs[phash]) {
[345] Fix | Delete
emptyDirs[phash] = true;
[346] Fix | Delete
self.navHash2Elm(phash)
[347] Fix | Delete
.removeClass(rmClass)
[348] Fix | Delete
.next('.elfinder-navbar-subtree').empty();
[349] Fix | Delete
}
[350] Fix | Delete
deleteCache(files[i]);
[351] Fix | Delete
} else if (isDir) {
[352] Fix | Delete
stayDirs[phash] = true;
[353] Fix | Delete
}
[354] Fix | Delete
};
[355] Fix | Delete
gc = function() {
[356] Fix | Delete
if (hashes.length) {
[357] Fix | Delete
gcJobRes && gcJobRes._abort();
[358] Fix | Delete
gcJobRes = self.asyncJob(calc, hashes, {
[359] Fix | Delete
interval : 20,
[360] Fix | Delete
numPerOnce : 100
[361] Fix | Delete
}).done(function() {
[362] Fix | Delete
var hd = self.storage('hide') || {items: {}};
[363] Fix | Delete
if (Object.keys(hiddenFiles).length) {
[364] Fix | Delete
$.each(hiddenFiles, function(h) {
[365] Fix | Delete
if (!hd.items[h]) {
[366] Fix | Delete
delete hiddenFiles[h];
[367] Fix | Delete
}
[368] Fix | Delete
});
[369] Fix | Delete
}
[370] Fix | Delete
});
[371] Fix | Delete
}
[372] Fix | Delete
};
[373] Fix | Delete
[374] Fix | Delete
self.trigger('filesgc').one('filesgc', function() {
[375] Fix | Delete
hashes = [];
[376] Fix | Delete
});
[377] Fix | Delete
[378] Fix | Delete
self.one('opendone', function() {
[379] Fix | Delete
if (prevcwd !== cwd) {
[380] Fix | Delete
if (! node.data('lazycnt')) {
[381] Fix | Delete
gc();
[382] Fix | Delete
} else {
[383] Fix | Delete
self.one('lazydone', gc);
[384] Fix | Delete
}
[385] Fix | Delete
}
[386] Fix | Delete
});
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
self.sorters = {};
[390] Fix | Delete
cwd = data.cwd.hash;
[391] Fix | Delete
cache(data.files);
[392] Fix | Delete
if (!files[cwd]) {
[393] Fix | Delete
cache([data.cwd]);
[394] Fix | Delete
} else {
[395] Fix | Delete
diff = self.diff([data.cwd], true);
[396] Fix | Delete
if (diff.changed.length) {
[397] Fix | Delete
cache(diff.changed, 'change');
[398] Fix | Delete
self.change({changed: diff.changed});
[399] Fix | Delete
}
[400] Fix | Delete
}
[401] Fix | Delete
data.changed && data.changed.length && cache(data.changed, 'change');
[402] Fix | Delete
[403] Fix | Delete
// trigger event 'sorterupdate'
[404] Fix | Delete
sorterStr = JSON.stringify(self.sorters);
[405] Fix | Delete
if (prevSorterStr !== sorterStr) {
[406] Fix | Delete
self.trigger('sorterupdate');
[407] Fix | Delete
prevSorterStr = sorterStr;
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
self.lastDir(cwd);
[411] Fix | Delete
[412] Fix | Delete
self.autoSync();
[413] Fix | Delete
},
[414] Fix | Delete
[415] Fix | Delete
/**
[416] Fix | Delete
* Store info about files/dirs in "files" object.
[417] Fix | Delete
*
[418] Fix | Delete
* @param Array files
[419] Fix | Delete
* @param String data type
[420] Fix | Delete
* @return void
[421] Fix | Delete
**/
[422] Fix | Delete
cache = function(data, type) {
[423] Fix | Delete
var type = type || 'files',
[424] Fix | Delete
keeps = ['sizeInfo', 'encoding'],
[425] Fix | Delete
defsorter = { name: true, perm: true, date: true, size: true, kind: true },
[426] Fix | Delete
sorterChk = !self.sorters._checked && (type === 'files'),
[427] Fix | Delete
l = data.length,
[428] Fix | Delete
setSorter = function(file) {
[429] Fix | Delete
var f = file || {},
[430] Fix | Delete
sorters = [];
[431] Fix | Delete
$.each(self.sortRules, function(key) {
[432] Fix | Delete
if (defsorter[key] || typeof f[key] !== 'undefined' || (key === 'mode' && typeof f.perm !== 'undefined')) {
[433] Fix | Delete
sorters.push(key);
[434] Fix | Delete
}
[435] Fix | Delete
});
[436] Fix | Delete
self.sorters = self.arrayFlip(sorters, true);
[437] Fix | Delete
self.sorters._checked = true;
[438] Fix | Delete
},
[439] Fix | Delete
changedParents = {},
[440] Fix | Delete
hideData = self.storage('hide') || {},
[441] Fix | Delete
hides = hideData.items || {},
[442] Fix | Delete
f, i, i1, keepProp, parents, hidden;
[443] Fix | Delete
[444] Fix | Delete
for (i = 0; i < l; i++) {
[445] Fix | Delete
f = Object.assign({}, data[i]);
[446] Fix | Delete
hidden = (!hideData.show && hides[f.hash])? true : false;
[447] Fix | Delete
if (f.name && f.hash && f.mime) {
[448] Fix | Delete
if (!hidden) {
[449] Fix | Delete
if (sorterChk && f.phash === cwd) {
[450] Fix | Delete
setSorter(f);
[451] Fix | Delete
sorterChk = false;
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
if (f.phash && (type === 'add' || (type === 'change' && (!files[f.hash] || f.size !== files[f.hash])))) {
[455] Fix | Delete
if (parents = self.parents(f.phash)) {
[456] Fix | Delete
$.each(parents, function() {
[457] Fix | Delete
changedParents[this] = true;
[458] Fix | Delete
});
[459] Fix | Delete
}
[460] Fix | Delete
}
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
if (files[f.hash]) {
[464] Fix | Delete
for (i1 =0; i1 < keeps.length; i1++) {
[465] Fix | Delete
if(files[f.hash][keeps[i1]] && ! f[keeps[i1]]) {
[466] Fix | Delete
f[keeps[i1]] = files[f.hash][keeps[i1]];
[467] Fix | Delete
}
[468] Fix | Delete
}
[469] Fix | Delete
if (f.sizeInfo && !f.size) {
[470] Fix | Delete
f.size = f.sizeInfo.size;
[471] Fix | Delete
}
[472] Fix | Delete
deleteCache(files[f.hash], true);
[473] Fix | Delete
}
[474] Fix | Delete
if (hides[f.hash]) {
[475] Fix | Delete
hiddenFiles[f.hash] = f;
[476] Fix | Delete
}
[477] Fix | Delete
if (hidden) {
[478] Fix | Delete
l--;
[479] Fix | Delete
data.splice(i--, 1);
[480] Fix | Delete
} else {
[481] Fix | Delete
files[f.hash] = f;
[482] Fix | Delete
if (f.mime === 'directory' && !ownFiles[f.hash]) {
[483] Fix | Delete
ownFiles[f.hash] = {};
[484] Fix | Delete
}
[485] Fix | Delete
if (f.phash) {
[486] Fix | Delete
if (!ownFiles[f.phash]) {
[487] Fix | Delete
ownFiles[f.phash] = {};
[488] Fix | Delete
}
[489] Fix | Delete
ownFiles[f.phash][f.hash] = true;
[490] Fix | Delete
}
[491] Fix | Delete
}
[492] Fix | Delete
}
[493] Fix | Delete
}
[494] Fix | Delete
// delete sizeInfo cache
[495] Fix | Delete
$.each(Object.keys(changedParents), function() {
[496] Fix | Delete
var target = files[this];
[497] Fix | Delete
if (target && target.sizeInfo) {
[498] Fix | Delete
delete target.sizeInfo;
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function