[OpenLayers-Dev] A generic button class:

Jeff Dege jdege at korterra.com
Mon Jul 30 16:50:15 EDT 2007


> From: dev-bounces at openlayers.org 
> [mailto:dev-bounces at openlayers.org] On Behalf Of Tim Schaub
> Sent: Monday, July 30, 2007 2:50 PM
> Cc: dev at openlayers.org
> Subject: Re: [OpenLayers-Dev] A generic button class:
> 
> Finally, for documentation sake alone, it makes sense to define an
empty 
> onClick method on the prototype (onClick: function() {}). Document
that 
> and have your trigger method always call it.

If we do that, then the trigger function no longer seems meaningful.

Instead of my:
    onClick: null,
    type: OpenLayers.Control.TYPE_BUTTON,
    trigger: function() {
        if (this.onClick)
           this.onClick();
    },

We'd have:

    onClick: function() {},
    type: OpenLayers.Control.TYPE_BUTTON,
    trigger: function() {
        this.onClick();
    },

In which case, we could just as easily leave out the onClick() function,
altogether, and instead of using the class thus:

    panel.addControls([nav,
        new OpenLayers.Control.Button(
          {'displayClass': 'MyButton', 'onClick': myFunction});
        ]);

do this:

    panel.addControls(new OpenLayers.Control.GenericButton(
        {'displayClass': 'MyButton', 'trigger': myFunction});
    ]);

And from that, we could skip the Button control entirely:

    panel.addControls(new OpenLayers.Control({type:
OpenLayers.Control.TYPE_BUTTON,
        'displayClass': 'MyButton', 'trigger': myFunction});
    ]);

At which point, things are simple enough that I'm not at all sure that
we gain anything by defining a separate Button class.








 



More information about the Dev mailing list