* elFinder resources registry.
* @author Dmitry (dio) Levashov
elFinder.prototype.resources = {
hover : 'ui-state-hover',
active : 'ui-state-active',
disabled : 'ui-state-disabled',
draggable : 'ui-draggable',
droppable : 'ui-droppable',
adroppable : 'elfinder-droppable-active',
cwdfile : 'elfinder-cwd-file',
treeroot : 'elfinder-navbar-root',
navdir : 'elfinder-navbar-dir',
navdirwrap : 'elfinder-navbar-dir-wrapper',
navarrow : 'elfinder-navbar-arrow',
navsubtree : 'elfinder-navbar-subtree',
navcollapse : 'elfinder-navbar-collapsed',
navexpand : 'elfinder-navbar-expanded',
treedir : 'elfinder-tree-dir',
placedir : 'elfinder-place-dir',
searchbtn : 'elfinder-button-search',
editing : 'elfinder-to-editing',
preventback : 'elfinder-prevent-back',
tabstab : 'ui-state-default ui-tabs-tab ui-corner-top ui-tab',
tabsactive : 'ui-tabs-active ui-state-active'
perms : '<span class="elfinder-perms"></span>',
lock : '<span class="elfinder-lock"></span>',
symlink : '<span class="elfinder-symlink"></span>',
navicon : '<span class="elfinder-nav-icon"></span>',
navspinner : '<span class="elfinder-spinner elfinder-navbar-spinner"></span>',
navdir : '<div class="elfinder-navbar-wrapper{root}"><span id="{id}" class="ui-corner-all elfinder-navbar-dir {cssclass}"{title}><span class="elfinder-navbar-arrow"></span><span class="elfinder-navbar-icon" {style}></span>{symlink}{permissions}{name}</span><div class="elfinder-navbar-subtree" style="display:none"></div></div>',
placedir : '<div class="elfinder-navbar-wrapper"><span id="{id}" class="ui-corner-all elfinder-navbar-dir {cssclass}"{title}><span class="elfinder-navbar-arrow"></span><span class="elfinder-navbar-icon" {style}></span>{symlink}{permissions}{name}</span><div class="elfinder-navbar-subtree" style="display:none"></div></div>'
// mimes.text will be overwritten with connector config if `textMimes` is included in initial response
// @see php/elFInder.class.php `public static $textMimes`
'application/docbook+xml',
'application/javascript',
'application/vnd.hp-hpgl',
'application/x-web-config',
req = this.requestCmd || cmd,
wz = fm.getUI('workzone'),
org = (this.origin && this.origin === 'navbar')? 'tree' : 'cwd',
find = tree? 'navHash2Elm' : 'cwdHash2Elm',
tarea= (! tree && fm.storage('view') != 'list'),
move = this.move || false,
empty= wz.hasClass('elfinder-cwd-wrapper-empty'),
requestAnimationFrame(function() {
input && input.trigger('blur');
if (!overlay.is(':hidden')) {
overlay.elfinderoverlay('hide').off('click close', cancel);
pnode.removeClass('ui-front')
.off('unselect.'+fm.namespace, unselect);
nnode && nnode.css('max-height', '');
.parent('td').css('overflow', '');
dstCls && dst.attr('class', dstCls);
empty && wz.addClass('elfinder-cwd-wrapper-empty');
move && fm.trigger('unlockfiles', {files: sel});
fm.trigger('selectfiles', { files: sel });
error && fm.error(error);
fm.enable().unbind('open', openCallback).trigger('resMixinMake');
id = 'tmp_'+parseInt(Math.random()*100000),
phash = this.data && this.data.target? this.data.target : (tree? fm.file(sel[0]).hash : fm.cwd().hash),
name : fm.uniqueName(this.prefix, phash),
date : 'Today '+date.getHours()+':'+date.getMinutes(),
dum = fm.getUI(org).trigger('create.'+fm.namespace, file),
overlay = fm.getUI('overlay'),
if (node && node.length) {
fm.unselectfiles({files : [id]}).unbind('resize', resize);
requestAnimationFrame(function() {
node.closest('.elfinder-navbar-wrapper').remove();
if (!overlay.is(':hidden')) {
pnode.css('z-index', '');
input = jQuery(tarea? '<textarea></textarea>' : '<input type="text"/>')
.on('keyup text', function(){
this.style.height = '1px';
this.style.height = this.scrollHeight + 'px';
this.style.width = colwidth + 'px';
if (this.scrollWidth > colwidth) {
this.style.width = this.scrollWidth + 10 + 'px';
.on('keydown', function(e) {
e.stopImmediatePropagation();
if (e.keyCode == jQuery.ui.keyCode.ESCAPE) {
} else if (e.keyCode == jQuery.ui.keyCode.ENTER) {
.on('mousedown click dblclick', function(e) {
if (e.type === 'dblclick') {
var name = jQuery.trim(input.val()),
if (!overlay.is(':hidden')) {
pnode.css('z-index', '');
if (!inError && parent.length) {
if (fm.options.validName && fm.options.validName.test) {
valid = fm.options.validName.test(name);
if (!name || name === '.' || name === '..' || !valid) {
fm.error(file.mime === 'directory'? 'errInvDirname' : 'errInvName', {modal: true, close: function(){setTimeout(select, 120);}});
if (fm.fileByName(name, phash)) {
fm.error(['errExists', name], {modal: true, close: function(){setTimeout(select, 120);}});
cut = (sel && move)? fm.exec('cut', sel) : null;
input.hide().before(jQuery('<span>').text(name));
fm.lockfiles({files : [id]});
data : Object.assign({cmd : req, name : name, target : phash}, data || {}),
notify : {type : req, cnt : 1},
navigate : {toast : toast},
fm.unlockfiles({files : [id]});
input.show().prev().remove();
if (Array.isArray(error) && jQuery.inArray('errUploadMime', error) !== -1) {
dfrd.notify('errUploadMime').reject();
if (data && data.added && data.added[0]) {
var item = data.added[0],
newItem = fm[find](dirhash),
'directory' : { cmd: 'open', msg: 'cmdopendir' },
'text' : { cmd: 'edit', msg: 'cmdedit' },
'default' : { cmd: 'open', msg: 'cmdopen' }
fm.one(req+'done', function() {
fm.exec('paste', dirhash);
if (fm.mimeIsText(item.mime) && !fm.mimesCanMakeEmpty[item.mime] && fm.mimeTypes[item.mime]) {
fm.trigger('canMakeEmptyFile', {mimes: [item.mime], unshift: true});
tmpMimes[item.mime] = fm.mimeTypes[item.mime];
fm.storage('mkfileTextMimes', Object.assign(tmpMimes, fm.storage('mkfileTextMimes') || {}));
Object.assign(nextAct, nextAction || acts[item.mime] || acts[item.mime.split('/')[0]] || acts[(fm.mimesCanMakeEmpty[item.mime] || jQuery.inArray(item.mime, fm.resources.mimes.text) !== -1) ? 'text' : 'none'] || acts['default']);
Object.assign(toast, nextAct.cmd ? {
incwd : {msg: fm.i18n(['complete', fm.i18n('cmd'+cmd)]), action: nextAct},
inbuffer : {msg: fm.i18n(['complete', fm.i18n('cmd'+cmd)]), action: nextAct}
inbuffer : {msg: fm.i18n(['complete', fm.i18n('cmd'+cmd)])}
.on('dragenter dragleave dragover drop', function(e) {
// stop bubbling to prevent upload with native drop event
var name = fm.splitFileExtention(input.val())[0];
if (!inError && fm.UA.Mobile && !fm.UA.iOS) { // since iOS has a bug? (z-index not effect) so disable it
overlay.on('click close', cancel).elfinderoverlay('show');
pnode.css('z-index', overlay.css('z-index') + 1);
! fm.enabled() && fm.enable();
input.trigger('focus').trigger('select');
input[0].setSelectionRange && input[0].setSelectionRange(0, name.length);
node.trigger('scrolltoview', {blink : false});
openCallback = function() {
dfrd && (dfrd.state() === 'pending') && dfrd.reject();
dst, dstCls, collapsed, expanded, arrow, subtree;
if (!fm.isCommandEnabled(req, phash) || !node.length) {
if (jQuery.isPlainObject(self.nextAction)){
nextAction = Object.assign({}, self.nextAction);
collapsed = fm.res('class', 'navcollapse');
expanded = fm.res('class', 'navexpand');
arrow = fm.res('class', 'navarrow');
subtree = fm.res('class', 'navsubtree');
node.closest('.'+subtree).show();
if (! dst.hasClass(collapsed)) {
dstCls = dst.attr('class');
dst.addClass(collapsed+' '+expanded+' elfinder-subtree-loaded');
if (dst.is('.'+collapsed+':not(.'+expanded+')')) {
dst.children('.'+arrow).trigger('click').data('dfrd').done(function() {
if (input.val() === file.name) {
input.val(fm.uniqueName(self.prefix, phash)).trigger('select').trigger('focus');
nnode = node.contents().filter(function(){ return this.nodeType==3 && jQuery(this).parent().attr('id') === fm.navHash2Id(file.hash); });
nnode.replaceWith(input.val(file.name));
empty && wz.removeClass('elfinder-cwd-wrapper-empty');
nnode = node.find('.elfinder-cwd-filename');
nnode.css('max-height', 'none');
colwidth = pnode.width();
pnode.width(colwidth - 15)
.parent('td').css('overflow', 'visible');
nnode.empty().append(input.val(file.name));
pnode.addClass('ui-front')
.css('position', 'relative')
.on('unselect.'+fm.namespace, unselect);
fm.bind('resize', resize).one('open', openCallback);
blink: function(elm, mode) {
slowonce : function(){elm.hide().delay(250).fadeIn(750).delay(500).fadeOut(3500);},
lookme : function(){elm.show().fadeOut(500).fadeIn(750);}
mode = mode || 'slowonce';
func = acts[mode] || acts['lookme'];