marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
141 stars 40 forks source link

Binding More then one JavaScript only Marko Widgets to an HTML element #50

Open SunnyGurnani opened 9 years ago

SunnyGurnani commented 9 years ago

Is there a way to create a JavaScript only widget (Like JQuery effect) which can be bound to any existing HTML element in a way which supports assigning more then one such widget to a single element.

I saw an example of code using

but with this method only one JavaScript widget can be bound.

Following is how JQuery supports multiple JavaScript behavior

$("elementselector").effect1().effect2();
patrick-steele-idem commented 9 years ago

When using Marko Widgets to build UI components you are using Marko Widgets to facilitate binding behavior to rendered DOM elements. Marko Widgets will invoke your initializer at the appropriate time and you are free to attach your own behavior however you want. This may include using jQuery plugins or calling code in another JavaScript module as shown below:

var fancyEffect = require('./fancy-effect');

module.exports = require('marko-widgets').defineComponent({
    // ...
    init: function() {
        var el = this.el;

        $(el).effect1().effect2();
        fancyEffect.enable(el);
    }
});

Does that answer your question?

patrick-steele-idem commented 9 years ago

Hi @SunnyGurnani, have you had a chance to review my previous comment? Please let me know if that answers your questions. Thanks.