Skip to content

Commit

Permalink
ENH Refactor sslink slightly for easier maintenance (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jan 25, 2024
1 parent 20dbe25 commit c16fb0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 17 additions & 22 deletions client/src/legacy/TinyMCE_sslink.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ const plugin = {
* @param {Object} editor
*/
init(editor) {
function getActions() {
// Fetch the actions whenever the fetch function is called.
return TinyMCEActionRegistrar.getSortedActions('sslink', editor.getParam('editorIdentifier'), true)
.map(action => Object.assign(
{},
action,
{ onAction: () => action.onAction(editor) }
));
}

const metaKey = navigator.platform.toUpperCase().includes('MAC') ? '⌘' : 'Ctrl';
const title = i18n._t('Admin.INSERT_LINK', 'Insert link');
const titleWithShortcut = i18n.inject(
Expand All @@ -33,33 +43,18 @@ const plugin = {
}
}

// Button in main toolbar
editor.ui.registry.addMenuButton('sslink', {
icon: 'link',
tooltip: titleWithShortcut,
fetch: (callback) => callback(
// Fetch the actions whenever the fetch function is called.
TinyMCEActionRegistrar.getSortedActions('sslink', editor.getParam('editorIdentifier'), true)
.map(action => Object.assign(
{},
action,
{ onAction: () => action.onAction(editor) }
))
),
fetch: (callback) => callback(getActions()),
});

editor.on('preinit', () => {
// Right click context menu item
editor.ui.registry.addNestedMenuItem('sslink', {
icon: 'link',
text: title,
getSubmenuItems: () => // Fetch the actions whenever the fetch function is called.
TinyMCEActionRegistrar.getSortedActions('sslink', editor.getParam('editorIdentifier'), true)
.map(action => Object.assign(
{},
action,
{ onAction: () => action.onAction(editor) }
)),
});
// Right click context menu item
editor.ui.registry.addNestedMenuItem('sslink', {
icon: 'link',
text: title,
getSubmenuItems: getActions,
});

// Context menu when a link is selected
Expand Down

0 comments on commit c16fb0f

Please sign in to comment.