9

elfinder を使用していますが、コンテキスト メニューにコマンドを追加して新しい機能を追加したいと考えています。プロジェクトの github issue tracker で解決策を見つけましたが、うまくいきません。これが私がすることです:

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

コンテキスト メニュー項目が表示されず、コンソールにエラー メッセージが表示されません。また、初期化によって上書きされた場合に備えて、init 部分の contextmenu->"files" の下に editimage を配置してみました。

4

2 に答える 2

24

私は解決策を見つけました:例は、関数内で関数を呼び出す必要があるという事実を示していません。アイコンが有効な場合は 0 を返し、無効な場合は -1 を返します。this.getstateelFinder.prototype.commands.yourcommand

したがって、独自のメニュー項目またはコンテキスト メニュー項目を追加するための完全なコードは次のようになります。

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');

});

これが同じ問題を抱えている人に役立つことを願っています。

于 2013-05-17T10:10:06.857 に答える