Skip to content

Commit 072a63d

Browse files
committed
PB-170: TinyMCE Performance is very poor with multiple instances on Stage
- Fixes for IE 11
1 parent 56e3622 commit 072a63d

File tree

6 files changed

+80
-40
lines changed

6 files changed

+80
-40
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/slide/preview.js

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/text/preview.js

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/utils/editor.js

Lines changed: 30 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/slide/preview.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import {DataObject} from "../../data-store";
1515
import Uploader from "../../uploader";
1616
import delayUntil from "../../utils/delay-until";
1717
import {
18-
createBookmark,
18+
createBookmark, createDoubleClickEvent,
1919
findNodeIndex, getNodeByIndex,
2020
isWysiwygSupported,
2121
lockImageSize,
2222
moveToBookmark,
23-
unlockImageSize
23+
unlockImageSize,
2424
} from "../../utils/editor";
2525
import nestingLinkDialog from "../../utils/nesting-link-dialog";
2626
import WysiwygFactory from "../../wysiwyg/factory";
@@ -222,12 +222,7 @@ export default class Preview extends BasePreview {
222222
}
223223

224224
if (target) {
225-
const dblClickEvent = new MouseEvent("dblclick", {
226-
view: window,
227-
bubbles: true,
228-
cancelable: true,
229-
});
230-
target.dispatchEvent(dblClickEvent);
225+
target.dispatchEvent(createDoubleClickEvent());
231226
}
232227
});
233228
}

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/text/preview.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import HideShowOption from "../../content-type-menu/hide-show-option";
1010
import {OptionsInterface} from "../../content-type-menu/option.types";
1111
import delayUntil from "../../utils/delay-until";
1212
import {
13-
createBookmark,
13+
createBookmark, createDoubleClickEvent,
1414
findNodeIndex, getNodeByIndex,
1515
isWysiwygSupported,
1616
lockImageSize,
@@ -192,12 +192,7 @@ export default class Preview extends BasePreview {
192192
}
193193

194194
if (target) {
195-
const dblClickEvent = new MouseEvent("dblclick", {
196-
view: window,
197-
bubbles: true,
198-
cancelable: true,
199-
});
200-
target.dispatchEvent(dblClickEvent);
195+
target.dispatchEvent(createDoubleClickEvent());
201196
}
202197
});
203198
}

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/utils/editor.ts

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export function convertVariablesToHtmlPreview(content: string) {
3838
return content.replace(/{\{\s?(?:customVar code=|config path=\")([^\}\"]+)[\"]?\s?\}\}/ig, (match, path) => {
3939
const placeholder = document.createElement("span");
4040
placeholder.id = btoa(path).replace(/\+/g, ":").replace(/\//g, "_").replace(/=/g, "-");
41-
placeholder.classList.add("magento-variable", "magento-placeholder", "mceNonEditable");
41+
placeholder.classList.add("magento-variable");
42+
placeholder.classList.add("magento-placeholder");
43+
placeholder.classList.add("mceNonEditable");
4244
if (magentoVariables[path].variable_type === "custom") {
4345
placeholder.classList.add("magento-custom-var");
4446
}
@@ -72,7 +74,9 @@ export function convertWidgetsToHtmlPreview(content: string) {
7274
const placeholder = document.createElement("span");
7375
placeholder.id = mageUtils.uniqueid();
7476
placeholder.contentEditable = "false";
75-
placeholder.classList.add("magento-placeholder", "magento-widget", "mceNonEditable");
77+
placeholder.classList.add("magento-widget");
78+
placeholder.classList.add("magento-placeholder");
79+
placeholder.classList.add("mceNonEditable");
7680

7781
attributes.type = attributes.type.replace(/\\\\/g, "\\");
7882
imageSrc = config.placeholders[attributes.type];
@@ -85,15 +89,15 @@ export function convertWidgetsToHtmlPreview(content: string) {
8589
const image = document.createElement("img");
8690
image.id = btoa(match).replace(/\+/g, ":").replace(/\//g, "_").replace(/=/g, "-");
8791
image.src = imageSrc;
88-
placeholder.append(image);
92+
placeholder.appendChild(image);
8993

9094
let widgetType = "";
9195
if (config.types[attributes.type]) {
9296
widgetType += config.types[attributes.type];
9397
}
9498

9599
const text = document.createTextNode(widgetType);
96-
placeholder.append(text);
100+
placeholder.appendChild(text);
97101

98102
return placeholder.outerHTML;
99103
}
@@ -127,7 +131,7 @@ export function parseAttributesString(attributes: string): { [key: string]: stri
127131
* @param element
128132
*/
129133
export function lockImageSize(element: HTMLElement) {
130-
element.querySelectorAll("img").forEach((image) => {
134+
[].slice.call(element.querySelectorAll("img")).forEach((image: HTMLImageElement) => {
131135
image.style.width = `${image.width}px`;
132136
image.style.height = `${image.height}px`;
133137
});
@@ -139,7 +143,7 @@ export function lockImageSize(element: HTMLElement) {
139143
* @param element
140144
*/
141145
export function unlockImageSize(element: HTMLElement) {
142-
element.querySelectorAll("img").forEach((image) => {
146+
[].slice.call(element.querySelectorAll("img")).forEach((image: HTMLImageElement) => {
143147
image.style.width = null;
144148
image.style.height = null;
145149
});
@@ -256,6 +260,39 @@ export function getNodeByIndex(wrapperElement: HTMLElement, name: string, index:
256260
return $(wrapperElement).find(selector).get(index);
257261
}
258262

263+
/**
264+
* Create a double click event that works in all browsers
265+
*/
266+
export function createDoubleClickEvent(): Event {
267+
try {
268+
return new MouseEvent("dblclick", {
269+
view: window,
270+
bubbles: true,
271+
cancelable: true,
272+
});
273+
} catch (e) {
274+
const dblClickEvent = document.createEvent("MouseEvent");
275+
dblClickEvent.initMouseEvent(
276+
"dblclick",
277+
true,
278+
true,
279+
window,
280+
0,
281+
0,
282+
0,
283+
0,
284+
0,
285+
false,
286+
false,
287+
false,
288+
false,
289+
0,
290+
null,
291+
);
292+
return dblClickEvent;
293+
}
294+
}
295+
259296
/**
260297
* Move the end point of a range to handle tables
261298
*

0 commit comments

Comments
 (0)