admin管理员组文章数量:1026989
I'm trying to reset tinymce content.
On the beginning there is some 'A content'. User changed it to some 'B content', but he don't want to save it, so he can click 'cancel' button and whole content is back to 'A' version.
A content is text saved earlier, so it's not constant. How to reset tinyMce text to original one? Html:
<div id="someDiv">Content A</div>
Would be nice to see something like this. If content was modified, cancel button will reset content to original:
if($('#someDiv').tinymce().isDirty()) {:
$('#someDiv').tinymce().reset();
}
I'm trying to reset tinymce content.
On the beginning there is some 'A content'. User changed it to some 'B content', but he don't want to save it, so he can click 'cancel' button and whole content is back to 'A' version.
A content is text saved earlier, so it's not constant. How to reset tinyMce text to original one? Html:
<div id="someDiv">Content A</div>
Would be nice to see something like this. If content was modified, cancel button will reset content to original:
if($('#someDiv').tinymce().isDirty()) {:
$('#someDiv').tinymce().reset();
}
Share
Improve this question
asked Mar 18, 2013 at 16:10
imclickingmaniacimclickingmaniac
1,5731 gold badge17 silver badges30 bronze badges
5
- 2 Yes, bravo CBroe. You know that i've visited almost all the results from few first pages of this query before i posted here? If you will find there answer for my question, then post, and don't treat me like an idiot! – imclickingmaniac Commented Mar 19, 2013 at 8:47
- I can’t know that you did any research of your self before if you don’t mention that in any way. – C3roe Commented Mar 19, 2013 at 9:11
- Well, sorry. I also don't like when ppl don't search before question, so I understand your intention. All results I found are about clearing editor, but not about reset to its beginning state. Also found few examples that doesn't work :( So I'm still waiting for help. – imclickingmaniac Commented Mar 19, 2013 at 9:29
- 1 I doubt that a simple “reset” is even possible – since these editors actually manipulate DOM content on the fly. I guess one would have to “save”/clone the original DOM node the editor is called upon before doing so – and then have the actual, user-manipulated DOM replaced by this copy of the original nodes when one wants to “reset” everything to its original state. – C3roe Commented Mar 19, 2013 at 9:41
- Yes. This is what i have done now. Because this is div and not form element the js reset will not help. I had little hope that there is some built in function to reset tinyMCE content and I just can't find it :( – imclickingmaniac Commented Mar 19, 2013 at 10:16
1 Answer
Reset to default 3This can be easily done.
You need to add this (using the setup parameter) to your configuration:
tinyMCE.init({
...
setup : function(ed) {
ed.onInit.add(function(ed, evt) {
ed.init_content = ed.getContent();
});
}
});
on buttonclick you call the following to reset the editor content
var ed = tinymce.get('your_editor_id');
ed.setContent(ed.init_content);
EDIT - For tinymce 4.x the syntax for attaching editor events has changed and is now:
tinymce.init({
...
setup: function (ed) {
ed.on('init', function () {
...
});
}
});
I'm trying to reset tinymce content.
On the beginning there is some 'A content'. User changed it to some 'B content', but he don't want to save it, so he can click 'cancel' button and whole content is back to 'A' version.
A content is text saved earlier, so it's not constant. How to reset tinyMce text to original one? Html:
<div id="someDiv">Content A</div>
Would be nice to see something like this. If content was modified, cancel button will reset content to original:
if($('#someDiv').tinymce().isDirty()) {:
$('#someDiv').tinymce().reset();
}
I'm trying to reset tinymce content.
On the beginning there is some 'A content'. User changed it to some 'B content', but he don't want to save it, so he can click 'cancel' button and whole content is back to 'A' version.
A content is text saved earlier, so it's not constant. How to reset tinyMce text to original one? Html:
<div id="someDiv">Content A</div>
Would be nice to see something like this. If content was modified, cancel button will reset content to original:
if($('#someDiv').tinymce().isDirty()) {:
$('#someDiv').tinymce().reset();
}
Share
Improve this question
asked Mar 18, 2013 at 16:10
imclickingmaniacimclickingmaniac
1,5731 gold badge17 silver badges30 bronze badges
5
- 2 Yes, bravo CBroe. You know that i've visited almost all the results from few first pages of this query before i posted here? If you will find there answer for my question, then post, and don't treat me like an idiot! – imclickingmaniac Commented Mar 19, 2013 at 8:47
- I can’t know that you did any research of your self before if you don’t mention that in any way. – C3roe Commented Mar 19, 2013 at 9:11
- Well, sorry. I also don't like when ppl don't search before question, so I understand your intention. All results I found are about clearing editor, but not about reset to its beginning state. Also found few examples that doesn't work :( So I'm still waiting for help. – imclickingmaniac Commented Mar 19, 2013 at 9:29
- 1 I doubt that a simple “reset” is even possible – since these editors actually manipulate DOM content on the fly. I guess one would have to “save”/clone the original DOM node the editor is called upon before doing so – and then have the actual, user-manipulated DOM replaced by this copy of the original nodes when one wants to “reset” everything to its original state. – C3roe Commented Mar 19, 2013 at 9:41
- Yes. This is what i have done now. Because this is div and not form element the js reset will not help. I had little hope that there is some built in function to reset tinyMCE content and I just can't find it :( – imclickingmaniac Commented Mar 19, 2013 at 10:16
1 Answer
Reset to default 3This can be easily done.
You need to add this (using the setup parameter) to your configuration:
tinyMCE.init({
...
setup : function(ed) {
ed.onInit.add(function(ed, evt) {
ed.init_content = ed.getContent();
});
}
});
on buttonclick you call the following to reset the editor content
var ed = tinymce.get('your_editor_id');
ed.setContent(ed.init_content);
EDIT - For tinymce 4.x the syntax for attaching editor events has changed and is now:
tinymce.init({
...
setup: function (ed) {
ed.on('init', function () {
...
});
}
});
本文标签: javascriptReset tinyMce contentStack Overflow
版权声明:本文标题:javascript - Reset tinyMce content - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745662532a2161977.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论