goog.provide('ol.events.condition'); goog.require('ol.asserts'); goog.require('ol.has'); goog.require('ol.functions'); goog.require('ol.MapBrowserEvent.EventType'); /** * Return `true` if only the alt-key is pressed, `false` otherwise (e.g. when * additionally the shift-key is pressed). * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True if only the alt key is pressed. * @api stable */ ol.events.condition.altKeyOnly = function(mapBrowserEvent) { var originalEvent = mapBrowserEvent.originalEvent; return ( originalEvent.altKey && !(originalEvent.metaKey || originalEvent.ctrlKey) && !originalEvent.shiftKey); }; /** * Return `true` if only the alt-key and shift-key is pressed, `false` otherwise * (e.g. when additionally the platform-modifier-key is pressed). * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True if only the alt and shift keys are pressed. * @api stable */ ol.events.condition.altShiftKeysOnly = function(mapBrowserEvent) { var originalEvent = mapBrowserEvent.originalEvent; return ( originalEvent.altKey && !(originalEvent.metaKey || originalEvent.ctrlKey) && originalEvent.shiftKey); }; /** * Return always true. * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True. * @function * @api stable */ ol.events.condition.always = ol.functions.TRUE; /** * Return `true` if the event is a `click` event, `false` otherwise. * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True if the event is a map `click` event. * @api stable */ ol.events.condition.click = function(mapBrowserEvent) { return mapBrowserEvent.type == ol.MapBrowserEvent.EventType.CLICK; }; /** * Return `true` if the event has an "action"-producing mouse button. * * By definition, this includes left-click on windows/linux, and left-click * without the ctrl key on Macs. * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} The result. */ ol.events.condition.mouseActionButton = function(mapBrowserEvent) { var originalEvent = mapBrowserEvent.originalEvent; return originalEvent.button == 0 && !(ol.has.WEBKIT && ol.has.MAC && originalEvent.ctrlKey); }; /** * Return always false. * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} False. * @function * @api stable */ ol.events.condition.never = ol.functions.FALSE; /** * Return `true` if the browser event is a `pointermove` event, `false` * otherwise. * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True if the browser event is a `pointermove` event. * @api */ ol.events.condition.pointerMove = function(mapBrowserEvent) { return mapBrowserEvent.type == 'pointermove'; }; /** * Return `true` if the event is a map `singleclick` event, `false` otherwise. * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True if the event is a map `singleclick` event. * @api stable */ ol.events.condition.singleClick = function(mapBrowserEvent) { return mapBrowserEvent.type == ol.MapBrowserEvent.EventType.SINGLECLICK; }; /** * Return `true` if the event is a map `dblclick` event, `false` otherwise. * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True if the event is a map `dblclick` event. * @api stable */ ol.events.condition.doubleClick = function(mapBrowserEvent) { return mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK; }; /** * Return `true` if no modifier key (alt-, shift- or platform-modifier-key) is * pressed. * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True only if there no modifier keys are pressed. * @api stable */ ol.events.condition.noModifierKeys = function(mapBrowserEvent) { var originalEvent = mapBrowserEvent.originalEvent; return ( !originalEvent.altKey && !(originalEvent.metaKey || originalEvent.ctrlKey) && !originalEvent.shiftKey); }; /** * Return `true` if only the platform-modifier-key (the meta-key on Mac, * ctrl-key otherwise) is pressed, `false` otherwise (e.g. when additionally * the shift-key is pressed). * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True if only the platform modifier key is pressed. * @api stable */ ol.events.condition.platformModifierKeyOnly = function(mapBrowserEvent) { var originalEvent = mapBrowserEvent.originalEvent; return ( !originalEvent.altKey && (ol.has.MAC ? originalEvent.metaKey : originalEvent.ctrlKey) && !originalEvent.shiftKey); }; /** * Return `true` if only the shift-key is pressed, `false` otherwise (e.g. when * additionally the alt-key is pressed). * * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @return {boolean} True if only the shift key is pressed. * @api stable */ ol.events.condition.shiftKeyOnly = function(mapBrowserEvent) { var originalEvent = mapBrowserEvent.originalEvent; return ( !originalEvent.altKey && !(originalEvent.metaKey || originalEvent.ctrlKey) && originalEvent.shiftKey); }; /** * Return `true` if the target element is not editable, i.e. not a ``-, * `