UPGRADE-5.md
Version 5.0.0 of MediumEditor introduces a significantly simpler system for building custom extensions as well as extending existing buttons and extensions. As part of moving towards this extendable model, there were significant changes to the way options are passed to MediumEditor, as well as the extensions and buttons themselves.
In addition to extension related changes, there were several other potential breaking changes related to API methods, as well as utility helper methods.
For details on all the currently supported MediumEditor options, refer to the Medium Editor Options Wiki Page.
'toolbar' object inside the outer options object.
buttons -> toolbar.buttonstoolbarAlign -> toolbar.aligndiffTop -> toolbar.diffTopdiffLeft -> toolbar.diffLeftstaticToolbar -> toolbar.staticstickyToolbar -> toolbar.stickyfirstButtonClass -> toolbar.firstButtonClasslastButtonClass -> toolbar.lastButtonClassupdateOnEmptySelection -> toolbar.updateOnEmptySelectionstandardizeSelectionStart -> toolbar.standardizeSelectionStart'anchor' object inside the outer options object.
anchorInputPlaceholder -> anchor.placeholderTextcheckLinkFormat -> anchor.linkValidationanchorButton & anchorButtonClass -> anchor.customClassOptionanchorTarget -> anchor.targetCheckboxanchorInputCheckboxLabel -> anchor.targetCheckboxText'anchorPreview' object inside the outer options object.
anchorPreviewHideDelay -> anchorPreview.hideDelay'paste' object inside the outer options object.
forcePlainText -> paste.forcePlainTextcleanPastedHTML -> paste.cleanPastedHTML'placeholder' object inside the outer options object.
placeholder -> placeholder.textdisableToolbartoolbar option to falsedisableAnchorPreviewanchorPreview option to falsedisablePlaceholdersplaceholder option to falseonShowToolbar & onHideToolbaronShowToolbar and onHideToolbar options are no longer supported. Instead, attach to the 'showToolbar' and 'hideToolbar' custom events via MediumEditor.subscribe()firstHeader & secondHeaderfirstHeader & secondHeader options have been removed. Instead, any number of the 6 header types can be passed as button names into the toolbar.buttons option array.
firstHeader: 'h2' and secondHeader: 'h3', it should now pass ['bold', 'italic', 'quote', 'h2', 'h3'] via the toolbar.buttons property of the MediumEditor options object.buttonLabelsbuttonLabels option no longer supports taking an object in that specifies custom labels for all buttons. Instead, pass an object into the toolbar.buttons option array that contains a .name property for the name of the button, a either a contentDefault or a contentFA property that should be in the innerHTML of the button (for default of fontawesome buttonLabels respectively).parentExtension.parent is no longer supported. All extensions will have a reference to the MediumEditor instance via their .base property, unless the property already exists..init()Extension.init() will no longer be passed any arguments. Previously, .init(instance) received an instance of MediumEditor as an argument, but this is not needed now that .base will be populated before .init() is called..deactivate()Extension.deactivate() will no longer be called by MediumEditor. .destroy() will be called instead when MediumEditor is destroyed..options.options property of any built-in extensions or buttons has been removed. All of the properties should be retrieved and set from the prototype of the object itself.
this.options.action, they should now use this.action..options property..id.destroy() and .setup(), the id will remain the same. This id was used to generate unique element ids for things like the id attribute of the toolbar element ('medium-editor-toolbar-[ID]').toolbarMediumEditor.toolbar is no longer a valid reference. Use MediumEditor.getExtensionByName('toolbar') instead..statics.statics references have been removed as the new style of extensions and buttons has been introduced. The objects exposed via .statics have also been changed, so code which uses them may require additonal changes.
MediumEditor.statics.ButtonsData -> MediumEditor.extensions.button.prototype.defaults (ideally this reference should no longer be needed)MediumEditor.statics.DefaultButton -> MediumEditor.extensions.buttonMediumEditor.statics.AnchorExtension -> MediumEditor.extensions.anchorMediumEditor.statics.FontSizeExtension -> MediumEditor.extensions.fontSizeMediumEditor.statics.Toolbar -> MediumEditor.extensions.toolbarMediumEditor.statics.AnchorPreview -> MediumEditor.extensions.anchorPreview.activate()MediumEditor.activate() has been replaced with MediumEditor.setup().deactivate()MediumEditor.deactivate() has been replaced with MediumEditor.destroy().createEvent()MediumEditor.createEvent() is no longer needed in order to fire custom events. It has been removed..hideToolbarDefaultActions()MediumEditor.hideToolbarDefaultActions() has been removed. Use the hideToolbarDefaultActions() method of the toolbar extension instead..setToolbarPosition()MediumEditor.setToolbarPosition() has been removed. Use the setToolbarPosition() method of the toolbar extension instead..callExtensions()MediumEditor.callExtensions() has been removed and is no longer supported.MediumEditor.util.getSelectionRange() has been moved to MediumEditor.selection.getSelectionRange()MediumEditor.util.getSelectionStart() has been moved to MediumEditor.selection.getSelectionStart()MediumEditor.util.unwrapElement() has been removed. Use MediumEditor.util.unwrap() insteadMediumEditor.util.getSelectionData() has been removedMediumEditor.util.setObject() has been removedMediumEditor.util.getObject() has been removedMediumEditor.util.derives() has been removed. Objects that can be drived from (like extensions and buttons) will have a .extend() method for extending.MediumEditor.util.now() has been removed. Use Date.now() instead.MediumEditor.util.parentElements has been renamed MediumEditor.util.blockContainerElementNamesMediumEditor.selection.getSelectionData() has been removed.clearfix class has been removed, and .clearfix class is no longer added to the toolbar element.'medium' in CSS classes has been replaced with 'medium-editor'
medium-editor-image-loading class on instead of medium-image-loadingdata-medium-element attribute on all MediumEditor elements has been renamed to data-medium-editor-elementsticky-toolbar and static-toolbar have been renamed medium-editor-sticky-toolbar and medium-editor-static-toolbar respectivelygetFocusedElement() method of the toolbar extension has been removed. Use MediumEditor.getFocusedElement() instead..key option on buttons is not longer supported for mapping keyboard shortcuts.