javascript - WP - JS - Get Instance of Tinymce Editor -


i'm creating wordpress plugin, adds metabox right under post editor containing button. plugin loads javascript file right below closing </body> tag.

purpose

at moment, trying achieve plugin simple. when user enters content editor , clicks button inside metabox, want modify editor's content.

js code

in simplest form:

jquery(document).ready(function($) {    $('#button').on('click', function(e) {       e.preventdefault();        var editor = tinymce.get("content");       editor.setcontent(some_content);    }); }); 

problem

the problem editor variable returns undefined.

firebug (when trying set var editor)

wpactiveeditor : "content"
editors : [ ]
activeeditor : null

what have tried

i have tried many, many things (also many small tweaks) found on tinymce's documentation , here on stackoverflow problem still remains same.

any appreciated.

ps. content textarea visible when running tests.

when editor first loads "text" mode active, tinymce not initialized, therefore cannot use tinymce.get(), opposed "visual" mode.

(i hadn't noticed works on "visual" mode, keep testing on "text" mode)

so, conditional statement necessary determine first tab active. solved problem piece of code:

if( $('#content').is(':visible') ) {      $('#content').val(some_content);  } else {      var editor = tinymce.get("content");     editor.setcontent(some_content);      } 

i pretty sure step other kind of problems now, @ least solved one!
hope answer prevent headaches :)


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -