Edit File by line
/home/barbar84/www/wp-conte.../plugins/file-man.../applicat.../library/js/commands
File: info.js
/**
[0] Fix | Delete
* @class elFinder command "info".
[1] Fix | Delete
* Display dialog with file properties.
[2] Fix | Delete
*
[3] Fix | Delete
* @author Dmitry (dio) Levashov, dio@std42.ru
[4] Fix | Delete
**/
[5] Fix | Delete
(elFinder.prototype.commands.info = function() {
[6] Fix | Delete
"use strict";
[7] Fix | Delete
var m = 'msg',
[8] Fix | Delete
fm = this.fm,
[9] Fix | Delete
spclass = 'elfinder-spinner',
[10] Fix | Delete
btnclass = 'elfinder-info-button',
[11] Fix | Delete
msg = {
[12] Fix | Delete
calc : fm.i18n('calc'),
[13] Fix | Delete
size : fm.i18n('size'),
[14] Fix | Delete
unknown : fm.i18n('unknown'),
[15] Fix | Delete
path : fm.i18n('path'),
[16] Fix | Delete
aliasfor : fm.i18n('aliasfor'),
[17] Fix | Delete
modify : fm.i18n('modify'),
[18] Fix | Delete
perms : fm.i18n('perms'),
[19] Fix | Delete
locked : fm.i18n('locked'),
[20] Fix | Delete
dim : fm.i18n('dim'),
[21] Fix | Delete
kind : fm.i18n('kind'),
[22] Fix | Delete
files : fm.i18n('files'),
[23] Fix | Delete
folders : fm.i18n('folders'),
[24] Fix | Delete
roots : fm.i18n('volumeRoots'),
[25] Fix | Delete
items : fm.i18n('items'),
[26] Fix | Delete
yes : fm.i18n('yes'),
[27] Fix | Delete
no : fm.i18n('no'),
[28] Fix | Delete
link : fm.i18n('link'),
[29] Fix | Delete
owner : fm.i18n('owner'),
[30] Fix | Delete
group : fm.i18n('group'),
[31] Fix | Delete
perm : fm.i18n('perm'),
[32] Fix | Delete
getlink : fm.i18n('getLink')
[33] Fix | Delete
},
[34] Fix | Delete
applyZWSP = function(str, remove) {
[35] Fix | Delete
if (remove) {
[36] Fix | Delete
return str.replace(/\u200B/g, '');
[37] Fix | Delete
} else {
[38] Fix | Delete
return str.replace(/(\/|\\)/g, "$1\u200B");
[39] Fix | Delete
}
[40] Fix | Delete
};
[41] Fix | Delete
[42] Fix | Delete
this.items = ['size', 'aliasfor', 'path', 'link', 'dim', 'modify', 'perms', 'locked', 'owner', 'group', 'perm'];
[43] Fix | Delete
if (this.options.custom && Object.keys(this.options.custom).length) {
[44] Fix | Delete
$.each(this.options.custom, function(name, details) {
[45] Fix | Delete
details.label && this.items.push(details.label);
[46] Fix | Delete
});
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
this.tpl = {
[50] Fix | Delete
main : '<div class="ui-helper-clearfix elfinder-info-title {dirclass}"><span class="elfinder-cwd-icon {class} ui-corner-all"{style}></span>{title}</div><table class="elfinder-info-tb">{content}</table>',
[51] Fix | Delete
itemTitle : '<strong>{name}</strong><span class="elfinder-info-kind">{kind}</span>',
[52] Fix | Delete
groupTitle : '<strong>{items}: {num}</strong>',
[53] Fix | Delete
row : '<tr><td class="elfinder-info-label">{label} : </td><td class="{class}">{value}</td></tr>',
[54] Fix | Delete
spinner : '<span>{text}</span> <span class="'+spclass+' '+spclass+'-{name}"></span>'
[55] Fix | Delete
};
[56] Fix | Delete
[57] Fix | Delete
this.alwaysEnabled = true;
[58] Fix | Delete
this.updateOnSelect = false;
[59] Fix | Delete
this.shortcuts = [{
[60] Fix | Delete
pattern : 'ctrl+i'
[61] Fix | Delete
}];
[62] Fix | Delete
[63] Fix | Delete
this.init = function() {
[64] Fix | Delete
$.each(msg, function(k, v) {
[65] Fix | Delete
msg[k] = fm.i18n(v);
[66] Fix | Delete
});
[67] Fix | Delete
};
[68] Fix | Delete
[69] Fix | Delete
this.getstate = function() {
[70] Fix | Delete
return 0;
[71] Fix | Delete
};
[72] Fix | Delete
[73] Fix | Delete
this.exec = function(hashes) {
[74] Fix | Delete
var files = this.files(hashes);
[75] Fix | Delete
if (! files.length) {
[76] Fix | Delete
files = this.files([ this.fm.cwd().hash ]);
[77] Fix | Delete
}
[78] Fix | Delete
var self = this,
[79] Fix | Delete
fm = this.fm,
[80] Fix | Delete
o = this.options,
[81] Fix | Delete
tpl = this.tpl,
[82] Fix | Delete
row = tpl.row,
[83] Fix | Delete
cnt = files.length,
[84] Fix | Delete
content = [],
[85] Fix | Delete
view = tpl.main,
[86] Fix | Delete
l = '{label}',
[87] Fix | Delete
v = '{value}',
[88] Fix | Delete
reqs = [],
[89] Fix | Delete
reqDfrd = null,
[90] Fix | Delete
opts = {
[91] Fix | Delete
title : fm.i18n('selectionInfo'),
[92] Fix | Delete
width : 'auto',
[93] Fix | Delete
close : function() {
[94] Fix | Delete
$(this).elfinderdialog('destroy');
[95] Fix | Delete
if (reqDfrd && reqDfrd.state() === 'pending') {
[96] Fix | Delete
reqDfrd.reject();
[97] Fix | Delete
}
[98] Fix | Delete
$.grep(reqs, function(r) {
[99] Fix | Delete
r && r.state() === 'pending' && r.reject();
[100] Fix | Delete
});
[101] Fix | Delete
}
[102] Fix | Delete
},
[103] Fix | Delete
count = [],
[104] Fix | Delete
replSpinner = function(msg, name, className) {
[105] Fix | Delete
dialog.find('.'+spclass+'-'+name).parent().html(msg).addClass(className || '');
[106] Fix | Delete
},
[107] Fix | Delete
id = fm.namespace+'-info-'+$.map(files, function(f) { return f.hash; }).join('-'),
[108] Fix | Delete
dialog = fm.getUI().find('#'+id),
[109] Fix | Delete
customActions = [],
[110] Fix | Delete
style = '',
[111] Fix | Delete
hashClass = 'elfinder-font-mono elfinder-info-hash',
[112] Fix | Delete
getHashAlgorisms = [],
[113] Fix | Delete
ndialog = fm.ui.notify,
[114] Fix | Delete
size, tmb, file, title, dcnt, rdcnt, path, hideItems, hashProg;
[115] Fix | Delete
[116] Fix | Delete
if (ndialog.is(':hidden') && ndialog.children('.elfinder-notify').length) {
[117] Fix | Delete
ndialog.elfinderdialog('open').height('auto');
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
if (!cnt) {
[121] Fix | Delete
return $.Deferred().reject();
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
if (dialog.length) {
[125] Fix | Delete
dialog.elfinderdialog('toTop');
[126] Fix | Delete
return $.Deferred().resolve();
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
hideItems = fm.storage('infohides') || fm.arrayFlip(o.hideItems, true);
[130] Fix | Delete
[131] Fix | Delete
if (cnt === 1) {
[132] Fix | Delete
file = files[0];
[133] Fix | Delete
[134] Fix | Delete
if (file.icon) {
[135] Fix | Delete
style = ' '+fm.getIconStyle(file);
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
view = view.replace('{dirclass}', file.csscls? fm.escape(file.csscls) : '').replace('{class}', fm.mime2class(file.mime)).replace('{style}', style);
[139] Fix | Delete
title = tpl.itemTitle.replace('{name}', fm.escape(file.i18 || file.name)).replace('{kind}', '<span title="'+fm.escape(file.mime)+'">'+fm.mime2kind(file)+'</span>');
[140] Fix | Delete
[141] Fix | Delete
tmb = fm.tmb(file);
[142] Fix | Delete
[143] Fix | Delete
if (!file.read) {
[144] Fix | Delete
size = msg.unknown;
[145] Fix | Delete
} else if (file.mime != 'directory' || file.alias) {
[146] Fix | Delete
size = fm.formatSize(file.size);
[147] Fix | Delete
} else {
[148] Fix | Delete
size = tpl.spinner.replace('{text}', msg.calc).replace('{name}', 'size');
[149] Fix | Delete
count.push(file.hash);
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
!hideItems.size && content.push(row.replace(l, msg.size).replace(v, size));
[153] Fix | Delete
!hideItems.aleasfor && file.alias && content.push(row.replace(l, msg.aliasfor).replace(v, file.alias));
[154] Fix | Delete
if (!hideItems.path) {
[155] Fix | Delete
if (path = fm.path(file.hash, true)) {
[156] Fix | Delete
content.push(row.replace(l, msg.path).replace(v, applyZWSP(fm.escape(path))).replace('{class}', 'elfinder-info-path'));
[157] Fix | Delete
} else {
[158] Fix | Delete
content.push(row.replace(l, msg.path).replace(v, tpl.spinner.replace('{text}', msg.calc).replace('{name}', 'path')).replace('{class}', 'elfinder-info-path'));
[159] Fix | Delete
reqs.push(fm.path(file.hash, true, {notify: null})
[160] Fix | Delete
.fail(function() {
[161] Fix | Delete
replSpinner(msg.unknown, 'path');
[162] Fix | Delete
})
[163] Fix | Delete
.done(function(path) {
[164] Fix | Delete
replSpinner(applyZWSP(path), 'path');
[165] Fix | Delete
}));
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
if (!hideItems.link && file.read) {
[169] Fix | Delete
var href,
[170] Fix | Delete
name_esc = fm.escape(file.name);
[171] Fix | Delete
if (file.url == '1') {
[172] Fix | Delete
content.push(row.replace(l, msg.link).replace(v, '<button class="'+btnclass+' '+spclass+'-url">'+msg.getlink+'</button>'));
[173] Fix | Delete
} else {
[174] Fix | Delete
if (file.url) {
[175] Fix | Delete
href = file.url;
[176] Fix | Delete
} else if (file.mime === 'directory') {
[177] Fix | Delete
if (o.nullUrlDirLinkSelf && file.url === null) {
[178] Fix | Delete
var loc = window.location;
[179] Fix | Delete
href = loc.pathname + loc.search + '#elf_' + file.hash;
[180] Fix | Delete
} else if (file.url !== '' && fm.option('url', (!fm.isRoot(file) && file.phash) || file.hash)) {
[181] Fix | Delete
href = fm.url(file.hash);
[182] Fix | Delete
}
[183] Fix | Delete
} else {
[184] Fix | Delete
href = fm.url(file.hash);
[185] Fix | Delete
}
[186] Fix | Delete
href && content.push(row.replace(l, msg.link).replace(v, '<a href="'+href+'" target="_blank">'+name_esc+'</a>'));
[187] Fix | Delete
}
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
if (!hideItems.dim) {
[191] Fix | Delete
if (file.dim) { // old api
[192] Fix | Delete
content.push(row.replace(l, msg.dim).replace(v, file.dim));
[193] Fix | Delete
} else if (file.mime.indexOf('image') !== -1) {
[194] Fix | Delete
if (file.width && file.height) {
[195] Fix | Delete
content.push(row.replace(l, msg.dim).replace(v, file.width+'x'+file.height));
[196] Fix | Delete
} else if (file.size && file.size !== '0') {
[197] Fix | Delete
content.push(row.replace(l, msg.dim).replace(v, tpl.spinner.replace('{text}', msg.calc).replace('{name}', 'dim')));
[198] Fix | Delete
reqs.push(fm.request({
[199] Fix | Delete
data : {cmd : 'dim', target : file.hash},
[200] Fix | Delete
preventDefault : true
[201] Fix | Delete
})
[202] Fix | Delete
.fail(function() {
[203] Fix | Delete
replSpinner(msg.unknown, 'dim');
[204] Fix | Delete
})
[205] Fix | Delete
.done(function(data) {
[206] Fix | Delete
replSpinner(data.dim || msg.unknown, 'dim');
[207] Fix | Delete
if (data.dim) {
[208] Fix | Delete
var dim = data.dim.split('x');
[209] Fix | Delete
var rfile = fm.file(file.hash);
[210] Fix | Delete
rfile.width = dim[0];
[211] Fix | Delete
rfile.height = dim[1];
[212] Fix | Delete
}
[213] Fix | Delete
}));
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
!hideItems.modify && content.push(row.replace(l, msg.modify).replace(v, fm.formatDate(file)));
[219] Fix | Delete
!hideItems.perms && content.push(row.replace(l, msg.perms).replace(v, fm.formatPermissions(file)));
[220] Fix | Delete
!hideItems.locked && content.push(row.replace(l, msg.locked).replace(v, file.locked ? msg.yes : msg.no));
[221] Fix | Delete
!hideItems.owner && file.owner && content.push(row.replace(l, msg.owner).replace(v, file.owner));
[222] Fix | Delete
!hideItems.group && file.group && content.push(row.replace(l, msg.group).replace(v, file.group));
[223] Fix | Delete
!hideItems.perm && file.perm && content.push(row.replace(l, msg.perm).replace(v, fm.formatFileMode(file.perm)));
[224] Fix | Delete
// Add custom info fields
[225] Fix | Delete
if (o.custom) {
[226] Fix | Delete
$.each(o.custom, function(name, details) {
[227] Fix | Delete
if (
[228] Fix | Delete
!hideItems[details.label]
[229] Fix | Delete
&&
[230] Fix | Delete
(!details.mimes || $.grep(details.mimes, function(m){return (file.mime === m || file.mime.indexOf(m+'/') === 0)? true : false;}).length)
[231] Fix | Delete
&&
[232] Fix | Delete
(!details.hashRegex || file.hash.match(details.hashRegex))
[233] Fix | Delete
) {
[234] Fix | Delete
// Add to the content
[235] Fix | Delete
content.push(row.replace(l, fm.i18n(details.label)).replace(v , details.tpl.replace('{id}', id)));
[236] Fix | Delete
// Register the action
[237] Fix | Delete
if (details.action && (typeof details.action == 'function')) {
[238] Fix | Delete
customActions.push(details.action);
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
});
[242] Fix | Delete
}
[243] Fix | Delete
} else {
[244] Fix | Delete
view = view.replace('{class}', 'elfinder-cwd-icon-group');
[245] Fix | Delete
title = tpl.groupTitle.replace('{items}', msg.items).replace('{num}', cnt);
[246] Fix | Delete
dcnt = $.grep(files, function(f) { return f.mime == 'directory' ? true : false ; }).length;
[247] Fix | Delete
if (!dcnt) {
[248] Fix | Delete
size = 0;
[249] Fix | Delete
$.each(files, function(h, f) {
[250] Fix | Delete
var s = parseInt(f.size);
[251] Fix | Delete
[252] Fix | Delete
if (s >= 0 && size >= 0) {
[253] Fix | Delete
size += s;
[254] Fix | Delete
} else {
[255] Fix | Delete
size = 'unknown';
[256] Fix | Delete
}
[257] Fix | Delete
});
[258] Fix | Delete
content.push(row.replace(l, msg.kind).replace(v, msg.files));
[259] Fix | Delete
!hideItems.size && content.push(row.replace(l, msg.size).replace(v, fm.formatSize(size)));
[260] Fix | Delete
} else {
[261] Fix | Delete
rdcnt = $.grep(files, function(f) { return f.mime === 'directory' && (! f.phash || f.isroot)? true : false ; }).length;
[262] Fix | Delete
dcnt -= rdcnt;
[263] Fix | Delete
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(', ')));
[264] Fix | Delete
!hideItems.size && content.push(row.replace(l, msg.size).replace(v, tpl.spinner.replace('{text}', msg.calc).replace('{name}', 'size')));
[265] Fix | Delete
count = $.map(files, function(f) { return f.hash; });
[266] Fix | Delete
[267] Fix | Delete
}
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
view = view.replace('{title}', title).replace('{content}', content.join('').replace(/{class}/g, ''));
[271] Fix | Delete
[272] Fix | Delete
dialog = self.fmDialog(view, opts);
[273] Fix | Delete
dialog.attr('id', id).one('mousedown', '.elfinder-info-path', function() {
[274] Fix | Delete
$(this).html(applyZWSP($(this).html(), true));
[275] Fix | Delete
});
[276] Fix | Delete
[277] Fix | Delete
if (getHashAlgorisms.length) {
[278] Fix | Delete
hashProg.appendTo(dialog.find('.'+spclass+'-'+getHashAlgorisms[0]).parent());
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
if (fm.UA.Mobile && $.fn.tooltip) {
[282] Fix | Delete
dialog.children('.ui-dialog-content .elfinder-info-title').tooltip({
[283] Fix | Delete
classes: {
[284] Fix | Delete
'ui-tooltip': 'elfinder-ui-tooltip ui-widget-shadow'
[285] Fix | Delete
},
[286] Fix | Delete
tooltipClass: 'elfinder-ui-tooltip ui-widget-shadow',
[287] Fix | Delete
track: true
[288] Fix | Delete
});
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
if (file && file.url == '1') {
[292] Fix | Delete
dialog.on('click', '.'+spclass+'-url', function(){
[293] Fix | Delete
$(this).parent().html(tpl.spinner.replace('{text}', fm.i18n('ntfurl')).replace('{name}', 'url'));
[294] Fix | Delete
fm.request({
[295] Fix | Delete
data : {cmd : 'url', target : file.hash},
[296] Fix | Delete
preventDefault : true
[297] Fix | Delete
})
[298] Fix | Delete
.fail(function() {
[299] Fix | Delete
replSpinner(name_esc, 'url');
[300] Fix | Delete
})
[301] Fix | Delete
.done(function(data) {
[302] Fix | Delete
if (data.url) {
[303] Fix | Delete
replSpinner('<a href="'+data.url+'" target="_blank">'+name_esc+'</a>' || name_esc, 'url');
[304] Fix | Delete
var rfile = fm.file(file.hash);
[305] Fix | Delete
rfile.url = data.url;
[306] Fix | Delete
} else {
[307] Fix | Delete
replSpinner(name_esc, 'url');
[308] Fix | Delete
}
[309] Fix | Delete
});
[310] Fix | Delete
});
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
// load thumbnail
[314] Fix | Delete
if (tmb) {
[315] Fix | Delete
$('<img/>')
[316] Fix | Delete
.on('load', function() { dialog.find('.elfinder-cwd-icon').addClass(tmb.className).css('background-image', "url('"+tmb.url+"')"); })
[317] Fix | Delete
.attr('src', tmb.url);
[318] Fix | Delete
}
[319] Fix | Delete
[320] Fix | Delete
// send request to count total size
[321] Fix | Delete
if (count.length) {
[322] Fix | Delete
reqDfrd = fm.getSize(count).done(function(data) {
[323] Fix | Delete
replSpinner(data.formated, 'size');
[324] Fix | Delete
}).fail(function() {
[325] Fix | Delete
replSpinner(msg.unknown, 'size');
[326] Fix | Delete
});
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
// call custom actions
[330] Fix | Delete
if (customActions.length) {
[331] Fix | Delete
$.each(customActions, function(i, action) {
[332] Fix | Delete
try {
[333] Fix | Delete
action(file, fm, dialog);
[334] Fix | Delete
} catch(e) {
[335] Fix | Delete
fm.debug('error', e);
[336] Fix | Delete
}
[337] Fix | Delete
});
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
return $.Deferred().resolve();
[341] Fix | Delete
};
[342] Fix | Delete
[343] Fix | Delete
}).prototype = { forceLoad : true }; // this is required command
[344] Fix | Delete
[345] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function