[Event.buttonclick] make buttonclick work if target element is a child of the clicked button
This commit is contained in:
@@ -97,6 +97,31 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({
|
||||
delete this.target;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getPressedButton
|
||||
* Get the pressed button, if any. Returns undefined if no button
|
||||
* was pressed.
|
||||
*
|
||||
* Arguments:
|
||||
* element - {DOMElement} The event target.
|
||||
*
|
||||
* Returns:
|
||||
* {DOMElement} The button element, or undefined.
|
||||
*/
|
||||
getPressedButton: function(element) {
|
||||
var depth = 5, // limit the search depth
|
||||
button;
|
||||
do {
|
||||
if(OpenLayers.Element.hasClass(element, "olButton")) {
|
||||
// hit!
|
||||
button = element;
|
||||
break;
|
||||
}
|
||||
element = element.parentNode;
|
||||
} while(--depth > 0 && element);
|
||||
return button;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: buttonClick
|
||||
* Check if a button was clicked, and fire the buttonclick event
|
||||
@@ -108,27 +133,25 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({
|
||||
var propagate = true,
|
||||
element = OpenLayers.Event.element(evt);
|
||||
if (element && (OpenLayers.Event.isLeftClick(evt) || !~evt.type.indexOf("mouse"))) {
|
||||
if (element.nodeType === 3 || OpenLayers.Element.hasClass(element, "olAlphaImg")) {
|
||||
element = element.parentNode;
|
||||
}
|
||||
if (OpenLayers.Element.hasClass(element, "olButton")) {
|
||||
// was a button pressed?
|
||||
var button = this.getPressedButton(element);
|
||||
if (button) {
|
||||
if (evt.type === "keydown") {
|
||||
switch (evt.keyCode) {
|
||||
case OpenLayers.Event.KEY_RETURN:
|
||||
case OpenLayers.Event.KEY_SPACE:
|
||||
this.target.triggerEvent("buttonclick", {
|
||||
buttonElement: element
|
||||
buttonElement: button
|
||||
});
|
||||
OpenLayers.Event.stop(evt);
|
||||
propagate = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.startEvt) {
|
||||
} else if (this.startEvt) {
|
||||
if (this.completeRegEx.test(evt.type)) {
|
||||
var pos = OpenLayers.Util.pagePosition(element);
|
||||
var pos = OpenLayers.Util.pagePosition(button);
|
||||
this.target.triggerEvent("buttonclick", {
|
||||
buttonElement: element,
|
||||
buttonElement: button,
|
||||
buttonXY: {
|
||||
x: this.startEvt.clientX - pos[0],
|
||||
y: this.startEvt.clientY - pos[1]
|
||||
|
||||
Reference in New Issue
Block a user