2012-04-09 21 views
5

ho inizializzato TinyMCE in questo modo:Rimuovere completamente 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 
}); 

Il codice di cui sopra funziona perfettamente. Il problema è quando provo a rimuovere tinyMCE.

Il mio codice di rimozione è:

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

Ho anche provato:

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

e

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

Il primo non sembra di fare nulla. Gli ultimi due mi danno questo errore:

Uncaught ReferenceError: t is not defined

Anche se TinyMCE è caricato dal documento HTML, sto caricando un altro script utilizza:

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

comparsa è un riferimento alla pop-up in cui TinyMCE è caricato . È semplicemente un div che viene creato usando jquery. I contenuti del div sono caricati usando jquery ajax.

L'editContent.js assomiglia a questo:

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() rimuovere()' dovrebbe fare il trucco.. Puoi pubblicare un caso di test su [jsFiddle] (http://jsfiddle.net) dove viene riprodotto il tuo problema? – mekwall

+0

Ho modificato la mia domanda iniziale per darti maggiori dettagli. Non posso usare jsFiddle ho paura perché ci sono troppe parti esterne richieste. – JPardoe

+0

chiamato tinyMCE.remove(); e ha dato un errore: "Uncaught TypeError: Impossibile leggere la proprietà 'id' di undefined" nella riga 11264 di tiny_mce_src.js – JPardoe

risposta

0

provare

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

dove 'testo' è l'ID del vostro editor

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

provato che - lo stesso errore: Uncaught ReferenceError: t non è definito ho incluso la versione _src di TinyMCE e si verifica l'errore on line 12318: 'nascondere: function() { \t \t \t var auto = questo, doc = t.getDoc(); Uncaught ReferenceError: t non è definito \t \t \t // Corretto il bug in cui IE ha un cursore lampeggiante a sinistra dalla l'editor \t \t \t se (ISIE && doc) \t \t \t \t doc.execCommand ('SelectAll') ; \t \t \t // Dobbiamo salvare prima che ci nascondiamo quindi Safari non va in crash \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

Problema risolto. Per coloro che sono interessati, ho caricato TinyMCE nel documento HTML, poi, quando avevo bisogno di inizializzare, l'ho fatto:

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'); 
    } 
}); 

Il codice di cui sopra è chiamato ogni volta che è richiesta l'editor TinyMCE. Ho quindi rimosso quando ho chiuso il popup in questo modo:

tinyMCE.remove('text'); 
4

Questo sembra un problema con tinyMCE dalla versione 3.5b3. Funziona nella versione 3.5b2.

Vedere l'esempio my fiddle.

Noterete che carica e scarica bene. Ma cambia la versione a bordo o 3.5b3 e riceverai l'errore durante lo scaricamento.

Come indicato sul 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

Grazie. Questo ha risolto il problema per me. –

Problemi correlati