首先,對不起我的英語不好,我來自德國。在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