2016-05-12 29 views
1

私のアプリケーションには、CKEditorのインスタンスがあります。ユーザがテキストをエディタに入力している間、最初の後者は大文字でなければなりません。そのために私はこのように、jQueryのKeyDownイベントのイベントハンドラを書いた:CKeditorのKeyDownイベント

$(document).ready(function() { 
    CKEDITOR.instances.CKEditor1.on('contentDom', function() { 
     CKEDITOR.instances.CKEditor1.document.on('keydown', function (event) { 
      if (this.selectionStart == 0 && event.keyCode >= 65 && event.keyCode <= 90 && !(event.shiftKey) && !(event.ctrlKey) && !(event.metaKey) && !(event.altKey)) { 
       var $t = $(this); 
       event.preventDefault(); 
       var char = String.fromCharCode(event.keyCode); 
       $t.val(char + $t.val().slice(this.selectionEnd)); 
       this.setSelectionRange(1, 1); 
      } 
     }); 
    }); 
}); 

それはランタイムエラーすなわちを与え、

0x800a138f - JavaScript runtime error: Unable to get property 'on' of undefined or null reference

がどのように私はCKEditorバージョンのためのKeyDownイベントを作成することができます(私が書いた上記のコードを。 .aspxページ)

答えて

0

あなたは間違った方法でcontentDomイベントを登録していると思います。 あなたのコードは、それがインスタンス化終了する前にCKEditorバージョンのインスタンスにアクセスしようとしている

CKEDITOR.replace('editor1', { 
    on: { 
     instanceReady: function() { 
      alert(this.name); // 'editor1' 
      var editor = this; 
      editor.on('contentDom', function() { 
       var editable = editor.editable(); 
       editable.attachListener(editable, 'click', function() { 
       console.log('The editable was clicked.'); 
       }); 
      }); 
     } 
    } 
}); 

あなたがしたいCKEditorバージョンをインスタンス化し、contentDomイベントを登録するには。 詳細はhttp://docs.ckeditor.com/#!/api/CKEDITOR.confighttp://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-contentDom

にあります。
関連する問題