').append(icon(file)).appendTo(jQuery(document.body));
dt.setDragImage(helper.get(0), 50, 47);
}
if (!fm.UA.IE) {
dt.setData('elfinderfrom', window.location.href + file.phash);
dt.setData('elfinderfrom:' + dt.getData('elfinderfrom'), '');
}
}
})
.on('dragend', function(e) {
helper && helper.remove();
})
};
};
self.extra = null;
if (e.data) {
targets = e.data.targets || [];
if (targets.length === 1 && (file = fm.file(targets[0])) && file.mime !== 'directory') {
if (file.url != '1') {
self.extra = getExtra(file);
} else {
// Get URL ondemand
var node;
self.extra = {
icon: 'link',
node: jQuery('
')
.attr({href: '#', title: fm.i18n('getLink'), draggable: 'false'})
.text(file.name)
.on('click touchstart', function(e){
if (e.type === 'touchstart' && e.originalEvent.touches.length > 1) {
return;
}
var parent = node.parent();
e.stopPropagation();
e.preventDefault();
parent.removeClass('ui-state-disabled').addClass('elfinder-button-icon-spinner');
fm.request({
data : {cmd : 'url', target : file.hash},
preventDefault : true
})
.always(function(data) {
parent.removeClass('elfinder-button-icon-spinner');
if (data.url) {
var rfile = fm.file(file.hash);
rfile.url = data.url;
node.replaceWith(getExtra(file).node);
} else {
parent.addClass('ui-state-disabled');
}
});
})
};
node = self.extra.node;
node.ready(function(){
requestAnimationFrame(function(){
node.parent().addClass('ui-state-disabled').css('pointer-events', 'auto');
});
});
}
}
}
}).one('open', function() {
if (fm.api >= 2.1012) {
czipdl = fm.getCommand('zipdl');
}
dlntf = fm.cookieEnabled && fm.api > 2.1038 && !fm.isCORS;
});
this.exec = function(select) {
var hashes = this.hashes(select),
fm = this.fm,
base = fm.options.url,
files = filter(hashes, true),
dfrd = jQuery.Deferred(),
iframes = '',
cdata = '',
targets = {},
i, url,
linkdl = false,
getTask = function(hashes) {
return function() {
var dfd = jQuery.Deferred(),
root = fm.file(fm.root(hashes[0])),
single = (hashes.length === 1),
volName = root? (root.i18 || root.name) : null,
dir, dlName, phash;
if (single) {
if (dir = fm.file(hashes[0])) {
dlName = (dir.i18 || dir.name);
}
} else {
jQuery.each(hashes, function() {
var d = fm.file(this);
if (d && (!phash || phash === d.phash)) {
phash = d.phash;
} else {
phash = null;
return false;
}
});
if (phash && (dir = fm.file(phash))) {
dlName = (dir.i18 || dir.name) + '-' + hashes.length;
}
}
if (dlName) {
volName = dlName;
}
volName && (volName = ' (' + volName + ')');
fm.request({
data : {cmd : 'zipdl', targets : hashes},
notify : {type : 'zipdl', cnt : 1, hideCnt : true, msg : fm.i18n('ntfzipdl') + volName},
cancel : true,
eachCancel : true,
preventDefault : true
}).done(function(e) {
var zipdl, dialog, btn = {}, dllink, form, iframe, m,
uniq = 'dlw' + (+new Date()),
zipdlFn = function(url) {
dllink = jQuery('
')
.attr('href', url)
.attr('download', fm.escape(dlName))
.on('click', function() {
dfd.resolve();
dialog && dialog.elfinderdialog('destroy');
});
if (linkdl) {
dllink.attr('target', '_blank')
.append('
'+fm.escape(dlName));
btn[fm.i18n('btnCancel')] = function() {
dialog.elfinderdialog('destroy');
};
dialog = self.fmDialog(dllink, {
title: fm.i18n('link'),
buttons: btn,
width: '200px',
destroyOnClose: true,
close: function() {
(dfd.state() !== 'resolved') && dfd.resolve();
}
});
} else {
click(dllink.hide().appendTo('body').get(0));
dllink.remove();
}
};
if (e.error) {
fm.error(e.error);
dfd.resolve();
} else if (e.zipdl) {
zipdl = e.zipdl;
if (dlName) {
m = fm.splitFileExtention(zipdl.name || '');
dlName += m[1]? ('.' + m[1]) : '.zip';
} else {
dlName = zipdl.name;
}
if (html5dl || linkdl) {
url = fm.options.url + (fm.options.url.indexOf('?') === -1 ? '?' : '&')
+ 'cmd=zipdl&download=1';
jQuery.each([hashes[0], zipdl.file, dlName, zipdl.mime], function(key, val) {
url += '&targets%5B%5D='+encodeURIComponent(val);
});
jQuery.each(fm.customData, function(key, val) {
url += '&'+encodeURIComponent(key)+'='+encodeURIComponent(val);
});
url += '&'+encodeURIComponent(dlName);
if (fm.hasParrotHeaders()) {
fm.getBinaryByUrl({url: url}, function(blob) {
if (blob instanceof Blob) {
url = (window.URL || window.webkitURL).createObjectURL(blob);
zipdlFn(url);
} else {
fm.error(['errUploadTransfer', fm.i18n('kindZIP')]);
}
});
} else {
zipdlFn(url);
}
} else {
form = jQuery('
')
.append('
')
.append('
');
jQuery.each([hashes[0], zipdl.file, dlName, zipdl.mime], function(key, val) {
form.append('
');
});
jQuery.each(fm.customData, function(key, val) {
form.append('
');
});
form.attr('target', uniq).appendTo('body');
iframe = jQuery('