admin管理员组文章数量:1125981
I need to determine if the page/post editor is in Visual or Text mode. I also need to determine when this changes.
Does WordPress provide some kind of functionality for doing this? I am writing some JS that requires this information.
I need to determine if the page/post editor is in Visual or Text mode. I also need to determine when this changes.
Does WordPress provide some kind of functionality for doing this? I am writing some JS that requires this information.
Share Improve this question edited Jun 6, 2014 at 10:14 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Jun 6, 2014 at 5:49 user52790user52790 132 bronze badges2 Answers
Reset to default 3To determine what mode the editor is currently in, you can use the
getUserSetting('editor')
in JavaScript, which returns either "html" or "tinymce".To determine when the editor mode is switched, you can use the jQuery
click
event handler on the#content-tmce
and#content-html
elements, which are the editor type switching buttons:jQuery( '#content-tmce' ).click( function() { // Visual editor selected } );
jQuery( '#content-html' ).click( function() { // Text editor selected } );
Bear in mind that these click events will always be triggered when you click on the buttons; when you click on the "Visual" button for example, the event will be triggered regardless whether the current mode is "Visual" or "Text". If you need to, you could easily tackle that by storing the previous state yourself.
You could check tmce-active:
var editor = $('.tmce-active').val() != '' ? 'Text' : 'View';
本文标签: How can I determine what mode the editor is in and when it changes
版权声明:本文标题:How can I determine what mode the editor is in and when it changes? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736677365a1947252.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论