Skip to content

Commit

Permalink
safeguarded instanceof TouchEvent checks against undefined TouchEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
nhnb committed Nov 28, 2023
1 parent 3df4d9e commit ecb812c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions srcjs/stendhal/ui/ViewPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { ActionContextMenu } from "./dialog/ActionContextMenu";
import { DropQuantitySelectorDialog } from "./dialog/DropQuantitySelectorDialog";

import { DirectionPad } from "./joystick/DirectionPad";
import { Joystick } from "./joystick/Joystick";
import { JoystickBase } from "./joystick/JoystickBase";

import { singletons } from "../SingletonRepo";
Expand Down Expand Up @@ -308,7 +307,7 @@ export class ViewPort {
const mHandle: any = {};

mHandle._onMouseDown = function(e: MouseEvent|TouchEvent) {
if (e instanceof TouchEvent) {
if (window['TouchEvent'] && e instanceof TouchEvent) {
stendhal.ui.touch.onTouchStart();
}
var pos = stendhal.ui.html.extractPosition(e);
Expand Down Expand Up @@ -352,13 +351,13 @@ export class ViewPort {
}

mHandle.onMouseUp = function(e: MouseEvent|TouchEvent) {
if (e instanceof TouchEvent) {
if (window['TouchEvent'] && e instanceof TouchEvent) {
stendhal.ui.touch.onTouchEnd();
}
var pos = stendhal.ui.html.extractPosition(e);
const long_touch = stendhal.ui.touch.isLongTouch();
if ((e instanceof MouseEvent && mHandle.isRightClick(e)
|| (e instanceof TouchEvent && long_touch))) {
|| (window['TouchEvent'] && e instanceof TouchEvent && long_touch))) {
if (entity != stendhal.zone.ground) {
const append: any[] = [];
if (long_touch) {
Expand Down Expand Up @@ -506,7 +505,7 @@ export class ViewPort {
// item was dropped
stendhal.ui.heldItem = undefined;

const is_touch = e instanceof TouchEvent;
const is_touch = window['TouchEvent'] && e instanceof TouchEvent;
// if ctrl is pressed or is a touch event, we ask for the quantity
if (e.ctrlKey || is_touch) {
ui.createSingletonFloatingWindow("Quantity", new DropQuantitySelectorDialog(action, is_touch), pos.pageX - 50, pos.pageY - 25);
Expand Down
2 changes: 1 addition & 1 deletion srcjs/stendhal/ui/component/ItemContainerImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class ItemContainerImplementation {
const long_touch = stendhal.ui.touch.isLongTouch();
if (this.isRightClick(event) || long_touch) {
const append = [];
if (evt instanceof TouchEvent && long_touch) {
if (window['TouchEvent'] && evt instanceof TouchEvent && long_touch) {
// XXX: better way to pass instance to action function?
const tmp = this;
// action to "hold" item for moving or dropping using touch
Expand Down

0 comments on commit ecb812c

Please sign in to comment.