TinyMCE在Wordpress中保存小工具后消失



首先,很抱歉我的英语不好,我来自德国。

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

我可以添加一个新的列表项,每个表单字段都将重复。但在网上搜索了三天没有结果后,我决定自己问。。。所以这是我的第一个问题,当我添加一个新项目时,新项目中的TinyMCE被禁用,我无法点击按钮或在其中键入文本。控制台日志中没有错误。

我的第二个问题是,当我保存小部件时,所有TinyMCE编辑器都会消失,并留下文本区域和html代码。

这里还有:没有错误。。。但我已经看到,TinyMCE在保存后没有加载。没有iframe,只有文本区域。

在重新加载小部件页面后,对于这两个问题,一切都恢复正常。所以我必须添加新项目并保存页面,然后重新加载它来编辑和编辑内容,但这并不能解决问题。

我想我必须重新初始化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'));
});

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

您是否试图同时运行多个编辑器?Wordpress和TinyMCE有一个限制,基本上一次只能有一个编辑器。我已经克服了这一点,但这非常困难。

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

tinymce.remove();

最新更新