Skip to content

Commit 88662ab

Browse files
author
Hwashiang Yu
committed
MC-5386: Anchors Under Each Div if TinyMCE link Is Added to Banner/Slide (Add Notification for When Link Attribute Is Entered)
- Updated validator rule mixin file for syntax issue - Moved nesting link dialog logic to it's own utility file.
1 parent ceaee98 commit 88662ab

File tree

7 files changed

+99
-94
lines changed

7 files changed

+99
-94
lines changed

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

Lines changed: 2 additions & 22 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/slide/preview.js

Lines changed: 2 additions & 22 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/form/element/validator-rules-mixin.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ define([
4040
* @return {Boolean}
4141
*/
4242
function validateIsUrl(href) {
43-
4443
return (/^(http|https|ftp):\/\/(([A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))(\.[A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))*)(:(\d+))?(\/[A-Z0-9~](([A-Z0-9_~-]|\.)*[A-Z0-9~]|))*\/?(.*)?$/i).test(href);//eslint-disable-line max-len
4544
}
4645

@@ -50,7 +49,6 @@ define([
5049
* @return {Boolean}
5150
*/
5251
function validateWysiwygHasAnchorTags(str) {
53-
5452
return (/<a[\s]+([^>]+)>|<a>|<\/a>/igm).test(str);
5553
}
5654

@@ -61,7 +59,6 @@ define([
6159
* @return {Boolean}
6260
*/
6361
function validateOneAnchorTagField(message, url) {
64-
6562
return !(validateWysiwygHasAnchorTags(message) &&
6663
['page', 'product', 'category', 'default'].indexOf(url.type) !== -1 &&
6764
url[url.type] &&

app/code/Magento/PageBuilder/view/adminhtml/web/js/utils/nesting-link-dialog.js

Lines changed: 42 additions & 0 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/banner/preview.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
import $ from "jquery";
77
import $t from "mage/translate";
88
import events from "Magento_PageBuilder/js/events";
9-
import confirmationDialog from "Magento_PageBuilder/js/modal/dismissible-confirm";
109
import Config from "../../config";
1110
import HideShowOption from "../../content-type-menu/hide-show-option";
1211
import {OptionsInterface} from "../../content-type-menu/option.d";
1312
import {DataObject} from "../../data-store";
14-
import FieldDefaultsInterface from "../../field-defaults.d";
1513
import Uploader from "../../uploader";
14+
import nestingLinkDialog from "../../utils/nesting-link-dialog";
1615
import WysiwygFactory from "../../wysiwyg/factory";
1716
import WysiwygInterface from "../../wysiwyg/wysiwyg-interface";
1817
import BasePreview from "../preview";
@@ -245,28 +244,7 @@ export default class Preview extends BasePreview {
245244
const dataStore = this.parent.dataStore.get() as DataObject;
246245
const imageObject = dataStore[this.config.additional_data.uploaderConfig.dataScope][0] || {};
247246
events.trigger(`image:${this.parent.id}:assignAfter`, imageObject);
248-
const message = dataStore.message as string;
249-
const linkUrl = dataStore.link_url as FieldDefaultsInterface;
250-
const aLinkRegex = /<a[\s]+([^>]+)>|<a>|<\/a>/igm;
251-
if (message.match(aLinkRegex) &&
252-
dataStore.link_url &&
253-
["page", "product", "category", "default"].indexOf(linkUrl.type) !== -1 &&
254-
linkUrl[linkUrl.type] &&
255-
linkUrl[linkUrl.type].length !== 0) {
256-
confirmationDialog({
257-
actions: {
258-
always: () => {
259-
const anchorLessMessage = message.replace(aLinkRegex, "");
260-
this.parent.dataStore.update(anchorLessMessage, "message");
261-
$("#" + this.wysiwyg.elementId).html(anchorLessMessage);
262-
},
263-
264-
},
265-
content: $t("Adding link in content and outer element is not allowed. Remove the link from the element before adding links to the content."), // tslint:disable-line:max-line-length
266-
title: $t("Nesting links are not allowed"),
267-
haveCancelButton: false,
268-
});
269-
}
247+
nestingLinkDialog(this.parent.dataStore, this.wysiwyg, "message", "link_url");
270248
});
271249
}
272250

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
import $ from "jquery";
77
import $t from "mage/translate";
88
import events from "Magento_PageBuilder/js/events";
9-
import confirmationDialog from "Magento_PageBuilder/js/modal/dismissible-confirm";
109
import _ from "underscore";
1110
import {PreviewSortableSortUpdateEventParams} from "../../binding/sortable-children";
1211
import Config from "../../config";
1312
import ConditionalRemoveOption from "../../content-type-menu/conditional-remove-option";
1413
import {OptionsInterface} from "../../content-type-menu/option.d";
1514
import {DataObject} from "../../data-store";
16-
import FieldDefaultsInterface from "../../field-defaults";
1715
import Uploader from "../../uploader";
1816
import delayUntil from "../../utils/delay-until";
17+
import nestingLinkDialog from "../../utils/nesting-link-dialog";
1918
import WysiwygFactory from "../../wysiwyg/factory";
2019
import WysiwygInterface from "../../wysiwyg/wysiwyg-interface";
2120
import ContentTypeMountEventParamsInterface from "../content-type-mount-event-params";
@@ -288,27 +287,7 @@ export default class Preview extends BasePreview {
288287
const dataStore = this.parent.dataStore.get() as DataObject;
289288
const imageObject = dataStore[this.config.additional_data.uploaderConfig.dataScope][0] || {};
290289
events.trigger(`image:${this.parent.id}:assignAfter`, imageObject);
291-
const content = dataStore.content as string;
292-
const linkUrl = dataStore.link_url as FieldDefaultsInterface;
293-
const aLinkRegex = /<a[\s]+([^>]+)>|<a>|<\/a>/igm;
294-
if (content.match(aLinkRegex) &&
295-
dataStore.link_url &&
296-
["page", "product", "category", "default"].indexOf(linkUrl.type) !== -1 &&
297-
linkUrl[linkUrl.type] &&
298-
linkUrl[linkUrl.type].length !== 0) {
299-
confirmationDialog({
300-
actions: {
301-
always: () => {
302-
const anchorLessMessage = content.replace(aLinkRegex, "");
303-
this.parent.dataStore.update(anchorLessMessage, "content");
304-
$("#" + this.wysiwyg.elementId).html(anchorLessMessage);
305-
},
306-
},
307-
content: $t("Adding link in content and outer element is not allowed. Remove the link from the element before adding links to the content."), // tslint:disable-line:max-line-length
308-
title: $t("Nesting links are not allowed"),
309-
haveCancelButton: false,
310-
});
311-
}
290+
nestingLinkDialog(this.parent.dataStore, this.wysiwyg, "content", "link_url");
312291
});
313292

314293
// Remove wysiwyg before assign new instance.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
import $ from "jquery";
7+
import $t from "mage/translate";
8+
import confirmationDialog from "Magento_PageBuilder/js/modal/dismissible-confirm";
9+
import DataStore, {DataObject} from "../data-store";
10+
import FieldDefaultsInterface from "../field-defaults";
11+
import WysiwygInterface from "../wysiwyg/wysiwyg-interface";
12+
13+
/**
14+
* Validate inline editor for having nested link
15+
* Creates a dialog and removes inline editor link if present
16+
*
17+
* @param {DataObject} dataStore
18+
* @param {WysiwygInterface} wysiwyg
19+
* @param {string} inlineMessageField
20+
* @param {string} linkUrlField
21+
*/
22+
export default function nestingLinkDialog(
23+
dataStore: DataStore,
24+
wysiwyg: WysiwygInterface,
25+
inlineMessageField: string,
26+
linkUrlField: string) {
27+
const dataStoreContent = dataStore.get() as DataObject;
28+
const inlineMessage = dataStoreContent[inlineMessageField] as string;
29+
const linkUrl = dataStoreContent[linkUrlField] as FieldDefaultsInterface;
30+
const aLinkRegex = /<a[\s]+([^>]+)>|<a>|<\/a>/igm;
31+
if (inlineMessage.match(aLinkRegex) &&
32+
linkUrl &&
33+
["page", "product", "category", "default"].indexOf(linkUrl.type) !== -1 &&
34+
linkUrl[linkUrl.type] &&
35+
linkUrl[linkUrl.type].length !== 0) {
36+
confirmationDialog({
37+
actions: {
38+
always: () => {
39+
const anchorLessInlineMessage = inlineMessage.replace(aLinkRegex, "");
40+
dataStore.update(anchorLessInlineMessage, inlineMessageField);
41+
$("#" + wysiwyg.elementId).html(anchorLessInlineMessage);
42+
},
43+
},
44+
content: $t("Adding link in content and outer element is not allowed. Remove the link from the element before adding links to the content."), // tslint:disable-line:max-line-length
45+
title: $t("Nesting links are not allowed"),
46+
haveCancelButton: false,
47+
});
48+
}
49+
}

0 commit comments

Comments
 (0)