I'm creating a scrolling text ticker class in MooTools, named
Scroller. The initializer takes two arguments, the element it's going
to "control" and the options for the scroller, and has a bunch of
methods start(), stop(), nextItem(), toggle(), etc. The initializer
calls the occlude method of Class.Occlude. So an example for calling
it is:

var s = new Scroller($("scroller"), options);

then call s.start() or s.nextItem() or whatever.

I want to be able to add the methods to the element itself, so I could
call $('scroller').nextItem(), $('scoller').start(), etc. It just
seems more semantically correct, but it seems to be frowned upon, or
I've never seen it in use, I suppose there's a reason, I just want to
know why.

Also, whenever I write a class for example the scroller, I'll add
this:

        $extend (Scroller, {
                all: function(els, options) {
                        els.each(function(el) {
                                new Scroller(el, options);
                        });
                }
        });

and this:

        Scroller.all($$('.moo-scroller'), {
                interval: 4000,
                //autostart: false,
                tween: {
                        duration: 1000,
                        transition: "expo:in:out"
                }
        });

So I can just add my script tag before </body> and add classes
correspondingly. So I'm thinking of creating a "Widgeter" class that
handles this and more, so my own Scroller class and any other class
could add itself to Widgeter like so:

initializer: function() {
        ...
        if(Widgeter) Widgeter.add(Scroller);
}

and Widgeter would have a function something like this:

$extend(Widgeter, {

        prefix: 'widget-',

        add: function(widget_class) {
                if(!widgets_arr.contains(widget_class)) widgets_arr.push
(widget_class);
        },

        init: function() {
                widgets_arr.each(this.widgetize);
        },

        widgetize: function(widget_class, options) {
                $$(this.prefix + 
widget_class.toLowerCase()).each(function(element)
{
                        new widget_class(element, options);
                        this.occlude(widget_class.toString(), element);
                });

        }
});


so all the classes that add functionality to elements.

So what do you think ?

Reply via email to