0

I'm using this editor: http://xing.github.com/wysihtml5/examples/simple.html (live demo).

You can assign custom functions to events:

"events": {
  "focus": function() {
    //my event
  }
},

I added a custom button:

"font-styles": function(locale, options) {
  return "<li>" +
    "<a class='btn btn-paragraph' data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='p'>" + locale.font_styles.p + "</a>" +
  "</li>";
}

So, I want to trigger the button on focus (textarea):

"events": {
  "focus": function() { 
    $('.btn-paragraph').trigger('click');
  }
},

But nothing happens, not even errors in the console. The strange thing is that I tried this:

"events": {
  "focus": function() { 
    $('.btn-paragraph').hide();
  }
},

And the button hid as soon as I focus my cursor in the textarea.

What I am missing here?

alexchenco
  • 53,565
  • 76
  • 241
  • 413
  • have you tried `.click()` instead of `.trigger("click")`? In some examples, that worked for people considering forum posts. – David Müller Dec 13 '12 at 10:13

1 Answers1

1

trigger will trigger all event handlers bound to the click event. It will not simulate user interaction. Since you aren't binding any event handlers (at least from what I can see), nothing happens.

Try this:

"events": {
  "focus": function() { 
    $('.btn-paragraph').click(function(){
        alert('foo');
    });
    $('.btn-paragraph').trigger('click');
  }
},
Asad Saeeduddin
  • 46,193
  • 6
  • 90
  • 139