From 72408369b4f5146b7219160437cccf331be9c6d7 Mon Sep 17 00:00:00 2001 From: Nelson Pecora Date: Fri, 14 Aug 2015 15:44:55 -0400 Subject: [PATCH 1/2] wysiwyg toolbar button fix --- behaviors/wysiwyg.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/behaviors/wysiwyg.js b/behaviors/wysiwyg.js index 6048e9fa1..fcdaaec52 100644 --- a/behaviors/wysiwyg.js +++ b/behaviors/wysiwyg.js @@ -377,6 +377,12 @@ module.exports = function (result, args) { // put the rich text field after the input dom.replaceElement(textInput, field); + function findExtension(extname) { + return function (ext) { + return ext.name === extname; + }; + } + rivets.binders.wysiwyg = { publish: true, bind: function (el) { @@ -384,24 +390,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'); From 25c847e0481830446fad55ee79b86a608034c2f5 Mon Sep 17 00:00:00 2001 From: Nelson Pecora Date: Fri, 14 Aug 2015 17:07:39 -0400 Subject: [PATCH 2/2] jsdoc --- behaviors/wysiwyg.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/behaviors/wysiwyg.js b/behaviors/wysiwyg.js index fcdaaec52..184aae78d 100644 --- a/behaviors/wysiwyg.js +++ b/behaviors/wysiwyg.js @@ -377,6 +377,11 @@ 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;