Let's not over-engineer things (see #164).

This commit is contained in:
ahocevar
2012-01-21 10:46:44 +01:00
parent c38f4ce7bb
commit 9f9feabfae
2 changed files with 5 additions and 16 deletions
+4 -13
View File
@@ -64,20 +64,11 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({
* <OpenLayers.Events> instances. * <OpenLayers.Events> instances.
* *
* Parameters: * Parameters:
* options - {<OpenLayers.Events>|Object} Target instance of
* <OpenLayers.Events> or configuration properties for this
* <OpenLayers.Events.buttonclick> instance.
*
* Required configuration properties:
* target - {<OpenLayers.Events>} The events instance that the buttonclick * target - {<OpenLayers.Events>} The events instance that the buttonclick
* event will be triggered on. * event will be triggered on.
*/ */
initialize: function(options) { initialize: function(target) {
if (options instanceof OpenLayers.Events) { this.target = target;
options = {target: options};
}
OpenLayers.Util.extend(this, options);
for (var i=this.events.length-1; i>=0; --i) { for (var i=this.events.length-1; i>=0; --i) {
this.target.register(this.events[i], this, this.buttonClick, { this.target.register(this.events[i], this, this.buttonClick, {
extension: true extension: true
@@ -118,12 +109,12 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({
if (this.cancelRegEx.test(evt.type)) { if (this.cancelRegEx.test(evt.type)) {
delete this._buttonStarted; delete this._buttonStarted;
} }
OpenLayers.Event.stop(evt, false); OpenLayers.Event.stop(evt);
propagate = false; propagate = false;
} }
if (this.startRegEx.test(evt.type)) { if (this.startRegEx.test(evt.type)) {
this._buttonStarted = true; this._buttonStarted = true;
OpenLayers.Event.stop(evt, false); OpenLayers.Event.stop(evt);
propagate = false; propagate = false;
} }
} else { } else {
+1 -3
View File
@@ -20,10 +20,8 @@
} }
function test_ButtonClick(t) { function test_ButtonClick(t) {
t.plan(2); t.plan(1);
events = new OpenLayers.Events({}, element); events = new OpenLayers.Events({}, element);
buttonClick = new OpenLayers.Events.buttonclick({target: events});
t.ok(buttonClick.target === events, "target set from options argument");
buttonClick = new OpenLayers.Events.buttonclick(events); buttonClick = new OpenLayers.Events.buttonclick(events);
t.ok(buttonClick.target === events, "target set from constructor arg"); t.ok(buttonClick.target === events, "target set from constructor arg");
buttonClick.destroy(); buttonClick.destroy();