1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.