fix touch events for iOS 13

This commit is contained in:
Ian Richardson
2019-11-18 12:52:16 -06:00
parent e4a7be99e1
commit bf18702d13
4 changed files with 10 additions and 12 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ resources:
type: module type: module
views: views:
- cards: - cards:
- type: 'custom:boilerplate-card' - type: custom:boilerplate-card
name: Boilerplate Card Development name: Boilerplate Card Development
entity: sun.sun entity: sun.sun
test_gui: true test_gui: true
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "boilerplate-card", "name": "boilerplate-card",
"version": "1.1.4", "version": "1.1.6",
"description": "Lovelace boilerplate-card", "description": "Lovelace boilerplate-card",
"keywords": [ "keywords": [
"home-assistant", "home-assistant",
+7 -9
View File
@@ -90,12 +90,10 @@ class ActionHandler extends HTMLElement implements ActionHandler {
y = (ev as MouseEvent).pageY; y = (ev as MouseEvent).pageY;
} }
if (options.hasHold) { this.timer = window.setTimeout(() => {
this.timer = window.setTimeout(() => { this.startAnimation(x, y);
this.startAnimation(x, y); this.held = true;
this.held = true; }, this.holdTime);
}, this.holdTime);
}
this.cooldownStart = true; this.cooldownStart = true;
window.setTimeout(() => (this.cooldownStart = false), 100); window.setTimeout(() => (this.cooldownStart = false), 100);
@@ -141,7 +139,7 @@ class ActionHandler extends HTMLElement implements ActionHandler {
// That might be a bug, but until it's fixed, this should make action-handler work. // That might be a bug, but until it's fixed, this should make action-handler work.
// If it's not a bug that is fixed, this might need updating with the next iOS version. // If it's not a bug that is fixed, this might need updating with the next iOS version.
// Note that all events (both touch and mouse) must be listened for in order to work on computers with both mouse and touchscreen. // Note that all events (both touch and mouse) must be listened for in order to work on computers with both mouse and touchscreen.
const isIOS13 = window.navigator.userAgent.match(/iPhone OS 13_/); const isIOS13 = /iPhone OS 13_/.test(window.navigator.userAgent);
if (!isIOS13) { if (!isIOS13) {
element.addEventListener('mousedown', clickStart, { passive: true }); element.addEventListener('mousedown', clickStart, { passive: true });
element.addEventListener('click', clickEnd); element.addEventListener('click', clickEnd);
@@ -169,7 +167,7 @@ class ActionHandler extends HTMLElement implements ActionHandler {
// TODO You need to replace all instances of "action-handler-boilerplate" with "action-handler-<your card name>" // TODO You need to replace all instances of "action-handler-boilerplate" with "action-handler-<your card name>"
customElements.define('action-handler-boilerplate', ActionHandler); customElements.define('action-handler-boilerplate', ActionHandler);
const geActionHandler = (): ActionHandler => { const getActionHandler = (): ActionHandler => {
const body = document.body; const body = document.body;
if (body.querySelector('action-handler-boilerplate')) { if (body.querySelector('action-handler-boilerplate')) {
return body.querySelector('action-handler-boilerplate') as ActionHandler; return body.querySelector('action-handler-boilerplate') as ActionHandler;
@@ -182,7 +180,7 @@ const geActionHandler = (): ActionHandler => {
}; };
export const actionHandlerBind = (element: ActionHandlerElement, options: ActionHandlerOptions): void => { export const actionHandlerBind = (element: ActionHandlerElement, options: ActionHandlerOptions): void => {
const actionhandler: ActionHandler = geActionHandler(); const actionhandler: ActionHandler = getActionHandler();
if (!actionhandler) { if (!actionhandler) {
return; return;
} }
+1 -1
View File
@@ -1 +1 @@
export const CARD_VERSION = '1.1.5'; export const CARD_VERSION = '1.1.6';