Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access the bootstrap-wysihtml5 editor object

Tags:

jquery

wysiwyg

I'm trying to acces into an bootstrap-wysihtml5 editor object. I'm doing this by this way:

$(document).ready(function () {
     $('.someLink').live('click', function () {
          var wysihtml5Editor = $('#textarea').wysihtml5().editor;
          console.log('wysihtml5Editor: '+wysihtml5Editor);
          wysihtml5Editor.composer.commands.exec("bold");
     });
});

Chrome console returns:

> wysihtml5Editor: undefined
> Uncaught TypeError: Cannot read property 'composer' of undefined

So, the point is.

Which is the way to acces into an wysihtml5 object?

The point of everything is insert some html code into my textarea.

like image 471
CROWD Avatar asked Jan 17 '23 23:01

CROWD


1 Answers

Try this:

$(document).ready(function () {
   $('.someLink').live('click', function () {
     $('#textarea').wysihtml5();
     var wysihtml5Editor = $("#textarea").data("wysihtml5").editor;
     console.log('wysihtml5Editor: '+wysihtml5Editor);
     // The following is important since wysihtml5 is initialized asynchronously
     wysihtml5Editor.observe("load", function() {
       wysihtml5Editor.composer.commands.exec("bold");
     });
   });
});
like image 111
Christopher Blum Avatar answered Feb 03 '23 02:02

Christopher Blum