[英]Tinymce 3 - insert new content in new block after custom button click
I want to ask if it's possible to add new content "outside" of content that has beed added recently. 我想问问是否有可能在新添加的内容之外添加新内容。 So, i have custom button which adds some simple HTML. 所以,我有自定义按钮,它添加了一些简单的HTML。 And what i want to archive is to add the same html but outside of existing one, so in place marked green on my screenshot. 我想存档的是在现有HTML之外添加相同的html,因此在屏幕截图上标记为绿色的位置。 I'm looking for a way how to escape from this div, and add new html after existing one. 我正在寻找一种方法来摆脱这个div,并在现有的html之后添加新的html。
below screenshot, and code - how javascript button in generated - very simple. 下面的屏幕截图和代码-如何生成javascript按钮-非常简单。
var oferta = '<div class="col-sm-3"><h1>test</h1></div>'
setup: function (ed) {
ed.addButton('example', {
title: 'example.desc',
image: './/',
text: 'Oferta',
icon: true,
onclick: function () {
tinyMCE.execCommand('mceInsertContent', false, oferta);
}
});
},
EDIT: Below how this looks now when i hit button 3 times in row.(every next content is added to existing one.) 编辑:下面,当我连续3次点击按钮时,它的外观如下。(每个下一个内容都添加到现有内容中。)
Is very easy to do it try to change you code with this example. 通过此示例尝试更改您的代码非常容易。
setup: function (editor) {
ed.addButton('example', {
title: 'example.desc',
image: './/',
text: 'Oferta',
icon: true,
onclick: function () {
var h1 = editor.dom.create('h1');
h1.innerText = 'test';
var oferta = editor.dom.create('div' ,{'class': 'col-sm-3'});
oferta.appendChild(h1);
var divs = editor.dom.select('div');
if(divs && divs.length > 0){
editor.dom.insertAfter(oferta,divs[divs.length-1])
}else{
tinyMCE.execCommand('mceInsertContent', false,oferta.outerHTML);
}
editor.selection.select(oferta);
editor.selection.collapse(true);
}
});
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.