diff --git a/src/svgcanvas/paste-elem.js b/src/svgcanvas/paste-elem.js index 50449f96..b6725c0c 100644 --- a/src/svgcanvas/paste-elem.js +++ b/src/svgcanvas/paste-elem.js @@ -28,7 +28,7 @@ export const init = function (canvas) { * @returns {void} */ export const pasteElementsMethod = function (type, x, y) { - let clipb = JSON.parse(sessionStorage.getItem(svgCanvas.getClipBoardID())); + let clipb = JSON.parse(sessionStorage.getItem(svgCanvas.getClipboardID())); if (!clipb) return; let len = clipb.length; if (!len) return; diff --git a/src/svgcanvas/select.js b/src/svgcanvas/select.js index f0b188c8..893383f8 100644 --- a/src/svgcanvas/select.js +++ b/src/svgcanvas/select.js @@ -11,7 +11,6 @@ import { getRotationAngle, getBBox, getStrokedBBox, isNullish } from './utilitie import { transformListToTransform, transformBox, transformPoint } from './math.js'; let svgCanvas; -let config_; let selectorManager_; // A Singleton const gripRadius = isTouch() ? 10 : 4; @@ -364,7 +363,7 @@ export class SelectorManager { r: gripRadius, stroke: '#22C', 'stroke-width': 2, - style: `cursor:url(${config_.imgPath}/rotate.svg) 12 12, auto;` + style: `cursor:url(${this.curConfig.imgPath}/rotate.svg) 12 12, auto;` } }); this.selectorGripsGroup.append(this.rotateGrip); @@ -372,7 +371,7 @@ export class SelectorManager { if (document.getElementById('canvasBackground')) { return; } - const [ width, height ] = config_.dimensions; + const [ width, height ] = this.curConfig.dimensions; const canvasbg = svgCanvas.createSVGElement({ element: 'svg', attr: { @@ -531,8 +530,7 @@ export class SelectorManager { * @param {module:select.SVGFactory} svgFactory - An object implementing the SVGFactory interface. * @returns {void} */ -export const init = function (config, canvas) { - config_ = config; +export const init = (canvas) => { svgCanvas = canvas; selectorManager_ = new SelectorManager(); }; diff --git a/src/svgcanvas/svgcanvas.js b/src/svgcanvas/svgcanvas.js index 8395bcf9..3258b678 100644 --- a/src/svgcanvas/svgcanvas.js +++ b/src/svgcanvas/svgcanvas.js @@ -218,7 +218,7 @@ class SvgCanvas { utilsInit(this); coordsInit(this); recalculateInit(this); - selectInit(this.curConfig, this); + selectInit(this); undoInit(this); selectionInit(this); @@ -267,34 +267,23 @@ class SvgCanvas { blurInit(this); selectedElemInit(this); - /** -* Flash the clipboard data momentarily on localStorage so all tabs can see. -* @returns {void} -*/ - function flashStorage() { - const data = sessionStorage.getItem(CLIPBOARD_ID); - localStorage.setItem(CLIPBOARD_ID, data); - setTimeout(function () { - localStorage.removeItem(CLIPBOARD_ID); - }, 1); - } /** * Transfers sessionStorage from one tab to another. * @param {!Event} ev Storage event. * @returns {void} */ - function storageChange(ev) { + const storageChange = (ev) => { if (!ev.newValue) return; // This is a call from removeItem. if (ev.key === CLIPBOARD_ID + '_startup') { // Another tab asked for our sessionStorage. localStorage.removeItem(CLIPBOARD_ID + '_startup'); - flashStorage(); + this.flashStorage(); } else if (ev.key === CLIPBOARD_ID) { // Another tab sent data. sessionStorage.setItem(CLIPBOARD_ID, ev.newValue); } - } + }; // Listen for changes to localStorage. window.addEventListener('storage', storageChange, false); @@ -418,6 +407,7 @@ class SvgCanvas { setInitBbox(value) { this.initBbox = value; } setRootSctm(value) { this.rootSctm = value; } setCurrentResizeMode(value) { this.currentResizeMode = value; } + getLastClickPoint(key) { return this.lastClickPoint[key]; } setLastClickPoint(value) { this.lastClickPoint = value; } getId() { return this.getCurrentDrawing().getId(); } getUIStrings() { return this.uiStrings; } @@ -557,6 +547,17 @@ class SvgCanvas { return old; } /** +* Flash the clipboard data momentarily on localStorage so all tabs can see. +* @returns {void} +*/ + flashStorage() { + const data = sessionStorage.getItem(CLIPBOARD_ID); + localStorage.setItem(CLIPBOARD_ID, data); + setTimeout(function () { + localStorage.removeItem(CLIPBOARD_ID); + }, 1); + } + /** * Selects only the given elements, shortcut for `clearSelection(); addToSelection()`. * @function module:svgcanvas.SvgCanvas#selectOnly * @param {Element[]} elems - an array of DOM elements to be selected