Abstract out key conditions for interactions, fixes #51, see also #54

This commit is contained in:
Tom Payne
2012-10-08 12:55:20 +02:00
parent a14a15159f
commit 8df0cfb9d9
6 changed files with 119 additions and 25 deletions
+56
View File
@@ -0,0 +1,56 @@
goog.provide('ol.interaction.ConditionType');
goog.provide('ol.interaction.condition');
/**
* @typedef {function(goog.events.BrowserEvent): boolean}
*/
ol.interaction.ConditionType;
/**
* @param {goog.events.BrowserEvent} browserEvent Browser event.
* @return {boolean} True if only the alt key is pressed.
*/
ol.interaction.condition.altKeyOnly = function(browserEvent) {
return (
browserEvent.altKey &&
!browserEvent.platformModifierKey &&
!browserEvent.shiftKey);
};
/**
* @param {goog.events.BrowserEvent} browserEvent Browser event.
* @return {boolean} True if only the no modifier keys are pressed.
*/
ol.interaction.condition.noModifierKeys = function(browserEvent) {
return (
!browserEvent.altKey &&
!browserEvent.platformModifierKey &&
!browserEvent.shiftKey);
};
/**
* @param {goog.events.BrowserEvent} browserEvent Browser event.
* @return {boolean} True if only the platform modifier key is pressed.
*/
ol.interaction.condition.platformModifierKeyOnly = function(browserEvent) {
return (
!browserEvent.altKey &&
browserEvent.platformModifierKey &&
!browserEvent.shiftKey);
};
/**
* @param {goog.events.BrowserEvent} browserEvent Browser event.
* @return {boolean} True if only the shift key is pressed.
*/
ol.interaction.condition.shiftKeyOnly = function(browserEvent) {
return (
!browserEvent.altKey &&
!browserEvent.platformModifierKey &&
browserEvent.shiftKey);
};