javascript - custom click event trigger, widget jquery -
i creating jquery widget, concept similar menu bar, has 2 buttons, example, buttonone , buttontwo.
i have style associated , html code.
i worked in hello world widget
// constructor _create: function() { var my=this.element; var supe=this; .............. //first event my.bind('mouseenter', function (event) { supe._trigger('activated', event, my); }); },
i use like
$(function() { ........... var bar=$("#bar-event").mybar(); //first atempt bar.click(function() { alert( "handler .click() called." ); }); //second attempt bar.bind('mybaractivated', function(event, data) { // handle event alert('yes working!!!!!!'); }); });
my first attempt, noob attempt, click works, in area of top div in html. in second attempt have access custom event.
unknown how fire click events of buttons, example, want control events like...
// $(function() { ........... var bar=$("#bar-event").mybar(); bar.clickbuttonone(function() {/*do*/}); //and bar.clickbuttontwo(function() {/*do*/});
or
//maybe $(function() { ........... var bar=$("#bar-event").mybar(); bar.bind('clickbuttonone',function(event,data) {/*do*/}); //and bar.bind('clickbuttontwo',function(event,data) {/*do*/});
but not trigger events within widget
well... capture click of button , propagate it
_create: function() { var my=this.element; var supe=this; ............... var btn=$(mybutton); btn.click(function (){ supe._trigger('btnclick'); }); }
if there more elegant or more efficient, let me know
Comments
Post a Comment