2011-04-23 25 views
0

我想下面的代碼TinyMCE的按鍵時,我嘗試顯示內容的預覽

$('textarea.tinymce').keypress(function(){ 
     dealDescription = $('textarea.tinymce').tinymce().execCommand('mcePreview'); 
     $("#deal_preview div").text(dealDescription); 
}); 

,但我不使用jQuery TinyMCE的編輯想使用jQuery TinyMCE的和其他的jQuery UI組件無法正常工作,所以我直接使用tinymce組件。

現在我需要在每個按鍵的預覽框中顯示內容預覽。

回答

0

我嘗試用下面的代碼在TinyMCE的4.x中使用此工作的罰款

tinyMCE.init({ 

    mode : "exact", 
    elements : "text", 

    setup : function (theEditor) { 
     theEditor.onKeyPress.add(
      function (theEditor) { 
       previewContent(theEditor); 
      } 
     ); 
    }, 
}); 

function previewContent(editorObject){ 
    var content = editorObject.getContent(); 
    document.getElementById("previewContent").innerHTML = content; 
} 
2

tinymce.init({ 
    selector: "#tinymce-textarea", 
    setup : function(ed) { 
     ed.on("change", function(e){ 
      $('#tinymce-livepreview').html(tinymce.activeEditor.getContent()); 
     }); 
     ed.on("keyup", function(){ 
      $('#tinymce-livepreview').html(tinymce.activeEditor.getContent()); 
     }); 
    } 
}); 

說明:

上( 「變」)是檢測鼠標事件的變化,如果你點擊工具欄圖標或從菜單中選擇。它也能夠檢測到鍵盤事件,但只能在失去焦點(不是實時)之後。

上(「KEYUP」)可以通過獲取活動的編輯器檢測到實時鍵盤事件

0

能initialisasing後進行的變化,以及:

tinyMCE.activeEditor.on('keyup', function() { 
    // your nicely formatted code here 
}); 

還有一個editors陣列可以如果你需要它迭代。