60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
CKFinder.define(['jquery'], function(jQuery) {
|
|
'use strict';
|
|
|
|
function copyFileUrl(finder) {
|
|
var files = finder.request('files:getSelected');
|
|
if (files && files.length > 0) {
|
|
var file = files.first();
|
|
var urlPromise = finder.request('file:getUrl', {
|
|
file: file
|
|
});
|
|
urlPromise.then(function(url) {
|
|
var textarea = document.createElement('textarea');
|
|
textarea.value = url;
|
|
textarea.style.position = 'fixed';
|
|
textarea.style.opacity = '0';
|
|
document.body.appendChild(textarea);
|
|
textarea.select();
|
|
try {
|
|
document.execCommand('copy');
|
|
finder.request('dialog:info', {
|
|
msg: 'URL souboru byla zkopírována do schránky'
|
|
});
|
|
} catch (err) {
|
|
console.error('Chyba při kopírování:', err);
|
|
finder.request('dialog:error', {
|
|
msg: 'Nepodařilo se zkopírovat URL'
|
|
});
|
|
}
|
|
document.body.removeChild(textarea);
|
|
}).catch(function(error) {
|
|
console.error('Chyba při získávání URL:', error);
|
|
finder.request('dialog:error', {
|
|
msg: 'Nepodařilo se získat URL souboru'
|
|
});
|
|
});
|
|
} else {
|
|
console.warn('Není vybrán žádný soubor');
|
|
}
|
|
}
|
|
|
|
return {
|
|
init: function(finder) {
|
|
finder.on('contextMenu', function(evt) {
|
|
evt.data.groups.add({ name: 'clipboard' });
|
|
});
|
|
finder.on('contextMenu:file:clipboard', function(evt) {
|
|
evt.data.items.add({
|
|
name: 'copyFileUrl',
|
|
label: 'Kopírovat URL',
|
|
icon: 'ckf-file-copy',
|
|
isActive: true,
|
|
action: function() {
|
|
copyFileUrl(finder);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
};
|
|
});
|