2016-06-10 92 views
0

TinyMCE 4.3.13是TinyMCE 4.1.3以來的新版本。在我們的應用程序中,我們將forced_root_block設置爲false。當圖片是頁面上的最後一個元素時,如果您嘗試刪除它,您會得到:「Uncaught TypeError:無法讀取屬性'null'的節點名稱」,除非它是頁面上的唯一元素。TinyMCE 4有沒有辦法在編輯時自動追加一個字符?

如果將它包裝在另一個元素中,則不會出現此錯誤,並且圖像會被刪除。如果圖像後面還有任何其他項目,即使是單個字符,也不會收到錯誤並刪除圖像。

因此,舉例來說,如果你打開源,並把這個在:

a <img src="http://ridgeaviation.ie/images/czaw-SportsCruiser-pic01.jpg"/> 
b 

,那麼你可以從UI刪除的圖像。

但與此:

a <img src="http://ridgeaviation.ie/images/czaw-SportsCruiser-pic01.jpg"/> 

你不能。

如果您在末尾放置「 」,您將無法刪除,因爲編輯器顯然會裁剪空間,但如果您在末尾放置「‌」,則它不會被裁剪,不可見,你可以刪除圖像。

這裏的HTML:

<!DOCTYPE html> 
<html> 
<head> 
    <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> 
    <script> 
tinymce.init({ 
    selector:'textarea', toolbar: "fontselect fontsizeselect | bold italic underline| bullist numlist outdent indent | alignleft aligncenter alignright alignjustify | forecolor backcolor | link anchor code", 
    menubar: "edit insert view format table tools", 
    plugins: [ 
    'advlist autolink lists link image charmap print preview hr anchor pagebreak', 
    'searchreplace wordcount visualblocks visualchars code fullscreen', 
    'insertdatetime media nonbreaking save table contextmenu directionality', 
    'emoticons template paste textcolor colorpicker textpattern imagetools' 
    ], 
    image_advtab: true, 
force_br_newlines: true, 
force_p_newlines: false, 
forced_root_block: false 
    }); 
</script> 
</head> 
<body> 
    <textarea>Easy (and free!) You should check out our premium features.</textarea> 
</body> 
</html> 

所以,問題是,有沒有一些方法來自動追加「‌」到正在編輯的文本,甚至有工具 - >源代碼編輯後? TinyMCE 3.x具有cleanup_callback,但在4.x中不可用。

回答

1

您可以使用TinyMCE change事件並在最後查找您的特殊字符,如果它沒有添加它?

例如:

tinymce.init({ 
    selector: 'textarea', 
    ... 
    setup: function (editor) { 
     editor.on('change', function() { 
      console.log('Content changed to: ' + editor.getContent()); 
      //Check the content here and add your character to the end if needed 
     }); 
    } 
}) 

下面是如何使用change事件小提琴... http://fiddle.tinymce.com/q0faab

+0

是的,謝謝!我使用了editor.on('NodeChange'),它效果很好。 – mutatron

相關問題