2010-06-28 35 views
7

我被要求在項目中使用TinyMCE編輯器。在下載頁面上,有一個主包,然後一個jQuery包什麼是TinyMCE jQuery包?

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

什麼是TinyMCE的的jQuery的建設?它只是TinyMCE具有與jQuery相同的特性嗎?它是標準的TinyMCE,但帶有一些附加組件,使用jQuery操縱TinyMCE更容易?還有別的嗎?一個快速的互聯網搜索告訴我「這是具有jQuery功能的小MCE!」,但我很好奇這意味着什麼。

+0

截至此日期,「jQuery版本」似乎是一種幻覺。它可能被刪除了?根據調查當前的NuGet包,查看下面的更新答案。 – 2015-07-22 10:08:22

+0

問:爲什麼你接受只顯示JS代碼版本而不是TinyMMCE jQuery示例的答案? 「@ woohoo」後面的答案對於所問的問題更爲準確。 – 2015-07-22 10:10:00

回答

3

jquery插件允許您使用jQuery語法將TinyMCE附加到textarea。下面是一個代碼示例,演示瞭如何將textarea控件轉換爲wysiwyg編輯器,同時打開多個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> 

這也是非常簡單的檢索或更新使用jQuery插件的所見即所得的HTML。

// 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

現在這兩個鏈接都被破壞了。 – murftown 2013-06-11 17:20:20

+0

如果有一個實際的代碼示例可以幫助人們瞭解它是如何工作的,那麼它會非常好...鏈接在時間上腐爛! – woohoo 2013-07-14 16:41:24

+1

謝謝,我已經更新了實際的代碼示例並刪除了損壞的鏈接 – 2013-08-29 22:42:20

3

這意味着這個軟件包不包含任何已經被jQuery覆蓋的javascript函數。即jQuery("selector")來找到dom元素。

+0

這可能意味着,但是NuGet包表明「jQuery版本」只是一個小型jQuery插件*,它位於完整TinyMCE之上!查看我在調查此事後添加的答案。 – 2015-07-22 10:07:25

2

鮑勃布萊克的答案是正確的。

此外,jquery包會減小TinyMCE下載的大小,修改TinyMCE代碼以儘可能使用JQuery函數(從包中刪除tinymce實現)。

+0

這不再(?)似乎是真的。 NuGet包表明「jQuery版本」是一個小小的jQuery插件,它位於完整的TinyMCE之上!查看我在調查此事後添加的答案。 – 2015-07-22 10:11:34

2

以下是使用tinymce jquery包(link)的示例的源代碼。 Tinymce現在在版本4,但這個例子是從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> 

希望這會有所幫助。