2010-06-28 10 views
7

Mi è stato chiesto di utilizzare l'editor TinyMCE in un progetto. Nella pagina di download, c'è un pacchetto principale, e poi un pacchetto di jQueryChe cos'è il pacchetto jQuery TinyMCE?

This package contains special jQuery build of TinyMCE and a jQuery integration plugin. 
tinymce_3_3_7_jquery.zip 

Qual è la build jQuery di TinyMCE? È solo TinyMCE con le stesse funzionalità create su jQuery? È standard TinyMCE ma con qualche tipo di add-on che facilita la manipolazione di TinyMCE con jQuery? Qualcos'altro? Una rapida ricerca su internet mi ha detto "è MCE minuscolo con funzionalità jQuery!", Ma sono curioso di sapere quali sono i mezzi.

+0

A partire da questa data, la "versione jQuery" sembra essere un'illusione. Forse è stato rimosso? Vedere la risposta aggiornata di seguito in base all'indagine sugli attuali pacchetti NuGet. –

+0

D: Perché hai accettato una risposta che mostra solo la versione del codice JS e non un esempio di jQuery TinyMMCE? La successiva risposta di '@ woohoo' è più accurata per la domanda posta. –

risposta

3

Il plug-in jquery consente di utilizzare la sintassi jquery per collegare TinyMCE a un'area di testo. Ecco un esempio di codice che illustra come convertire un controllo textarea in un editor wysiwyg, attivando contemporaneamente diverse opzioni TinyMCE.

<!-- Load jQuery --> 
<script type="text/javascript" src="http://www.google.com/jsapi"></script> 
<script type="text/javascript"> 
     google.load("jquery", "1.3"); 
</script> 

<!-- Load jQuery build --> 
<script type="text/javascript" src="<your installation path>/tiny_mce/tiny_mce.js"></script> 
<script type="text/javascript"> 
tinyMCE.init({ 
     // General options 
     mode : "textareas", 
     theme : "advanced", 
     plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", 

     // Theme options 
     theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", 
     theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", 
     theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", 
     theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak", 
     theme_advanced_toolbar_location : "top", 
     theme_advanced_toolbar_align : "left", 
     theme_advanced_statusbar_location : "bottom", 
     theme_advanced_resizing : true, 

     // Example content CSS (should be your site CSS) 
     content_css : "css/example.css", 

     // Drop lists for link/image/media/template dialogs 
     template_external_list_url : "js/template_list.js", 
     external_link_list_url : "js/link_list.js", 
     external_image_list_url : "js/image_list.js", 
     media_external_list_url : "js/media_list.js", 

     // Replace values for the template plugin 
     template_replace_values : { 
       username : "Some User", 
       staffid : "991234" 
     } 
}); 
</script> 

<form method="post" action="somepage"> 
     <textarea name="content" style="width:100%"> 
     </textarea> 
</form> 

E 'anche molto semplice da recuperare o aggiornare il codice html wysiwyg utilizzando il plugin jQuery.

// Will change the contents of an textarea with the ID "someeditor" 
$('#someeditor').html('Some contents...'); 

// Will change the contents all text areas with the class tinymce 
$('textarea.tinymce').html('Some contents...'); 

// Gets the contents from a specific editor 
alert($('#someeditor').html()); 
+1

Entrambi i collegamenti sono interrotti ora. – murftown

+0

sarebbe molto bello se ci fosse un vero esempio di codice che aiuti le persone a capire come funziona ... i collegamenti marciscono nel tempo! – woohoo

+1

Grazie, ho aggiornato con esempi di codice effettivi e rimosso i collegamenti interrotti –

3

Significa che questo pacchetto non contiene funzioni javascript che sono già coperte da jQuery. Ad esempio jQuery("selector") per trovare gli elementi dom.

+0

Può significare che, ma il pacchetto NuGet indica che la "versione jQuery" è * nient'altro che un piccolo plugin jQuery * che si trova in cima al completo TinyMCE! Vedi la risposta che ho aggiunto dopo aver esaminato la questione. –

2

La risposta da Bob nero è giusto.

Inoltre, il pacchetto jquery diminuisce le dimensioni dei download di TinyMCE, modificando il codice TinyMCE per utilizzare le funzioni di JQuery ove possibile (rimuovendo le implementazioni di stagno dal pacchetto).

+0

Questo non è più (?) Sembra essere vero. I pacchetti NuGet indicano che la "versione jQuery" è * nient'altro che un piccolo plugin jQuery * che si trova in cima al completo TinyMCE! Vedi la risposta che ho aggiunto dopo aver esaminato la questione. –

2

Ecco il codice sorgente da un esempio di utilizzo del pacchetto jQuery di tinymce (link). Tinymce è ora alla versione 4, ma questo esempio è dalla versione 3.x:

<!-- Load jQuery --> 
<script type="text/javascript" src="http://www.google.com/jsapi"></script> 
<script type="text/javascript"> 
     google.load("jquery", "1.3"); 
</script> 

<!-- Load jQuery build --> 
<script type="text/javascript" src="../../js/tinymce_3_x/jscripts/tiny_mce/jquery.tinymce.js"></script> 
<script type="text/javascript"> 
     $(function() { 
       $('textarea.tinymce').tinymce({ 
         // Location of TinyMCE script 
         script_url : '../../js/tinymce_3_x/jscripts/tiny_mce/tiny_mce.js', 

         // General options 
         theme : "advanced", 
         plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", 

         // Theme options 
         theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect", 
         theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", 
         theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", 
         theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak", 
         theme_advanced_toolbar_location : "top", 
         theme_advanced_toolbar_align : "left", 
         theme_advanced_statusbar_location : "bottom", 
         theme_advanced_resizing : true, 

         // Example content CSS (should be your site CSS) 
         content_css : "css/content.css", 

         // Drop lists for link/image/media/template dialogs 
         template_external_list_url : "lists/template_list.js", 
         external_link_list_url : "lists/link_list.js", 
         external_image_list_url : "lists/image_list.js", 
         media_external_list_url : "lists/media_list.js", 

         // Replace values for the template plugin 
         template_replace_values : { 
           username : "Some User", 
           staffid : "991234" 
         } 
       }); 
     }); 
</script> 

<form method="post" action="somepage"> 
     <textarea id="content" name="content" class="tinymce" style="width:100%"> 
     </textarea> 

     <!-- Some integration calls --> 
     <a href="javascript:;" onmousedown="$('#content').tinymce().show();">[Show]</a> 
     <a href="javascript:;" onmousedown="$('#content').tinymce().hide();">[Hide]</a> 
     <a href="javascript:;" onmousedown="$('#content').tinymce().execCommand('Bold');">[Bold]</a> 
     <a href="javascript:;" onmousedown="alert($('#content').html());">[Get contents]</a> 
     <a href="javascript:;" onmousedown="alert($('#content').tinymce().selection.getContent());">[Get selected HTML]</a> 
     <a href="javascript:;" onmousedown="alert($('#content').tinymce().selection.getContent({format : 'text'}));">[Get selected text]</a> 
     <a href="javascript:;" onmousedown="alert($('#content').tinymce().selection.getNode().nodeName);">[Get selected element]</a> 
     <a href="javascript:;" onmousedown="$('#content').tinymce().execCommand('mceInsertContent',false,'<b>Hello world!!</b>');">[Insert HTML]</a> 
     <a href="javascript:;" onmousedown="$('#content').tinymce().execCommand('mceReplaceContent',false,'<b>{$selection}</b>');">[Replace selection]</a> 
</form> 

Spero che questo aiuti.

Problemi correlati