Sean and anyone else that stumbles across this Q & A!
I finally figured out how to extend the Medium editor in Kentico 12 SP. Thanks very much to your answers above Sean, they led me to the correct setup. Here are my steps:
- Add the java script file for the Medium editor extension to the folder where medium-editor.js is located. In my case, I used the Text Widget right out of the Kentico documentation examples, so it's located in /Content/InlineEditors/TextEditor/medium-editor/js/medium-editor.js
-
At the top of the text-editor.js file, add a reference to the Medium Button extension like so:
MediumButton = window['MediumButton'];
-
In the buttons string array, add the name of the button that you want to add. In my case, it was just like Sean's above, "smallButton"
buttons: ["bold", "italic", "underline", "orderedlist", "unorderedlist", "h1", "h2", "h3", "h4", "justifyLeft", "justifyCenter", "justifyRight", "smallButton"]
-
In the extensions section, initialize the new button w/ the correct properties:
extensions: {
imageDragging: {},
smallButton: new MediumButton({
label: 'SM',
start: ''
})
}
NOTE: The button name has to match what you put in the string array, otherwise the button will not show up on the toolbar.
- Push your code to your site and that's it! The "SM" button should now appear on your toolbar!
I've included the entire code snippet that goes inside the opening function in the text-editor.js file that I'm using so that everyone can see how all the pieces come together:
window.kentico.pageBuilder.registerInlineEditor("text-editor", {
init: function (options) {
var editor = options.editor;
MediumButton = window['MediumButton'];
var config = {
toolbar: {
buttons: ["bold", "italic", "underline", "orderedlist", "unorderedlist", "h1", "h2", "h3", "h4", "justifyLeft", "justifyCenter", "justifyRight", "smallButton"]
},
imageDragging: false,
extensions: {
imageDragging: {},
smallButton: new MediumButton({
label: '<b>SM</b>',
start: '<small>',
end: '</small>'
})
}
};
if (editor.dataset.enableFormatting === "False") {
config.toolbar = false;
config.keyboardCommands = false;
}
var mediumEditor = new MediumEditor(editor, config);
mediumEditor.subscribe("editableInput", function () {
var event = new CustomEvent("updateProperty", {
detail: {
name: options.propertyName,
value: mediumEditor.getContent(),
refreshMarkup: false
}
});
editor.dispatchEvent(event);
});
},
destroy: function (options) {
var mediumEditor = MediumEditor.getEditorFromElement(options.editor);
if (mediumEditor) {
mediumEditor.destroy();
}
},
dragStart: function (options) {
var mediumEditor = MediumEditor.getEditorFromElement(options.editor);
var focusedElement = mediumEditor && mediumEditor.getFocusedElement();
var focusedMediumEditor = focusedElement && MediumEditor.getEditorFromElement(focusedElement);
var toolbar = focusedMediumEditor && focusedMediumEditor.getExtensionByName("toolbar");
if (focusedElement && toolbar) {
toolbar.hideToolbar();
focusedElement.removeAttribute("data-medium-focused");
}
}
});
})