I am wondering if this a better replacement to this code to make it look less hacky:
active_tiny_editor = setInterval(function () {
if(tinyMCE.activeEditor!==null){
my_object.switch_tabs('tmce');
clearInterval(active_tiny_editor);
}
}, 200);
Ideally the problem is that after page reload, the Wordpress visual editor is gone. I need to switch back to text mode and again to visual editor to see the content..
It looks like something doesn't get initialized correctly on the page after the first load and it gets fixed when switching editing modes.
Please let me know if you have some idea. Thanks.
UPDATE:
This is the code:
// select active editor tab
switch(bootstrap_config_object.editor_active_tab)
{
case 0:
bootstrap_object.switch_tabs('html');
break;
case 1:
if(bootstrap_config_object.tmce_editor_status==1){
active_tiny_editor = setInterval(function () {
if(tinyMCE.activeEditor!==null){
bootstrap_object.switch_tabs('tmce');
clearInterval(active_tiny_editor);
}
}, 200);
}else{
bootstrap_object.switch_tabs('html');
}
break;
case 2:
bootstrap_object.switch_tabs('syntax');
myCodeMirror.refresh();
break;
}
Then this is the bootstrap_object containing the switching tabs logic:
switch_tabs: function(do_active) {// switch active tabs
switch(do_active)
{
case 'html':
jQuery('#content-html').addClass('switch-html');
jQuery('#content-bootstrap').removeClass('switch-bootstrap');
jQuery('#wrap-code-bootstrap, #codemirror-insert-media').addClass('element-hide');
jQuery('#content, #ed_toolbar, .insert-media, #content-resize-handle').removeClass('element-hide');
jQuery('#wp-content-wrap').addClass('html-active').removeClass('syntax-active').removeClass('tmce-active');
jQuery('#content').show();
jQuery('#content_parent, .CodeMirror').hide();
if(bootstrap_config_object.codemirror_status==1){
bootstrap_object.replase_shortcode_add_method('normal');
}
break;
case 'tmce':
active_tiny_editor = setInterval(function () {
if(tinyMCE.activeEditor!==null){
jQuery('#content_parent').show();
clearInterval(active_tiny_editor);
}
}, 200);
jQuery('#content-tmce').addClass('switch-tmce');
jQuery('#content-bootstrap').removeClass('switch-bootstrap');
jQuery('#wrap-code-bootstrap, #content, #ed_toolbar, #codemirror-insert-media').addClass('element-hide');
jQuery('#content_parent, .insert-media, #content-resize-handle').removeClass('element-hide');
jQuery('#wp-content-wrap').addClass('tmce-active').removeClass('syntax-active').removeClass('html-active');
jQuery('#content_parent').show();
jQuery('.CodeMirror, #content').hide();
if(bootstrap_config_object.codemirror_status==1){
bootstrap_object.replase_shortcode_add_method('normal');
}
break;
case 'syntax':
jQuery('#content-bootstrap').addClass('switch-bootstrap');
jQuery('.wp-switch-editor').removeClass('switch-tmce switch-html');
jQuery('#content_parent, #content, #ed_toolbar, .insert-media, #content-resize-handle').addClass('element-hide');
jQuery('#wrap-code-bootstrap, #codemirror-insert-media').removeClass('element-hide');
jQuery('#wp-content-wrap').addClass('syntax-active').removeClass('tmce-active').removeClass('html-active');
jQuery('.CodeMirror').show();
jQuery('#content_parent, #content').hide();
// resize codemirror
wp_settings = bootstrap_object.URLToArray(jQuery.cookie("wp-settings-"+bootstrap_config_object.user_id));
if(wp_settings){
jQuery('.CodeMirror').css('height', parseInt(wp_settings['ed_size'])+30+'px');
}
tinyMCE.execCommand('mceRemoveControl', false, 'content');
if(bootstrap_config_object.codemirror_status==1){
bootstrap_object.replase_shortcode_add_method('syntax');
}
break;
}
// set active tab
jQuery('#editor-active-tab').val(do_active);
THe functionality:
I have three editing tabs in the WP editor, the traditional Visual and Text editor in WP. Then I add a new one called "Syntax" which will transformed the editor to show the syntax HTML using Code Mirror. I need them to be consistent and stable when it comes to using it and adding shortcodes, etc.