【问题标题】:TinyMCE + jQuery + custom plugin = tinymce is undefined?TinyMCE + jQuery + 自定义插件 = tinymce 未定义?
【发布时间】:2010-06-16 21:29:41
【问题描述】:

当我尝试创建小插件以允许我在网站的所有文本区域上打开和关闭所见即所得时,就会出现问题。

//$('form.default textarea').each(function(){
// console.log( $('<a href="#">Enable  WYSIWYG editor</a>').insertAfter('form.default textarea').prev('textarea.wysiwyg').tinymce().hide() );
//});

完整的(有点简化的)代码如下所示:

$('textarea.wysiwyg').tinymce({
  skin : 'cirkuit',
  theme : 'advanced',
  plugins : 'pagebreak,style,layer,advlink,inlinepopups,contextmenu,paste,directionality,noneditable,nonbreaking,xhtmlxtras,template',
  // Theme options
  theme_advanced_buttons1 : 'formatselect,fontsizeselect,forecolor,|,bold,italic,strikethrough,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,|,link,unlink,|,image,|,code,paste,pastetext,pasteword,removeformat,|,backcolor,|,underline,justifyfull,sup,|,outdent,indent,|,hr,charmap,|,undo,redo',
  theme_advanced_buttons2 : '',
  theme_advanced_buttons3 : '',
  theme_advanced_toolbar_location : 'top',
  theme_advanced_toolbar_align : 'left',
  theme_advanced_statusbar_location: 'bottom',
  theme_advanced_resizing : true,
  theme_advanced_resize_horizontal : false,
  height : 500,
  theme_advanced_resizing_min_height : 500,
  document_base_url : 'http://static.<?=$settings['system_host']?>/'
 });

 $('textarea.wysiwyg').each(function() {
  $(this).tinymce().hide();
 });

什么是错误? FireBug 说 tinymce() in undefined;此消息出现在 each() 循环中。因此,tinymce() 实际上已被初始化。

我真的很迷茫,这可能是什么原因造成的。

【问题讨论】:

    标签: jquery tinymce wysiwyg


    【解决方案1】:

    这是您正在寻找的切换功能:http://tinymce.moxiecode.com/punbb/viewtopic.php?id=436

    var tinyMCEmode = true;
    function toogleEditorMode(sEditorID) {
        try {
            if(tinyMCEmode) {
                tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
                tinyMCEmode = false;
            } else {
                tinyMCE.addMCEControl(document.getElementById('pagecontent'), sEditorID);
                tinyMCEmode = true;
            }
        } catch(e) {
            //error handling
        }
    }
    

    使用方法:

    <a href="#" title="toogle TinyMCE" onclick="toogleEditorMode('pagecontent');">Toogle TinyMCE</a>
    

    我怀疑您的问题是在 tinyMCE 使用自己的 JavaScript 库时使用 jQuery 来执行此操作。它显然不喜欢隐藏。我会使用类似于给出的示例的东西,因为我们知道它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 2014-09-02
      • 1970-01-01
      相关资源
      最近更新 更多