2012-04-09 35 views
5

Tôi đã khởi TinyMCE như vậy:Tháo gỡ hoàn toàn JQuery TinyMCE

$('#text').tinymce({ 
    // Location of TinyMCE script, optional, already loaded in page. 
    script_url : '../adminContent/js/tiny_mce/tiny_mce.js', 

    // General options 
    theme : "advanced", 
    plugins : "table,advimage,advlink,iespell,inlinepopups,preview,contextmenu,paste,visualchars", 

    // Theme options 
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image", 
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,removeformat,cleanup,code,|,preview,tablecontrols,|,hr,visualaid,|,charmap,iespell", 
    theme_advanced_buttons3 : "", 

    theme_advanced_toolbar_location : "top", 
    theme_advanced_toolbar_align : "left", 
    theme_advanced_statusbar_location : "bottom", 
    theme_advanced_resizing : true 
}); 

Đoạn mã trên hoạt động hoàn hảo. Vấn đề là khi tôi cố gắng loại bỏ tinyMCE.

đang remove của tôi là:

$('#text').tinymce().execCommand('mceRemoveControl', false, 'text'); 

Tôi cũng đã thử:

$('#text').remove(); 

$('#text').tinymce().remove(); 

Người đầu tiên dường như không làm gì cả. Cuối cùng hai cho tôi lỗi này:

Uncaught ReferenceError: t is not defined

Mặc dù TinyMCE được tải bởi các tài liệu HTML, Tôi tải kịch bản khác sử dụng:

$.getScript(viewPath + '/mod/adminContent/js/editContent.js', function(){ 
    initEditContent(popup); 
}); 

cửa sổ bật lên là một tham chiếu đến các popup trong đó TinyMCE được tải . Nó chỉ đơn giản là một div được tạo ra bằng cách sử dụng jquery. Nội dung của div được tải bằng cách sử dụng jquery ajax.

Các editContent.js trông như thế này:

var contentID; 
function initEditContent(popup){ 
    contentID = $('#contentID').val(); 

    tinyMCE.execCommand("mceAddControl", true, 'text'); 

    setTimeout(reposition, 50); 
    setTimeout(reposition, 150); 
    setTimeout(reposition, 250); 

    // Submit form 
    $('#editTextForm').ajaxForm(
    { 
     // Before submit 
     beforeSubmit: function(){ 
      //setPopupMessage(popup, '<div id="loading"><img src="../../img/loading.gif" />&nbsp;Please wait...</div>'); 
     }, 

     // Once submit completed 
     success: function(responseText){ 
      tinyMCE.execCommand("mceRemoveControl", true, 'text'); 
      //closePopup(popup); 

      // Update button with new data 
      $('#' + contentID).html(responseText); 
     } 
    }); 
} 
+0

'.tinymce() remove() 'nên làm các trick.. Bạn có thể đăng một trường hợp thử nghiệm trên [jsFiddle] (http://jsfiddle.net) nơi mà vấn đề của bạn được sao chép không? – mekwall

+0

Tôi đã chỉnh sửa câu hỏi ban đầu của mình để cung cấp thêm chi tiết cho bạn. Không thể sử dụng jsFiddle Tôi sợ vì có quá nhiều phần bên ngoài được yêu cầu. – JPardoe

+0

gọi là tinyMCE.remove(); và nó đưa ra một lỗi: "Uncaught TypeError: Không thể đọc thuộc tính 'id' của undefined" trên dòng 11264 của tiny_mce_src.js – JPardoe

Trả lời

0

thử

$('#text').tinymce().execCommand('mceRemoveControl', true, 'text'); 

nơi 'text' là ID của soạn thảo của bạn

<textarea id='text' ..... 
+0

Cố gắng đó - cùng một lỗi: của router ReferenceError: t không được định nghĩa Tôi đã bao gồm các phiên bản _src của TinyMCE và lỗi xảy ra trên đường dây 12.318: 'hide: function() { \t \t \t var tự = điều này, doc = t.getDoc(); của router ReferenceError: t không được định nghĩa \t \t \t // Sửa lỗi IE có một con trỏ nhấp nháy trái từ trình biên tập \t \t \t if (isIE && doc) \t \t \t \t doc.execCommand ('SelectAll') ; \t \t \t // Chúng ta phải tiết kiệm trước khi chúng ta giấu rất Safari không sụp đổ \t \t \t self.save(); \t \t \t DOM.hide (self.getContainer()); \t \t \t DOM.setStyle (self.id, 'display', self.orgDisplay); \t \t}, ' – JPardoe

1

Vấn đề giải quyết. Đối với những người quan tâm, tôi nạp TinyMCE trong tài liệu HTML, sau đó khi tôi cần thiết để khởi nó, tôi đã làm:

tinyMCE.init({ 
    mode : "textareas", 
    // General options 
    theme : "advanced", 
    plugins : "table,advimage,advlink,iespell,inlinepopups,preview,contextmenu,paste,visualchars", 

    // Theme options 
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image", 
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,removeformat,cleanup,code,|,preview,tablecontrols,|,hr,visualaid,|,charmap,iespell", 
    theme_advanced_buttons3 : "", 

    theme_advanced_toolbar_location : "top", 
    theme_advanced_toolbar_align : "left", 
    theme_advanced_statusbar_location : "bottom", 
    theme_advanced_resizing : true, 

    oninit: function(){ 
     alert('tinyMCE loaded'); 
    } 
}); 

Đoạn mã trên được gọi mỗi khi biên tập TinyMCE là bắt buộc. Sau đó tôi xóa nó khi tôi đóng cửa sổ bật lên như vậy:

tinyMCE.remove('text'); 
4

Điều này có vẻ như là một vấn đề với tinyMCE kể từ phiên bản 3.5b3. Nó hoạt động trong phiên bản 3.5b2.

Xem ví dụ my fiddle.

Bạn sẽ nhận thấy rằng nó tải và dỡ hàng tốt. Nhưng thay đổi phiên bản thành cạnh hoặc 3.5b3 và bạn sẽ gặp lỗi khi dỡ hàng.

Như đã nêu trên tinyMCE bug site:

Description of problem:

Javascript error on line 13518. t is not defined.

Steps to reproduce:

  1. Call tinyMCE.execCommand('mceRemoveControl', false, idOfTextarea);

Problem:

In 3.5b3 you renamed t to self, but didn't rename the used variable in the same line to get the doc.

Solution:

Change line 13518 (in function hide()) to: var self = this, doc = self.getDoc();

+0

Cảm ơn bạn. Điều này giải quyết các vấn đề đối với tôi. –

Các vấn đề liên quan