Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit 5ae410c

Browse files
author
steven.roulleau
committed
fix(examples): wait editor to be initialized
1 parent aff1628 commit 5ae410c

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

examples/v4/multiple_inputs.js

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -116,50 +116,54 @@ function addIdleListeners(editors) {
116116
function addInputsPointerDownListener(inputId) {
117117
const input = document.getElementById(inputId);
118118
input.addEventListener('pointerdown', (event) => {
119-
pointerDownOnInput = true;
120-
pointerDownOnInputPoint = extractPoint(event, input, editorElementRef.editor.configuration);
121-
if (selectedInput !== input) {
122-
if (editorElementRef) {
123-
if (selectedInput) {
124-
oldInput = selectedInput;
125-
editorElementRef.editor.convert();
126-
editorElementRef.editor.waitForIdle();
127-
waitingForIdle = true;
119+
if (editorElementRef.editor.initialized) {
120+
pointerDownOnInput = true;
121+
pointerDownOnInputPoint = extractPoint(event, input, editorElementRef.editor.configuration);
122+
if (selectedInput !== input) {
123+
if (editorElementRef) {
124+
if (selectedInput) {
125+
oldInput = selectedInput;
126+
editorElementRef.editor.convert();
127+
editorElementRef.editor.waitForIdle();
128+
waitingForIdle = true;
129+
}
128130
}
131+
clearForIdle = false;
132+
selectedEditor === 0 ? editorElementRef = editorElement : editorElementRef = editorElement2;
133+
selectedInput = input;
134+
editorElementRef.style.width = `${event.target.clientWidth}px`;
135+
editorElementRef.style.height = `${event.target.clientHeight}px`;
136+
editorElementRef.style.display = 'block';
137+
editorElementRef.style.position = 'absolute';
138+
editorElementRef.style.left = `${event.target.tagName === 'svg' ? event.target.parentElement.offsetLeft + 1 : event.target.offsetLeft + 1}px`;
139+
editorElementRef.style.top = `${event.target.tagName === 'svg' ? event.target.parentElement.offsetTop + 1 : event.target.offsetTop + 1}px`;
140+
editorElementRef.style.background = 'white';
141+
const inputValue = inputValues.get(selectedInput.id);
142+
if (inputValue) {
143+
editorElementRef.editor.import_(inputValue, 'text/plain');
144+
}
145+
editorElementRef.editor.resize();
146+
selectedEditor === 0 ? selectedEditor = 1 : selectedEditor = 0;
129147
}
130-
clearForIdle = false;
131-
selectedEditor === 0 ? editorElementRef = editorElement : editorElementRef = editorElement2;
132-
selectedInput = input;
133-
editorElementRef.style.width = `${event.target.clientWidth}px`;
134-
editorElementRef.style.height = `${event.target.clientHeight}px`;
135-
editorElementRef.style.display = 'block';
136-
editorElementRef.style.position = 'absolute';
137-
editorElementRef.style.left = `${event.target.tagName === 'svg' ? event.target.parentElement.offsetLeft + 1 : event.target.offsetLeft + 1}px`;
138-
editorElementRef.style.top = `${event.target.tagName === 'svg' ? event.target.parentElement.offsetTop + 1 : event.target.offsetTop + 1}px`;
139-
editorElementRef.style.background = 'white';
140-
const inputValue = inputValues.get(selectedInput.id);
141-
if (inputValue) {
142-
editorElementRef.editor.import_(inputValue, 'text/plain');
143-
}
144-
editorElementRef.editor.resize();
145-
selectedEditor === 0 ? selectedEditor = 1 : selectedEditor = 0;
146148
}
147149
});
148150
input.addEventListener('pointermove', (event) => { // Trigger a pointerMove
149-
if (this.activePointerId && this.activePointerId === event.pointerId) {
150-
editorElementRef.editor.pointerMove(extractPoint(event, editorElementRef.editor.domElement, editorElementRef.editor.configuration));
151-
} else if (pointerDownOnInput) {
152-
const point = extractPoint(event, editorElementRef.editor.domElement, editorElementRef.editor.configuration);
153-
const diffX = Math.abs(pointerDownOnInputPoint.x - point.x);
154-
const diffY = Math.abs(pointerDownOnInputPoint.y - point.y);
155-
// mMaxDiffX = Math.max(diffX, mMaxDiffX);
156-
const cond1 = diffX < 1 && diffY > 1; // && mMaxDiffX < 15;
157-
const cond2 = diffX > 1 && diffY > 1; // && mMaxDiffX < 15;
158-
if (cond1 || cond2) {
159-
this.activePointerId = event.pointerId;
160-
// Hack for iOS 9 Safari : pointerId has to be int so -1 if > max value
161-
const pointerId = event.pointerId > 2147483647 ? -1 : event.pointerId;
162-
editorElementRef.editor.pointerDown(pointerDownOnInputPoint, event.pointerType, pointerId);
151+
if (editorElementRef.editor.initialized) {
152+
if (this.activePointerId && this.activePointerId === event.pointerId) {
153+
editorElementRef.editor.pointerMove(extractPoint(event, editorElementRef.editor.domElement, editorElementRef.editor.configuration));
154+
} else if (pointerDownOnInput) {
155+
const point = extractPoint(event, editorElementRef.editor.domElement, editorElementRef.editor.configuration);
156+
const diffX = Math.abs(pointerDownOnInputPoint.x - point.x);
157+
const diffY = Math.abs(pointerDownOnInputPoint.y - point.y);
158+
// mMaxDiffX = Math.max(diffX, mMaxDiffX);
159+
const cond1 = diffX < 1 && diffY > 1; // && mMaxDiffX < 15;
160+
const cond2 = diffX > 1 && diffY > 1; // && mMaxDiffX < 15;
161+
if (cond1 || cond2) {
162+
this.activePointerId = event.pointerId;
163+
// Hack for iOS 9 Safari : pointerId has to be int so -1 if > max value
164+
const pointerId = event.pointerId > 2147483647 ? -1 : event.pointerId;
165+
editorElementRef.editor.pointerDown(pointerDownOnInputPoint, event.pointerType, pointerId);
166+
}
163167
}
164168
}
165169
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy