diff --git a/behaviors/wysiwyg.js b/behaviors/wysiwyg.js index 6048e9fa1..184aae78d 100644 --- a/behaviors/wysiwyg.js +++ b/behaviors/wysiwyg.js @@ -377,6 +377,17 @@ module.exports = function (result, args) { // put the rich text field after the input dom.replaceElement(textInput, field); + /** + * match extension names when instantiating medium-editor + * @param {string} extname e.g. 'italic' + * @returns {Function} + */ + function findExtension(extname) { + return function (ext) { + return ext.name === extname; + }; + } + rivets.binders.wysiwyg = { publish: true, bind: function (el) { @@ -384,24 +395,24 @@ module.exports = function (result, args) { var observer = this.observer, data = observer.value() || '', // don't print 'undefined' if there's no data editor = createEditor(field, buttons), - italicBtn = dom.find('.medium-editor-action-italic'), - strikeBtn = dom.find('.medium-editor-action-strikethrough'), - linkBtn = dom.find('.medium-editor-action-anchor'); - - // put the initial data into the editor - el.innerHTML = data; + italicExtension = _.find(editor.extensions, findExtension('italic')), + strikethoughExtension = _.find(editor.extensions, findExtension('strikethrough')), + linkExtension = _.find(editor.extensions, findExtension('anchor')); // apply custom styling to buttons - if (italicBtn) { - italicBtn.innerHTML = 'I'; + if (italicExtension) { + italicExtension.button.innerHTML = 'I'; } - if (strikeBtn) { - strikeBtn.innerHTML = 'M'; + if (strikethoughExtension) { + strikethoughExtension.button.innerHTML = 'M'; } - if (linkBtn) { - linkBtn.innerHTML = ``; + if (linkExtension) { + linkExtension.button.innerHTML = ``; } + // put the initial data into the editor + el.innerHTML = data; + // hide the tier2 buttons when closing the toolbar editor.subscribe('hideToolbar', function () { dom.find('.medium-editor-toolbar').classList.remove('show-all');