From bc37121ae0bb48cf0ca288b7aee58c56c00b3e4c Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sun, 24 Jun 2012 13:45:32 +0200 Subject: [PATCH] Accessibility - now we can use the keyboard to zoom in and out. --- src/ol/control/Zoom.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ol/control/Zoom.js b/src/ol/control/Zoom.js index 84f38bc38e..ecd976cbea 100644 --- a/src/ol/control/Zoom.js +++ b/src/ol/control/Zoom.js @@ -1,6 +1,8 @@ goog.provide('ol.control.Zoom'); +goog.require('ol.event'); goog.require('ol.control.Control'); + goog.require('goog.dom'); @@ -58,7 +60,8 @@ ol.control.Zoom.prototype.setMap = function(map) { ol.control.Zoom.prototype.activate = function() { var active = goog.base(this, 'activate'); if (active) { - this.map_.getEvents().register("click", this.handle, this); + this.map_.getEvents().register('click', this.handle, this); + this.map_.getEvents().register('keypress', this.handle, this); } return active; }; @@ -67,7 +70,8 @@ ol.control.Zoom.prototype.activate = function() { ol.control.Zoom.prototype.deactivate = function() { var inactive = goog.base(this, 'deactivate'); if (inactive) { - this.map_.getEvents().unregister("click", this.handle, this); + this.map_.getEvents().unregister('click', this.handle, this); + this.map_.getEvents().unregister('keypress', this.handle, this); } return inactive; }; @@ -78,16 +82,15 @@ ol.control.Zoom.prototype.deactivate = function() { ol.control.Zoom.prototype.handle = function(evt) { var target = /** @type {Node} */ (evt.target), handled = false; - if (goog.dom.getAncestorByClass(target, ol.control.Zoom.RES.IN_CLS)) { - this.map_.zoomIn(); - handled = true; - } else - if (goog.dom.getAncestorByClass(target, ol.control.Zoom.RES.OUT_CLS)) { - this.map_.zoomOut(); - handled = true; - } - if (handled) { - evt.preventDefault(); + if (evt.type === 'click' || ol.event.isEnterOrSpace(evt)) { + if (goog.dom.getAncestorByClass(target, ol.control.Zoom.RES.IN_CLS)) { + this.map_.zoomIn(); + handled = true; + } else + if (goog.dom.getAncestorByClass(target, ol.control.Zoom.RES.OUT_CLS)) { + this.map_.zoomOut(); + handled = true; + } } return !handled; };