2017-03-21 11 views
2

TinyMCE 편집기에 키보드 단축키를 추가하고 싶습니다. 내가의 라인을 따라 뭔가해야 할 것을 알고TinyMCE v4에서 tinymce.Shortcuts를 구현하는 방법

tinymce.init({ 
    selector: 'textarea', 
    menubar: false, 
    mode : "exact", 
    plugins: [ 
    'advlist autolink lists link image charmap print preview anchor', 
    'searchreplace visualblocks code fullscreen', 
    'insertdatetime media table contextmenu paste code', 
    'print' 
    ], 
    toolbar: 'print | styleselect | bullist numlist', 
}); 

: 여기

내 초기화 코드

editor.shortcuts.add('ctrl+a', function() {}); 

을하지만 내 초기화로 바로 가기 코드를 연결하는 방법을 이해하지 않습니다 암호.

TinyMCE 문서 here 그러나 나는 그것을 이해하는 데 어려움을 겪고있었습니다. 여기

답변

1

이것은 @ Thariama가 제공 한 답변의 확장입니다. 나를 위해 일한 코드이었다

tinymce.init({ 
    selector: 'textarea', 
    menubar: false, 
    mode : "exact", 
    setup: function(editor) { 
     editor.shortcuts.add('ctrl+a', desc, function() { //desc can be any string, it is just for you to describe your code. 
      // your code here 
     }); 
    }, 
    plugins: [ 
    'advlist autolink lists link image charmap print preview anchor', 
    'searchreplace visualblocks code fullscreen', 
    'insertdatetime media table contextmenu paste code', 
    'print' 
    ], 
    toolbar: 'print | styleselect | bullist numlist', 
}); 

가 또는 당신은 또한 당신이 키 TinyMCE에 의해 예약 된 명령 오버라이드 (override) 할 수 있습니다 다음, 사용할 수 있습니다 : 앞의 두 대답 보완

tinymce.init({ 
    selector: 'textarea', 
    menubar: false, 
    mode : "exact", 
    setup: function(e) { 
     e.on("keyup", function(e) { 
     if (e.keyCode === 27) { // keyCode 27 is for the ESC key, just an example, use any key code you like 
      // your code here 
     } 
     }); 
    }, 
    plugins: [ 
    'advlist autolink lists link image charmap print preview anchor', 
    'searchreplace visualblocks code fullscreen', 
    'insertdatetime media table contextmenu paste code', 
    'print', 
    ], 
    toolbar: 'print | styleselect | bullist numlist', 
}); 
1

그것을 수행하는 방법입니다 :

tinymce.init({ 
    selector: 'textarea', // change this value according to your HTML 

    // add your shortcuts here 
    setup: function(editor) { 
    editor.shortcuts.add('ctrl+a', function() {}); 
    } 
}); 

setup 초기화 매개 변수를 사용합니다!

+0

이 답변에 대한 질문입니다. 이 기능이 작동하려면 함수를 설명하는 문자열을 추가해야합니다. 작동하지 않는다 : 'editor.shortcuts.add ('ctrl + a', myCommandDescription, function() {})); 'TinyMCE 보관 문서 [여기] (http://archive.tinymce.com/wiki.php/API3:method.tinymce.Editor.addShortcut)에서 발견 된 비추천 코드를 사용해 본 결론을 얻었다. 해당 설명 문자열을 추가하지 않고도 작업 할 핵심 명령을 얻을 수 있습니까? –

+0

아니요, add 함수가 주석 중심 함수이기 때문에 빈 문자열을 사용할 수 있습니다. – Thariama

+0

도와 주셔서 감사합니다. @Thariama. 날 올바른 방향으로 가야 해. 정말 감사. –

0

을, 전체 예제는 다음과 같습니다.

tinymce.init({ 
//here you can have selector, menubar... 
setup: function (editor) { 
     setLocale(editor); 
      // For the keycode (eg. 13 = enter) use: cf http://keycode.info 
      editor.shortcuts.add('ctrl+13', 'indent', function(){  
       tinymce.activeEditor.execCommand('indent'); 
      }); 

      editor.shortcuts.add('ctrl+f', 'subscript ', function(){  
       tinymce.activeEditor.execCommand('subscript'); 
      }); 
     }, 
     });