Skip to content

Commit bb93831

Browse files
authored
Merge pull request #37 from modxcms/tiny6
Migrate to TinyMCE 6
2 parents 143fc22 + b82b1e5 commit bb93831

File tree

17 files changed

+2841
-7137
lines changed

17 files changed

+2841
-7137
lines changed
Lines changed: 42 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
11
export default class Data {
22
constructor(editor) {
33
this.editor = editor;
4+
window.editor = editor;
45
this.element = editor.dom.getParent(editor.selection.getStart(), 'a[href]');
5-
66
const textarea = document.createElement('textarea');
7-
textarea.innerHTML = editor.selection.getContent();
7+
textarea.innerHTML = this.editor.selection.getContent();
88

99
this.initialData = {
10-
link_text: textarea.value,
10+
link_text: this.editor.selection.getContent(),
1111
link_title: '',
1212
classes: '',
1313
new_window: false,
14-
page: {
15-
page: '',
16-
url: '',
17-
anchor: '',
18-
parameters: ''
19-
},
20-
url: {
21-
url: ''
22-
},
23-
email: {
24-
to: '',
25-
subject: '',
26-
body: ''
27-
},
28-
phone: {
29-
phone: ''
30-
},
31-
file: {
32-
file: ''
33-
}
14+
'page_page': '',
15+
'page_url': '',
16+
'page_anchor': '',
17+
'page_parameters': '',
18+
'url_url': '',
19+
'email_to': '',
20+
'email_subject': '',
21+
'email_body': '',
22+
'phone_phone': '',
23+
'file_file': { value: '', metadata: undefined }
3424
};
3525

36-
this.activeTab = 'page';
26+
this.activeTab = 'url';
3727
this.data = this.parseData();
3828
}
3929

@@ -61,54 +51,34 @@ export default class Data {
6151
this.editor.selection.select(this.element);
6252

6353
const data = {
64-
global: {
65-
link_text: '',
66-
link_title: '',
67-
classes: '',
68-
new_window: false
69-
},
70-
page: {
71-
...(this.initialData.page || {})
72-
},
73-
url: {
74-
...(this.initialData.url || {})
75-
},
76-
email: {
77-
...(this.initialData.email || {})
78-
},
79-
phone: {
80-
...(this.initialData.phone || {})
81-
},
82-
file: {
83-
...(this.initialData.file || {})
84-
}
54+
link_text: this.editor.selection.getContent(),
55+
link_title: '',
56+
classes: '',
57+
new_window: false,
58+
...(this.initialData || {})
59+
8560
};
8661

87-
data.global.link_title = this.element.getAttribute('title');
88-
data.global.classes = this.element.getAttribute('class');
89-
data.global.new_window = (this.element.getAttribute('target') === '_blank');
90-
data.global.link_text = this.element.innerHTML;
62+
data.link_title = this.element.getAttribute('title') ?? '';
63+
data.classes = this.element.getAttribute('class') ?? '';
64+
data.new_window = (this.element.getAttribute('target') === '_blank');
65+
data.link_text = this.element.innerHTML;
9166

9267
const linkType = this.element.dataset.fredLinkType;
93-
let url = this.element.getAttribute('href') || '';
68+
let url = this.element.getAttribute('href') ?? '';
9469

9570
if (linkType === 'page') {
96-
data.page.page = this.element.getAttribute('data-fred-link-page');
97-
data.page.anchor = this.element.getAttribute('data-fred-link-anchor');
98-
data.page.parameters = this.element.getAttribute('data-fred-link-parameters');
71+
data.page_page = this.element.getAttribute('data-fred-link-page') ?? '';
72+
data.page_anchor = this.element.getAttribute('data-fred-link-anchor') ?? '';
73+
data.page_parameters = this.element.getAttribute('data-fred-link-parameters') ?? '';
9974

100-
if (data.page.page || data.page.anchor || data.page.parameters) {
101-
data.page.url = url.replace(('#' + data.page.anchor), '');
102-
data.page.url = data.page.url.replace(('?' + data.page.parameters), '');
75+
if (data.page_page || data.page_anchor || data.page_parameters) {
76+
data.page_url = url.replace(('#' + data.page_anchor), '');
77+
data.page_url = data.page_url.replace(('?' + data.page_parameters), '');
10378

10479
return {
10580
tab: 'page',
106-
data: {
107-
...(data.global),
108-
page: {
109-
...(data.page)
110-
}
111-
}
81+
data,
11282
};
11383
}
11484
}
@@ -118,73 +88,53 @@ export default class Data {
11888
url = url.slice(7);
11989
url = url.split('?');
12090

121-
data.email.to = url[0];
91+
data.email_to = url[0];
12292
if (url[1]) {
12393
const components = url[1].split('&');
12494
components.forEach(component => {
12595
component = component.split('=');
12696
if (component[0] === 'subject') {
127-
data.email.subject = decodeURI(component[1]);
97+
data.email_subject = decodeURI(component[1]);
12898
}
12999

130100
if (component[0] === 'body') {
131-
data.email.body = decodeURI(component[1]);
101+
data.email_body = decodeURI(component[1]);
132102
}
133103
});
134104
}
135105

136106
return {
137107
tab: 'email',
138-
data: {
139-
...(data.global),
140-
email: {
141-
...(data.email)
142-
}
143-
}
108+
data,
144109
}
145110
}
146111
}
147112

148113
if (linkType === 'phone') {
149114
if (url.slice(0, 4) === 'tel:') {
150-
data.phone.phone = url.slice(4);
115+
data.phone_phone = url.slice(4);
151116

152117
return {
153118
tab: 'phone',
154-
data: {
155-
...(data.global),
156-
phone: {
157-
...(data.phone)
158-
}
159-
}
119+
data,
160120
}
161121
}
162122
}
163123

164124
if (linkType === 'file') {
165-
data.file.file = url;
125+
data.file_file = { value: url, metadata: undefined };
166126

167127
return {
168128
tab: 'file',
169-
data: {
170-
...(data.global),
171-
file: {
172-
...(data.file)
173-
}
174-
}
129+
data,
175130
}
176131
}
177132

178-
data.url.url = url;
133+
data.url_url = url;
179134

180135
return {
181136
tab: 'url',
182-
data: {
183-
...(data.global),
184-
url: {
185-
...(data.url)
186-
}
187-
}
137+
data,
188138
};
189139
}
190140
}

_build/assets/js/Plugins/modxlink/Link.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,47 +51,47 @@ export default class Link {
5151
}
5252

5353
savePage(data) {
54-
if (!data.page.page && !data.page.anchor && !data.page.parameters) return;
54+
if (!data.page_page && !data.page_anchor && !data.page_parameters) return;
5555

5656
const attributes = {
5757
...(Link.getGeneralAttributes(data, 'page')),
58-
'data-fred-link-page': data.page.page
58+
'data-fred-link-page': data.page_page
5959
};
60-
attributes.href = data.page.url;
60+
attributes.href = data.page_url;
6161

62-
if (data.page.anchor) {
63-
attributes['data-fred-link-anchor'] = data.page.anchor;
64-
attributes.href = `${data.page.url}#${data.page.anchor}`;
62+
if (data.page_anchor) {
63+
attributes['data-fred-link-anchor'] = data.page_anchor;
64+
attributes.href = `${data.page_url}#${data.page_anchor}`;
6565
}
66-
if (data.page.parameters) {
67-
attributes['data-fred-link-parameters'] = data.page.parameters;
68-
attributes.href = `${attributes.href}?${data.page.parameters}`;
66+
if (data.page_parameters) {
67+
attributes['data-fred-link-parameters'] = data.page_parameters;
68+
attributes.href = `${attributes.href}?${data.page_parameters}`;
6969
}
7070

7171
return this.handleLink(data.link_text, attributes);
7272
}
7373

7474
saveUrl(data) {
75-
if (!data.url.url) return;
75+
if (!data.url_url) return;
7676

7777
return this.handleLink(data.link_text, {
7878
...(Link.getGeneralAttributes(data, 'url')),
79-
href: data.url.url
79+
href: data.url_url
8080
});
8181
}
8282

8383
saveEmail(data) {
84-
if (!data.email.to) return;
84+
if (!data.email_to) return;
8585

86-
let href = `mailto:${data.email.to}`;
86+
let href = `mailto:${data.email_to}`;
8787
const mailAttrs = [];
8888

89-
if (data.email.subject) {
90-
mailAttrs.push('subject=' + encodeURI(data.email.subject));
89+
if (data.email_subject) {
90+
mailAttrs.push('subject=' + encodeURI(data.email_subject));
9191
}
9292

93-
if (data.email.body) {
94-
mailAttrs.push('body=' + encodeURI(data.email.body));
93+
if (data.email_body) {
94+
mailAttrs.push('body=' + encodeURI(data.email_body));
9595
}
9696

9797
if (mailAttrs.length > 0) {
@@ -105,20 +105,20 @@ export default class Link {
105105
}
106106

107107
savePhone(data) {
108-
if (!data.phone.phone) return;
108+
if (!data.phone_phone) return;
109109

110110
return this.handleLink(data.link_text, {
111111
...(Link.getGeneralAttributes(data, 'phone')),
112-
href: `tel:${data.phone.phone}`
112+
href: `tel:${data.phone_phone}`
113113
});
114114
}
115115

116116
saveFile(data) {
117-
if (!data.file.file) return;
117+
if (!data.file_file) return;
118118

119119
return this.handleLink(data.link_text, {
120120
...(Link.getGeneralAttributes(data, 'file')),
121-
href: data.file.file
121+
href: data.file_file.value
122122
});
123123
}
124124

0 commit comments

Comments
 (0)