gpt4 book ai didi

javascript - 将自定义上下文菜单项添加到 elFinder

转载 作者:可可西里 更新时间:2023-11-01 02:51:18 25 4
gpt4 key购买 nike

我正在使用 elfinder,我想通过向上下文菜单添加命令来添加新功能。我在项目的 github 问题跟踪器上找到了一个解决方案,但我无法让它工作。这是我的做法:

var elf;
jQuery().ready(function() {
elFinder.prototype._options.commands.push('editimage');
elFinder.prototype._options.contextmenu.files.push('editimage');
elFinder.prototype.i18.en.messages['cmdeditimage'] = 'Edit Image';
elFinder.prototype.i18.de.messages['cmdeditimage'] = 'Bild bearbeiten';
elFinder.prototype.commands.editimage = function() {
this.exec = function(hashes) {
console.log('hallo');
}
}
elf = jQuery('#elfinder').elfinder({
...
//elfinder initialization

上下文菜单项未显示,控制台中未发现任何错误消息。我还尝试将 editimage 放在 init 部分的 contextmenu->"files"下,以防它被初始化覆盖。

最佳答案

我找到了解决方案:这些示例并未表明您需要 elFinder.prototype 内的一个名为this.getstate 的函数.commands.yourcommand 功能。图标启用时返回 0,禁用时返回 -1。

因此,添加您自己的菜单项或上下文菜单项的完整代码如下所示:

var elf;
jQuery().ready(function() {

elFinder.prototype.i18.en.messages['cmdeditimage'] = 'Edit Image';
elFinder.prototype.i18.de.messages['cmdeditimage'] = 'Bild bearbeiten';
elFinder.prototype._options.commands.push('editimage');
elFinder.prototype.commands.editimage = function() {
this.exec = function(hashes) {
//do whatever
}
this.getstate = function() {
//return 0 to enable, -1 to disable icon access
return 0;
}
}
...
elf = jQuery('#elfinder').elfinder({
lang: 'de', // language (OPTIONAL)
url : '/ext/elfinder-2.0-rc1/php/connector.php', //connector URL
width:'100%',
uiOptions : {
// toolbar configuration
toolbar : [
...
['quicklook', 'editimage'],
/*['copy', 'cut', 'paste'],*/
...
]},
contextmenu : {
...
// current directory file menu
files : [
'getfile', '|','open', 'quicklook', 'editimage', ...
]
}
}).elfinder('instance');

});

希望这能帮助遇到同样问题的人。

关于javascript - 将自定义上下文菜单项添加到 elFinder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16604842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com