Skip to content

Commit c16fb0f

Browse files
ENH Refactor sslink slightly for easier maintenance (#1661)
1 parent 20dbe25 commit c16fb0f

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

client/dist/js/TinyMCE_sslink.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/legacy/TinyMCE_sslink.js

+17-22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ const plugin = {
1111
* @param {Object} editor
1212
*/
1313
init(editor) {
14+
function getActions() {
15+
// Fetch the actions whenever the fetch function is called.
16+
return TinyMCEActionRegistrar.getSortedActions('sslink', editor.getParam('editorIdentifier'), true)
17+
.map(action => Object.assign(
18+
{},
19+
action,
20+
{ onAction: () => action.onAction(editor) }
21+
));
22+
}
23+
1424
const metaKey = navigator.platform.toUpperCase().includes('MAC') ? '⌘' : 'Ctrl';
1525
const title = i18n._t('Admin.INSERT_LINK', 'Insert link');
1626
const titleWithShortcut = i18n.inject(
@@ -33,33 +43,18 @@ const plugin = {
3343
}
3444
}
3545

46+
// Button in main toolbar
3647
editor.ui.registry.addMenuButton('sslink', {
3748
icon: 'link',
3849
tooltip: titleWithShortcut,
39-
fetch: (callback) => callback(
40-
// Fetch the actions whenever the fetch function is called.
41-
TinyMCEActionRegistrar.getSortedActions('sslink', editor.getParam('editorIdentifier'), true)
42-
.map(action => Object.assign(
43-
{},
44-
action,
45-
{ onAction: () => action.onAction(editor) }
46-
))
47-
),
50+
fetch: (callback) => callback(getActions()),
4851
});
4952

50-
editor.on('preinit', () => {
51-
// Right click context menu item
52-
editor.ui.registry.addNestedMenuItem('sslink', {
53-
icon: 'link',
54-
text: title,
55-
getSubmenuItems: () => // Fetch the actions whenever the fetch function is called.
56-
TinyMCEActionRegistrar.getSortedActions('sslink', editor.getParam('editorIdentifier'), true)
57-
.map(action => Object.assign(
58-
{},
59-
action,
60-
{ onAction: () => action.onAction(editor) }
61-
)),
62-
});
53+
// Right click context menu item
54+
editor.ui.registry.addNestedMenuItem('sslink', {
55+
icon: 'link',
56+
text: title,
57+
getSubmenuItems: getActions,
6358
});
6459

6560
// Context menu when a link is selected

0 commit comments

Comments
 (0)