Merge pull request #8666 from schmidtk/ts-condition-fixes

Fix condition TypeScript errors
This commit is contained in:
Andreas Hocevar
2018-10-02 21:10:10 +02:00
committed by GitHub
+12 -12
View File
@@ -2,6 +2,7 @@
* @module ol/events/condition * @module ol/events/condition
*/ */
import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
import {TRUE, FALSE} from '../functions.js'; import {TRUE, FALSE} from '../functions.js';
import {WEBKIT, MAC} from '../has.js'; import {WEBKIT, MAC} from '../has.js';
@@ -24,7 +25,7 @@ import {WEBKIT, MAC} from '../has.js';
* @api * @api
*/ */
export const altKeyOnly = function(mapBrowserEvent) { export const altKeyOnly = function(mapBrowserEvent) {
const originalEvent = mapBrowserEvent.originalEvent; const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return ( return (
originalEvent.altKey && originalEvent.altKey &&
!(originalEvent.metaKey || originalEvent.ctrlKey) && !(originalEvent.metaKey || originalEvent.ctrlKey) &&
@@ -41,7 +42,7 @@ export const altKeyOnly = function(mapBrowserEvent) {
* @api * @api
*/ */
export const altShiftKeysOnly = function(mapBrowserEvent) { export const altShiftKeysOnly = function(mapBrowserEvent) {
const originalEvent = mapBrowserEvent.originalEvent; const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return ( return (
originalEvent.altKey && originalEvent.altKey &&
!(originalEvent.metaKey || originalEvent.ctrlKey) && !(originalEvent.metaKey || originalEvent.ctrlKey) &&
@@ -94,7 +95,7 @@ export const click = function(mapBrowserEvent) {
* @return {boolean} The result. * @return {boolean} The result.
*/ */
export const mouseActionButton = function(mapBrowserEvent) { export const mouseActionButton = function(mapBrowserEvent) {
const originalEvent = mapBrowserEvent.originalEvent; const originalEvent = /** @type {MouseEvent} */ (mapBrowserEvent.originalEvent);
return originalEvent.button == 0 && return originalEvent.button == 0 &&
!(WEBKIT && MAC && originalEvent.ctrlKey); !(WEBKIT && MAC && originalEvent.ctrlKey);
}; };
@@ -156,7 +157,7 @@ export const doubleClick = function(mapBrowserEvent) {
* @api * @api
*/ */
export const noModifierKeys = function(mapBrowserEvent) { export const noModifierKeys = function(mapBrowserEvent) {
const originalEvent = mapBrowserEvent.originalEvent; const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return ( return (
!originalEvent.altKey && !originalEvent.altKey &&
!(originalEvent.metaKey || originalEvent.ctrlKey) && !(originalEvent.metaKey || originalEvent.ctrlKey) &&
@@ -174,7 +175,7 @@ export const noModifierKeys = function(mapBrowserEvent) {
* @api * @api
*/ */
export const platformModifierKeyOnly = function(mapBrowserEvent) { export const platformModifierKeyOnly = function(mapBrowserEvent) {
const originalEvent = mapBrowserEvent.originalEvent; const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return !originalEvent.altKey && return !originalEvent.altKey &&
(MAC ? originalEvent.metaKey : originalEvent.ctrlKey) && (MAC ? originalEvent.metaKey : originalEvent.ctrlKey) &&
!originalEvent.shiftKey; !originalEvent.shiftKey;
@@ -190,7 +191,7 @@ export const platformModifierKeyOnly = function(mapBrowserEvent) {
* @api * @api
*/ */
export const shiftKeyOnly = function(mapBrowserEvent) { export const shiftKeyOnly = function(mapBrowserEvent) {
const originalEvent = mapBrowserEvent.originalEvent; const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return ( return (
!originalEvent.altKey && !originalEvent.altKey &&
!(originalEvent.metaKey || originalEvent.ctrlKey) && !(originalEvent.metaKey || originalEvent.ctrlKey) &&
@@ -208,7 +209,7 @@ export const shiftKeyOnly = function(mapBrowserEvent) {
*/ */
export const targetNotEditable = function(mapBrowserEvent) { export const targetNotEditable = function(mapBrowserEvent) {
const target = mapBrowserEvent.originalEvent.target; const target = mapBrowserEvent.originalEvent.target;
const tagName = target.tagName; const tagName = /** @type {Element} */ (target).tagName;
return ( return (
tagName !== 'INPUT' && tagName !== 'INPUT' &&
tagName !== 'SELECT' && tagName !== 'SELECT' &&
@@ -224,11 +225,9 @@ export const targetNotEditable = function(mapBrowserEvent) {
* @api * @api
*/ */
export const mouseOnly = function(mapBrowserEvent) { export const mouseOnly = function(mapBrowserEvent) {
assert(mapBrowserEvent.pointerEvent, 56); // mapBrowserEvent must originate from a pointer event assert(mapBrowserEvent instanceof MapBrowserPointerEvent, 56); // mapBrowserEvent must originate from a pointer event
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType // see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
return ( return /** @type {MapBrowserPointerEvent} */ (mapBrowserEvent).pointerEvent.pointerType == 'mouse';
/** @type {import("../MapBrowserEvent.js").default} */ (mapBrowserEvent).pointerEvent.pointerType == 'mouse'
);
}; };
@@ -242,6 +241,7 @@ export const mouseOnly = function(mapBrowserEvent) {
* @api * @api
*/ */
export const primaryAction = function(mapBrowserEvent) { export const primaryAction = function(mapBrowserEvent) {
const pointerEvent = mapBrowserEvent.pointerEvent; assert(mapBrowserEvent instanceof MapBrowserPointerEvent, 56); // mapBrowserEvent must originate from a pointer event
const pointerEvent = /** @type {MapBrowserPointerEvent} */ (mapBrowserEvent).pointerEvent;
return pointerEvent.isPrimary && pointerEvent.button === 0; return pointerEvent.isPrimary && pointerEvent.button === 0;
}; };