1

我向 elFinder 添加了一个新的工具栏按钮和一个新的上下文菜单项。

效果很好,但只有在选择了一个普通文件时才应启用此项目。So should be dimmed when no file selected and should be dimmed when multiple files are selected or if is selected an directory.

我学到了比elFinder.prototype.commands.mycmd我应该将this.getstate返回值设置为:

  • 0如果应启用工具栏/上下文菜单项,并且
  • -1如果它应该被禁用

所以,现在有了这个:

埃尔

Finder.prototype.commands.mycmd= function() {

    var self  = this,
        fm    = self.fm;

    self.disableOnSearch = true;

    self.title = 'mycmd';

    self.getstate = function() {
            // need help here to add the "directory is selected check"
        return fm.selected().length == 1 ? 0 : -1;
    }

    self.exec = function() {
        alert("hello");
    }
}

不幸的是,我只知道 Perl,所以我很难通过所有 elFinder 的 javascript 代码来弄清楚如何掌握条件。

认识elFinder足够深入的人来帮助我解决这种情况吗?

4

1 回答 1

2

只需在 elFinder 的download.js.

这有效 - 至少现在.. ;)

elFinder.prototype.commands.mycmd= function() {

    var self  = this,
        fm    = self.fm;

    self.disableOnSearch = true;
    filter = function(hashes) {
        return $.map(self.files(hashes), function(f) { return f.mime == 'directory' ? null : f });
    };

    self.title = 'mycmd';

    self.getstate = function() {
        var sel = self.fm.selected(),
        cnt = sel.length;
        return  !self._disabled && cnt == 1 && cnt == filter(sel).length ? 0 : -1;
    }

    self.exec = function() {
        alert("hello");
    }
}
于 2013-11-27T19:59:10.963 回答