2013-05-17 2 views
6

저는 elfinder를 사용하고 있습니다. 컨텍스트 메뉴에 명령을 추가하여 새로운 기능을 추가하고 싶습니다. 프로젝트의 github 발행 추적기에 대한 해결책을 찾았지만 제대로 작동하지 않습니다. 여기 내가하는 일 :elFinder에 사용자 정의 컨텍스트 메뉴 항목 추가하기

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 

컨텍스트 메뉴 항목이 나타나지 않고 콘솔에 오류 메시지가 표시되지 않습니다. 나는 또한 초기화에 의해 덮어 쓴 경우 초기화 부분에 contextmenu -> "files"아래에 editimage를 두어 보았습니다.

답변

20

솔루션을 찾았습니다.이 예제에서는 이라는 함수가 elFinder.prototype.commands.yourcommand 함수 내부에 this.getstate이라는 함수가 있어야한다는 사실을 보여주지 않습니다. 아이콘이 활성화되면 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'); 

}); 

희망은이 같은 문제를 가진 사람을 도움이됩니다.

+0

당신에게 너무 감사합니다 :

그래서,

elFinder.prototype.commands.editpres = function() { this.exec = function(hashes) { var file = this.files(hashes); var hash = file[0].hash; var fm = this.fm; var url = fm.url(hash); var scope = angular.element("body").scope(); scope.openEditorEdit(url); } // Getstate configured to only light up button if a file is selected. this.getstate = function() { var sel = this.files(sel), cnt = sel.length; return !this._disabled && cnt ? 0 : -1; } } 

을 표시하기 위해 아이콘을 얻으려면이 페이지를 발견 다른 사람 .... 들어, CSS 파일에 다음을 추가 ! – KryDos

+0

이것은 많은 시간을 실험적으로 저장합니다. elFinder 팀이 왜 이런 답을 쓰지 못하는지 궁금합니다. 고맙습니다. – jm666

+0

Yp 그 트릭을 않습니다. 대단히 감사합니다! – Gogol

4

답변 주셔서 감사합니다.

명확하지 않은 한 가지는 변수가 통과하는 방식이었습니다.

.elfinder-button-icon-editpres { background:url('../img/icons/editpres.png') no-repeat; } 
관련 문제