2017-02-10 64 views
3

首先,对不起我的英语不好,我来自德国。在Wordpress中保存Widget后,TinyMCE消失

我刚刚创建了我的第一个小部件。这是一个从列表中自动创建网格的小部件。

我可以添加一个新的列表项,并且每个表单字段都将被复制。 但经过3天的搜索没有结果的互联网我决定自己问... 所以这是我的第一个问题,当我添加一个新的项目,TinyMCE在新项目被禁用,我不能点击在按钮上或键入文本。 控制台日志中没有错误。

我的第二个问题是,当我保存小部件时,所有的TinyMCE编辑器都消失了,离开textareas,并带有html代码。

这里还有:没有错误......但是我看到了,保存后TinyMCE没有加载。没有iframe,只有textarea。

重新加载小部件页面之后,对于这两个问题,再次都是正常的。 所以我必须添加新的项目并保存页面,然后重新加载它来编辑和编辑内容,但这并不能解决问题。我想我不得不重新初始化TinyMCE,但我不知道如何。

我在将wordpress编辑器添加到我的小部件时遇到了问题,所以我整合了来自网站的jQuery TinyMCE。

这里是我的附加功能的代码片段:

$("body").on('click.sgw','.sgw-add',function() { 
    var sgw = $(this).parent().parent(); 
    var num = sgw.find('.simple-grid .list-item').length + 1; 

    sgw.find('.amount').val(num); 

    var item = sgw.find('.simple-grid .list-item:last-child').clone(); 
    var item_id = item.attr('id'); 
    item.attr('id',increment_last_num(item_id)); 

    $('.toggled-off',item).removeClass('toggled-off'); 
    $('.number',item).html(num); 
    $('.item-title',item).html(''); 
    $('.custom_media_image',item).attr('src',''); 
    $('textarea',item).val(''); 
    $('img.custom_media_image',item).each(function() { 
     var class_val = $(this).attr('class'); 
     $(this).attr('class',increment_last_num(class_val)); 
    }); 

    $('textarea',item).each(function() { 
     var id_iframe = $(this).attr('id'); 
     tinymce.EditorManager.execCommand('mceRemoveEditor',true, id_iframe); 
     tinymce.EditorManager.execCommand('mceAddEditor',true, id_iframe); 
    }); 


    $('label',item).each(function() { 
     var for_val = $(this).attr('for'); 
     $(this).attr('for',increment_last_num(for_val)); 
    }); 
    $('input',item).each(function() { 
     var id_val = $(this).attr('id'); 
     var name_val = $(this).attr('name'); 

     $(this).attr('id',increment_last_num(id_val)); 
     $(this).attr('name',increment_last_num(name_val)); 

     if($(':checked',this)){ 
      $(this).removeAttr('checked'); 
     } 
     if($(this).hasClass('custom_media_button') || $(this).hasClass('custom_media_url')){ 
      var class_val = $(this).attr('class'); 
      $(this).attr('class',increment_last_num(class_val)); 
     } 
     if($(this).hasClass('button-primary')){ 
      var number_val = $(this).attr('number'); 
      $(this).attr('number',increment_last_num(number_val)); 
     } 
     $(this).not('#custom_media_button').val(''); 
    }); 

    sgw.find('.simple-grid').append(item); 
    sgw.find('.order').val(sgw.find('.simple-grid').sortable('toArray')); 
}); 

我希望这是可以理解的,有人能帮助我。 你可以在这里下载邮编:https://www.dropbox.com/s/22b8q29v94n7mdj/simple-grid-widget.zip?dl=0

回答

0

你是否试图一次运行几个编辑器? Wordpress和TinyMCE有一个限制,一次只能编辑一个编辑器。我已经解决了这个问题,但这非常困难。

加载您可能需要删除旧的新的编辑器:

tinymce.remove(); 
0

是的,我跑在列表项的文字区域编辑。我应该在哪个地方放置代码?在我初始化之前?抱歉!