diff --git a/lib/OpenLayers/Control/SelectFeature.js b/lib/OpenLayers/Control/SelectFeature.js index 2336b24929..ac9ab2ee3f 100644 --- a/lib/OpenLayers/Control/SelectFeature.js +++ b/lib/OpenLayers/Control/SelectFeature.js @@ -76,7 +76,7 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, { initialize: function(layer, options) { OpenLayers.Control.prototype.initialize.apply(this, [options]); this.callbacks = OpenLayers.Util.extend({ - down: this.downFeature, + click: this.clickFeature, over: this.overFeature, out: this.outFeature }, this.callbacks); @@ -85,13 +85,13 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, { }, /** - * Method: downFeature - * Called when the feature handler detects a mouse-down on a feature + * Method: clickFeature + * Called when the feature handler detects a click on a feature * * Parameters: * feature - {} */ - downFeature: function(feature) { + clickFeature: function(feature) { if(this.hover) { return; } diff --git a/lib/OpenLayers/Handler/Feature.js b/lib/OpenLayers/Handler/Feature.js index f07ff29582..fc1a9a1990 100644 --- a/lib/OpenLayers/Handler/Feature.js +++ b/lib/OpenLayers/Handler/Feature.js @@ -8,8 +8,8 @@ * * Class: OpenLayers.Handler.Feature * Handler to respond to mouse events related to a drawn feature. - * Callbacks will be called for over, move, out, up, and down (corresponding - * to the equivalent mouse events). + * Callbacks will be called for over, move, out, up, down, and click + * (corresponding to the equivalent mouse events). */ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { @@ -41,6 +41,18 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { this.layer = layer; }, + /** + * Method: click + * Handle click. Call the "click" callback if down on a feature. + * + * Parameters: + * evt - {Event} + */ + click: function(evt) { + var selected = this.select('click', evt); + return !selected; // stop event propagation if selected + }, + /** * Method: mousedown * Handle mouse down. Call the "down" callback if down on a feature. diff --git a/tests/Handler/test_Feature.html b/tests/Handler/test_Feature.html index 7be2ab0ce0..56295094a9 100644 --- a/tests/Handler/test_Feature.html +++ b/tests/Handler/test_Feature.html @@ -54,6 +54,149 @@ "layer z-index properly adjusted"); } + function test_Handler_Feature_events(t) { + t.plan(25); + + var map = new OpenLayers.Map('map'); + var control = new OpenLayers.Control(); + map.addControl(control); + var layer = new OpenLayers.Layer(); + map.addLayer(layer); + var handler = new OpenLayers.Handler.Feature(control, layer); + + // list below events that should be handled (events) and those + // that should not be handled (nonevents) by the handler + var events = ["mousedown", "mouseup", "mousemove", "click", "dblclick"]; + var nonevents = ["mouseout", "resize", "focus", "blur"]; + map.events.registerPriority = function(type, obj, func) { + var output = func(); + // Don't listen for setEvent handlers (#902) + if (typeof output == "string") { + t.eq(OpenLayers.Util.indexOf(nonevents, type), -1, + "registered method is not one of the events " + + "that should not be handled"); + t.ok(OpenLayers.Util.indexOf(events, type) > -1, + "activate calls registerPriority with browser event: " + type); + t.eq(typeof func, "function", + "activate calls registerPriority with a function"); + t.eq(func(), type, + "activate calls registerPriority with the correct method:"+type); + t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.Feature", + "activate calls registerPriority with the handler"); + } + } + + // set browser event like properties on the handler + for(var i=0; i