[英]TinyMCE - selection.setContent with getContent (Warp Button)
I wanna have a button to wrap content with all tags. 我想要一个按钮来包装所有标签的内容。
My Code: 我的代码:
editor.addButton('MobileToggleArea', {
text: '<M>',
icon: false,
onclick: function (){
editor.selection.setContent('<div class="mobile-hide">' + editor.selection.getContent({format: 'raw'}) + '</div><div class="mobil-mehr">mehr</div>');
}
});
Example: 例:
<p>test</p>
<p>test</p>
Result: 结果:
<p> </p>
<div class="mobile-hide">
<p>test</p>
<p>test</p>
<div class="mobil-mehr">mehr</div>
<p> </p>
Problem: It is adding additional p
tags, why? 问题:它正在添加其他p
标签,为什么? how to prevent? 怎么预防?
Other Problem (but not so bad) is when selected only one p
Tag: 其他问题(但不是很严重)是仅选择一个p
标签时:
<div class="mobile-hide">test</div>
<div class="mobil-mehr">mehr</div>
The p
Tag has gone away. p
标签已消失。
Plugins: char word count autosave charmap code fullscreen image importcss link lists paste searchreplace tabfocus table template visualblocks anchor hr nonbreaking textcolor colorpicker 插件:字符数自动保存charmap代码全屏图像importcss链接列表粘贴搜索替换tabfocus表格模板visualblocks锚hr不间断textcolor colorpicker
Thanks for helping out. 感谢您的帮助。
I fixed both problems with Jquery: 我修复了Jquery的两个问题:
editor.addButton('MobileToggleArea', {
text: '<M>',
icon: false,
onclick: function (){
editor.selection.setContent('<div class="mobile-hide">' + editor.selection.getContent({format: 'raw'}) + '</div><div class="mobil-mehr">mehr</div>');
jQuery(editor.getBody()).find('.mobile-hide').prev().remove('p');
jQuery(editor.getBody()).find('.mobile-hide').next().next().remove('p');
jQuery(editor.getBody()).find('.mobile-hide').each(function(){
if(!jQuery(this).find('*').length){
jQuery(this).wrapInner('<p></p>');
}
});
}
});
Open for better Solutions =) 开放寻求更好的解决方案=)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.