简体   繁体   中英

custom click event trigger, widget jquery

I am creating a jquery widget, the concept is similar to a menu bar, it has two buttons, for example, ButtonOne and ButtonTwo.

I have style associated and my html code.

I worked in a 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 for .click() called." );
        });
        //second attempt
        bar.bind('mybaractivated', function(event, data) {
                // handle the event
            alert('YES WORKING!!!!!!');

        });
    });

My first attempt, was noob attempt, click works, but in all area of top div in html. In second attempt have access to my custom event.

Unknown to how to fire the click events of my buttons, for example, i want control the 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 to do to trigger events within the widget

Well... was something like capture the click of my button and propagate it

_create: function() 
    {
        var my=this.element;
        var supe=this;            

        ...............

        var btn=$(mybutton);
        btn.click(function (){
            supe._trigger('btnclick');
        });

    }

if there is a more elegant or more efficient, let me know

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM