From b9a89a97897330284abd9ac01e65b7435acaadc4 Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Wed, 5 Jan 2022 23:05:41 -0300 Subject: [PATCH] move touch.js to canvas --- src/common/browser.js | 6 ------ src/editor/Editor.js | 1 - src/editor/EditorStartup.js | 1 - src/editor/extensions/ext-imagelib/ext-imagelib.js | 7 ------- src/svgcanvas/select.js | 5 +++-- src/svgcanvas/svgcanvas.js | 3 ++- src/{editor => svgcanvas}/touch.js | 12 +++++++----- 7 files changed, 12 insertions(+), 23 deletions(-) rename src/{editor => svgcanvas}/touch.js (76%) diff --git a/src/common/browser.js b/src/common/browser.js index 231617c4..5a1e2863 100644 --- a/src/common/browser.js +++ b/src/common/browser.js @@ -15,7 +15,6 @@ const isWebkit_ = userAgent.includes('AppleWebKit') const isGecko_ = userAgent.includes('Gecko/') const isChrome_ = userAgent.includes('Chrome/') const isMac_ = userAgent.includes('Macintosh') -const isTouch_ = 'ontouchstart' in window // text character positioning (for IE9 and now Chrome) const supportsGoodTextCharPos_ = (function () { @@ -60,11 +59,6 @@ export const isChrome = () => isChrome_ * @returns {boolean} */ export const isMac = () => isMac_ -/** - * @function module:browser.isTouch - * @returns {boolean} -*/ -export const isTouch = () => isTouch_ /** * @function module:browser.supportsGoodTextCharPos diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 97b7e1c2..41012187 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -16,7 +16,6 @@ import './components/index.js' import './dialogs/index.js' -import './touch.js' import { isMac } from '../common/browser.js' import SvgCanvas from '../svgcanvas/svgcanvas.js' diff --git a/src/editor/EditorStartup.js b/src/editor/EditorStartup.js index 9b37fd91..59429db5 100644 --- a/src/editor/EditorStartup.js +++ b/src/editor/EditorStartup.js @@ -1,5 +1,4 @@ /* globals seConfirm seAlert */ -import './touch.js' import { convertUnit } from '../common/units.js' import { putLocale diff --git a/src/editor/extensions/ext-imagelib/ext-imagelib.js b/src/editor/extensions/ext-imagelib/ext-imagelib.js index c8da0d7a..7a93cb18 100644 --- a/src/editor/extensions/ext-imagelib/ext-imagelib.js +++ b/src/editor/extensions/ext-imagelib/ext-imagelib.js @@ -443,13 +443,6 @@ export default { header.textContent = allLibs back.style.display = 'none' }) - back.addEventListener('touchend', function () { - frame.setAttribute('src', 'about:blank') - frame.style.display = 'none' - libOpts.style.display = 'block' - header.textContent = allLibs - back.style.display = 'none' - }) back.setAttribute('style', 'margin-right: 5px;') back.style.display = 'none' diff --git a/src/svgcanvas/select.js b/src/svgcanvas/select.js index 8b7f478b..d0f20696 100644 --- a/src/svgcanvas/select.js +++ b/src/svgcanvas/select.js @@ -6,13 +6,14 @@ * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller */ -import { isTouch, isWebkit } from '../common/browser.js' // , isOpera +import { isWebkit } from '../common/browser.js' // , isOpera import { getRotationAngle, getBBox, getStrokedBBox } from './utilities.js' import { transformListToTransform, transformBox, transformPoint } from './math.js' let svgCanvas let selectorManager_ // A Singleton -const gripRadius = isTouch() ? 10 : 4 +// change radius if touch screen +const gripRadius = window.ontouchstart ? 10 : 4 /** * Private class for DOM element selection boxes. diff --git a/src/svgcanvas/svgcanvas.js b/src/svgcanvas/svgcanvas.js index 6ff17d5a..28572644 100644 --- a/src/svgcanvas/svgcanvas.js +++ b/src/svgcanvas/svgcanvas.js @@ -7,7 +7,6 @@ * @copyright 2010 Alexis Deveria, 2010 Pavol Rusnak, 2010 Jeff Schiller, 2021 OptimistikSAS * */ - import { Canvg as canvg } from 'canvg' import 'pathseg' // SVGPathSeg Polyfill (see https://github.com/progers/pathseg) @@ -17,6 +16,7 @@ import * as draw from './draw.js' import { init as pasteInit, pasteElementsMethod } from './paste-elem.js' +import { init as touchInit } from './touch.js' import { svgRootElement } from './svgroot.js' import { init as undoInit, changeSelectedAttributeNoUndoMethod, @@ -162,6 +162,7 @@ class SvgCanvas { container.append(this.svgroot) // The actual element that represents the final output SVG element. this.svgContent = this.svgdoc.createElementNS(NS.SVG, 'svg') + touchInit(this) clearInit(this) this.clearSvgContentElement() // Current `draw.Drawing` object. diff --git a/src/editor/touch.js b/src/svgcanvas/touch.js similarity index 76% rename from src/editor/touch.js rename to src/svgcanvas/touch.js index b716b8df..2dc37f5c 100644 --- a/src/editor/touch.js +++ b/src/svgcanvas/touch.js @@ -4,7 +4,7 @@ * @param {Event} ev * @returns {void} */ -function touchHandler (ev) { +const touchHandler = (ev) => { const { changedTouches } = ev const first = changedTouches[0] @@ -43,7 +43,9 @@ function touchHandler (ev) { } } -document.addEventListener('touchstart', touchHandler, true) -document.addEventListener('touchmove', touchHandler, true) -document.addEventListener('touchend', touchHandler, true) -document.addEventListener('touchcancel', touchHandler, true) +export const init = (_svgCanvas) => { + document.addEventListener('touchstart', touchHandler, true) + document.addEventListener('touchmove', touchHandler, true) + document.addEventListener('touchend', touchHandler, true) + document.addEventListener('touchcancel', touchHandler, true) +}