Adding support support for metaKey (Mac Cmd key)
This commit is contained in:
@@ -139,7 +139,8 @@ OpenLayers.Handler = OpenLayers.Class({
|
||||
var keyModifiers =
|
||||
(evt.shiftKey ? OpenLayers.Handler.MOD_SHIFT : 0) |
|
||||
(evt.ctrlKey ? OpenLayers.Handler.MOD_CTRL : 0) |
|
||||
(evt.altKey ? OpenLayers.Handler.MOD_ALT : 0);
|
||||
(evt.altKey ? OpenLayers.Handler.MOD_ALT : 0) |
|
||||
(evt.metaKey ? OpenLayers.Handler.MOD_META : 0);
|
||||
|
||||
/* if it differs from the handler object's key mask,
|
||||
bail out of the event handler */
|
||||
@@ -232,12 +233,12 @@ OpenLayers.Handler = OpenLayers.Class({
|
||||
* to get more information about the event that the handler is
|
||||
* processing.
|
||||
*
|
||||
* This allows modifier keys on the event to be checked (alt, shift,
|
||||
* and ctrl cannot be checked with the keyboard handler). For a
|
||||
* This allows modifier keys on the event to be checked (alt, shift, ctrl,
|
||||
* and meta cannot be checked with the keyboard handler). For a
|
||||
* control to determine which modifier keys are associated with the
|
||||
* event that a handler is currently processing, it should access
|
||||
* (code)handler.evt.altKey || handler.evt.shiftKey ||
|
||||
* handler.evt.ctrlKey(end).
|
||||
* handler.evt.ctrlKey || handler.evt.metaKey(end).
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The browser event.
|
||||
@@ -285,4 +286,10 @@ OpenLayers.Handler.MOD_CTRL = 2;
|
||||
*/
|
||||
OpenLayers.Handler.MOD_ALT = 4;
|
||||
|
||||
/**
|
||||
* Constant: OpenLayers.Handler.MOD_META
|
||||
* If set as the <keyMask>, <checkModifiers> returns false if Cmd is down.
|
||||
*/
|
||||
OpenLayers.Handler.MOD_META = 8;
|
||||
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
}
|
||||
|
||||
function test_Handler_setEvent(t) {
|
||||
t.plan(4);
|
||||
t.plan(5);
|
||||
var map = new OpenLayers.Map('map');
|
||||
var control = new OpenLayers.Control();
|
||||
map.addControl(control);
|
||||
@@ -135,7 +135,8 @@
|
||||
xy: new OpenLayers.Pixel(Math.random(), Math.random()),
|
||||
altKey: (Math.random() > 0.5),
|
||||
shiftKey: (Math.random() > 0.5),
|
||||
ctrlKey: (Math.random() > 0.5)
|
||||
ctrlKey: (Math.random() > 0.5),
|
||||
metaKey: (Math.random() > 0.5)
|
||||
}
|
||||
map.events.triggerEvent("click", testEvent);
|
||||
t.ok(handler.evt.xy.x == testEvent.xy.x &&
|
||||
@@ -147,6 +148,8 @@
|
||||
"handler.evt.shiftKey correct");
|
||||
t.eq(handler.evt.ctrlKey, testEvent.ctrlKey,
|
||||
"handler.evt.ctrlKey correct");
|
||||
t.eq(handler.evt.metaKey, testEvent.metaKey,
|
||||
"handler.evt.metaKey correct");
|
||||
}
|
||||
|
||||
function test_Handler_destroy(t) {
|
||||
@@ -173,7 +176,7 @@
|
||||
}
|
||||
|
||||
function test_Handler_checkModifiers(t) {
|
||||
t.plan(26);
|
||||
t.plan(62);
|
||||
var handler = new OpenLayers.Handler({});
|
||||
handler.keyMask = null;
|
||||
var proceed = handler.checkModifiers({});
|
||||
@@ -192,7 +195,8 @@
|
||||
MOD_NONE: null,
|
||||
MOD_SHIFT: "shiftKey",
|
||||
MOD_CTRL: "ctrlKey",
|
||||
MOD_ALT: "altKey"
|
||||
MOD_ALT: "altKey",
|
||||
MOD_META: "metaKey"
|
||||
}
|
||||
var proceed, evt, value, c, k;
|
||||
for(c in constants) {
|
||||
@@ -220,8 +224,8 @@
|
||||
* is OpenLayers.Handler.MOD_SHIFT, checkModifiers should return
|
||||
* true.
|
||||
*/
|
||||
var constants = ["MOD_SHIFT", "MOD_CTRL", "MOD_ALT"];
|
||||
var keys = ["shiftKey", "ctrlKey", "altKey"];
|
||||
var constants = ["MOD_SHIFT", "MOD_CTRL", "MOD_ALT", "MOD_META"];
|
||||
var keys = ["shiftKey", "ctrlKey", "altKey", "metaKey"];
|
||||
var proceed, evt, c1, c2, k1, k2;
|
||||
for(var i=0; i<constants.length-1; ++i) {
|
||||
c1 = constants[i];
|
||||
|
||||
Reference in New Issue
Block a user