I need to show the editor on my plugin dynamically. I tried using the javascript code to show editor
tinyMCE.settings = tinyMCEPreInit.mceInit.content;
tinyMCE.execCommand('mceAddControl', false, textareaid);
But it doesnot show the upload and switch editors.
So I tired using an ajax in my javascript.
javascript
dataString = 'action=' + admin_object.action_editor + '&security=' + admin_object.action_editor_security + '&count=' + count;
jQuery.ajax({
type: "POST",
url: admin_object.ajax_url,
data: dataString,
success: function(resultData){
jQuery('.woocommerce_product_tab_wrapper').stop(true).css('opacity', '1').unblock();
$div_group.append(resultData);
$div_wrap.append($div_group);
jQuery('.woocommerce_product_tab_wrapper').append($div_wrap);
$div_wrap.css('display','none');
tinyMCE.settings = tinyMCEPreInit.mceInit.content;
tinyMCE.execCommand('mceAddControl', false, 'wptb_content_'+tab_count);
switchEditors.switchto({'id' : 'wptb_content_'+tab_count+'-html'});
jQuery("#wptb_content_"+ tab_count +"_ifr").contents().find(".qp").css("background-color","#00ff00");
jQuery('.woocommerce_product_tab_wrapper .tabs').find('li.'+tab_title_slug + '_tab a').click();
tab_count++;
}
});
Ajax function handler
public function get_editor() {
check_ajax_referer( 'get-editor', 'security' );
$tabcount = isset($_POST['count']) ? $_POST['tabcount'] : '';
if(!is_numeric($count) && $count < 0) die();
$settings = array(
'quicktags' => array( 'buttons' => 'em,strong,link' ),
'textarea_name' => 'content[]',
'quicktags' => true,
'tinymce' => true,
'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;background:#FFFFFF;}</style>'
);
wp_editor( htmlspecialchars_decode( '' ), 'content_'.$tabcount, $settings );
die();
}
It shows me the upload and the switch editor. But now another error crops up. Initially editor is switched to html mode and buttons shown are visual. When I click the switch editor button to html the editor goes off.
Can any body help to show the editors by using the javascript.
Thanks