From c6b96b27b6e5fe7d753838befbfde63f9fa68eb7 Mon Sep 17 00:00:00 2001 From: Ahmet Sezgin Duran Date: Mon, 24 Nov 2014 21:37:11 +0200 Subject: [PATCH] Update Medium Editor files --- vendor/assets/javascripts/medium-editor.js | 106 +++++++++++------- .../medium-editor/medium-editor.css | 6 +- .../medium-editor/themes/bootstrap.css | 3 +- .../medium-editor/themes/default.css | 3 +- .../stylesheets/medium-editor/themes/flat.css | 4 +- .../stylesheets/medium-editor/themes/mani.css | 3 +- 6 files changed, 70 insertions(+), 55 deletions(-) diff --git a/vendor/assets/javascripts/medium-editor.js b/vendor/assets/javascripts/medium-editor.js index 8d6f35c..d20830e 100644 --- a/vendor/assets/javascripts/medium-editor.js +++ b/vendor/assets/javascripts/medium-editor.js @@ -152,11 +152,15 @@ else if (typeof define === 'function' && define.amd) { return; } this.parentElements = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'pre']; - this.id = document.querySelectorAll('.medium-editor-toolbar').length + 1; + if (!this.options.elementsContainer) { + this.options.elementsContainer = document.body; + } + this.id = this.options.elementsContainer.querySelectorAll('.medium-editor-toolbar').length + 1; return this.setup(); }, setup: function () { + this.events = []; this.isActive = true; this.initElements() .bindSelect() @@ -166,6 +170,28 @@ else if (typeof define === 'function' && define.amd) { .passInstance(); }, + on: function(target, event, listener, useCapture) { + target.addEventListener(event, listener, useCapture); + this.events.push([target, event, listener, useCapture]); + }, + + off: function(target, event, listener, useCapture) { + var index = this.events.indexOf([target, event, listener, useCapture]), + e; + if(index !== -1) { + e = this.events.splice(index, 1); + e[0].removeEventListener(e[1], e[2], e[3]); + } + }, + + removeAllEvents: function() { + var e = this.events.pop(); + while(e) { + e[0].removeEventListener(e[1], e[2], e[3]); + e = this.events.pop(); + } + }, + initElements: function () { this.updateElementList(); var i, @@ -185,9 +211,6 @@ else if (typeof define === 'function' && define.amd) { } // Init toolbar if (addToolbar) { - if (!this.options.elementsContainer) { - this.options.elementsContainer = document.body; - } this.initToolbar() .bindButtons() .bindAnchorForm() @@ -272,7 +295,7 @@ else if (typeof define === 'function' && define.amd) { bindParagraphCreation: function (index) { var self = this; - this.elements[index].addEventListener('keypress', function (e) { + this.on(this.elements[index], 'keypress', function (e) { var node = getSelectionStart.call(self), tagName; if (e.which === 32) { @@ -283,7 +306,7 @@ else if (typeof define === 'function' && define.amd) { } }); - this.elements[index].addEventListener('keyup', function (e) { + this.on(this.elements[index], 'keyup', function (e) { var node = getSelectionStart.call(self), tagName, editorElement; @@ -329,7 +352,7 @@ else if (typeof define === 'function' && define.amd) { bindReturn: function (index) { var self = this; - this.elements[index].addEventListener('keypress', function (e) { + this.on(this.elements[index], 'keypress', function (e) { if (e.which === 13) { if (self.options.disableReturn || this.getAttribute('data-disable-return')) { e.preventDefault(); @@ -346,7 +369,7 @@ else if (typeof define === 'function' && define.amd) { bindTab: function (index) { var self = this; - this.elements[index].addEventListener('keydown', function (e) { + this.on(this.elements[index], 'keydown', function (e) { if (e.which === 9) { // Override tab only for pre nodes var tag = getSelectionStart.call(self).tagName.toLowerCase(); @@ -377,7 +400,7 @@ else if (typeof define === 'function' && define.amd) { 'bold': '', 'italic': '', 'underline': '', - 'strikethrough': '', + 'strikethrough': '', 'superscript': '', 'subscript': '', 'anchor': '', @@ -406,6 +429,7 @@ else if (typeof define === 'function' && define.amd) { 'bold': 'B', 'italic': 'I', 'underline': 'U', + 'strikethrough': 'A', 'superscript': 'x1', 'subscript': 'x1', 'anchor': '#', @@ -428,6 +452,7 @@ else if (typeof define === 'function' && define.amd) { 'bold': '', 'italic': '', 'underline': '', + 'strikethrough': '', 'superscript': '', 'subscript': '', 'anchor': '', @@ -586,11 +611,11 @@ else if (typeof define === 'function' && define.amd) { }, self.options.delay); }; - document.documentElement.addEventListener('mouseup', this.checkSelectionWrapper); + this.on(document.documentElement, 'mouseup', this.checkSelectionWrapper); for (i = 0; i < this.elements.length; i += 1) { - this.elements[i].addEventListener('keyup', this.checkSelectionWrapper); - this.elements[i].addEventListener('blur', this.checkSelectionWrapper); + this.on(this.elements[i], 'keyup', this.checkSelectionWrapper); + this.on(this.elements[i], 'blur', this.checkSelectionWrapper); } return this; }, @@ -772,7 +797,7 @@ else if (typeof define === 'function' && define.amd) { } }; for (i = 0; i < buttons.length; i += 1) { - buttons[i].addEventListener('click', triggerAction); + this.on(buttons[i], 'click', triggerAction); } this.setFirstAndLastItems(buttons); return this; @@ -934,12 +959,12 @@ else if (typeof define === 'function' && define.amd) { linkSave = this.anchorForm.querySelector('a.medium-editor-toobar-anchor-save'), self = this; - this.anchorForm.addEventListener('click', function (e) { + this.on(this.anchorForm, 'click', function (e) { e.stopPropagation(); self.keepToolbarAlive = true; }); - this.anchorInput.addEventListener('keyup', function (e) { + this.on(this.anchorInput, 'keyup', function (e) { var button = null, target; @@ -960,7 +985,7 @@ else if (typeof define === 'function' && define.amd) { } }); - linkSave.addEventListener('click', function(e) { + this.on(linkSave, 'click', function(e) { var button = null, target; e.preventDefault(); @@ -978,27 +1003,27 @@ else if (typeof define === 'function' && define.amd) { self.createLink(self.anchorInput, target, button); }, true); - this.anchorInput.addEventListener('click', function (e) { + this.on(this.anchorInput, 'click', function (e) { // make sure not to hide form when cliking into the input e.stopPropagation(); self.keepToolbarAlive = true; }); // Hide the anchor form when focusing outside of it. - this.options.ownerDocument.body.addEventListener('click', function (e) { + this.on(this.options.ownerDocument.body, 'click', function (e) { if (e.target !== self.anchorForm && !isDescendant(self.anchorForm, e.target) && !isDescendant(self.toolbarActions, e.target)) { self.keepToolbarAlive = false; self.checkSelection(); } }, true); - this.options.ownerDocument.body.addEventListener('focus', function (e) { + this.on(this.options.ownerDocument.body, 'focus', function (e) { if (e.target !== self.anchorForm && !isDescendant(self.anchorForm, e.target) && !isDescendant(self.toolbarActions, e.target)) { self.keepToolbarAlive = false; self.checkSelection(); } }, true); - linkCancel.addEventListener('click', function (e) { + this.on(linkCancel, 'click', function (e) { e.preventDefault(); self.showToolbarActions(); restoreSelection.call(self, self.savedSelection); @@ -1078,18 +1103,18 @@ else if (typeof define === 'function' && define.amd) { // cleanup clearInterval(interval_timer); - self.anchorPreview.removeEventListener('mouseover', stamp); - self.anchorPreview.removeEventListener('mouseout', unstamp); - anchorEl.removeEventListener('mouseover', stamp); - anchorEl.removeEventListener('mouseout', unstamp); + self.off(self.anchorPreview, 'mouseover', stamp); + self.off(self.anchorPreview, 'mouseout', unstamp); + self.off(anchorEl, 'mouseover', stamp); + self.off(anchorEl, 'mouseout', unstamp); } }, 200); - self.anchorPreview.addEventListener('mouseover', stamp); - self.anchorPreview.addEventListener('mouseout', unstamp); - anchorEl.addEventListener('mouseover', stamp); - anchorEl.addEventListener('mouseout', unstamp); + this.on(self.anchorPreview, 'mouseover', stamp); + this.on(self.anchorPreview, 'mouseout', unstamp); + this.on(anchorEl, 'mouseover', stamp); + this.on(anchorEl, 'mouseout', unstamp); }, createAnchorPreview: function () { @@ -1101,7 +1126,7 @@ else if (typeof define === 'function' && define.amd) { anchorPreview.innerHTML = this.anchorPreviewTemplate(); this.options.elementsContainer.appendChild(anchorPreview); - anchorPreview.addEventListener('click', function () { + this.on(anchorPreview, 'click', function () { self.anchorPreviewClickHandler(); }); @@ -1142,7 +1167,7 @@ else if (typeof define === 'function' && define.amd) { leaveAnchor = function () { // mark the anchor as no longer hovered, and stop listening overAnchor = false; - self.activeAnchor.removeEventListener('mouseout', leaveAnchor); + self.off(self.activeAnchor, 'mouseout', leaveAnchor); }; if (e.target && e.target.tagName.toLowerCase() === 'a') { @@ -1160,7 +1185,7 @@ else if (typeof define === 'function' && define.amd) { return true; } this.activeAnchor = e.target; - this.activeAnchor.addEventListener('mouseout', leaveAnchor); + this.on(this.activeAnchor, 'mouseout', leaveAnchor); // show the anchor preview according to the configured delay // if the mouse has not left the anchor tag in that time setTimeout(function () { @@ -1179,7 +1204,7 @@ else if (typeof define === 'function' && define.amd) { self.editorAnchorObserver(e); }; for (i = 0; i < this.elements.length; i += 1) { - this.elements[i].addEventListener('mouseover', this.editorAnchorObserverWrapper); + this.on(this.elements[i], 'mouseover', this.editorAnchorObserverWrapper); } return this; }, @@ -1196,6 +1221,7 @@ else if (typeof define === 'function' && define.amd) { el.target = '_blank'; } else { el = el.getElementsByTagName('a'); + for (i = 0; i < el.length; i += 1) { el[i].target = '_blank'; } @@ -1268,7 +1294,7 @@ else if (typeof define === 'function' && define.amd) { } }, 100); }; - this.options.contentWindow.addEventListener('resize', this.windowResizeHandler); + this.on(this.options.contentWindow, 'resize', this.windowResizeHandler); return this; }, @@ -1295,18 +1321,12 @@ else if (typeof define === 'function' && define.amd) { delete this.anchorPreview; } - this.options.ownerDocument.documentElement.removeEventListener('mouseup', this.checkSelectionWrapper); - this.options.contentWindow.removeEventListener('resize', this.windowResizeHandler); - for (i = 0; i < this.elements.length; i += 1) { - this.elements[i].removeEventListener('mouseover', this.editorAnchorObserverWrapper); - this.elements[i].removeEventListener('keyup', this.checkSelectionWrapper); - this.elements[i].removeEventListener('blur', this.checkSelectionWrapper); - this.elements[i].removeEventListener('paste', this.pasteWrapper); this.elements[i].removeAttribute('contentEditable'); this.elements[i].removeAttribute('data-medium-element'); } + this.removeAllEvents(); }, htmlEntities: function (str) { @@ -1352,7 +1372,7 @@ else if (typeof define === 'function' && define.amd) { } }; for (i = 0; i < this.elements.length; i += 1) { - this.elements[i].addEventListener('paste', this.pasteWrapper); + this.on(this.elements[i], 'paste', this.pasteWrapper); } return this; }, @@ -1374,8 +1394,8 @@ else if (typeof define === 'function' && define.amd) { }; for (i = 0; i < this.elements.length; i += 1) { activatePlaceholder(this.elements[i]); - this.elements[i].addEventListener('blur', placeholderWrapper); - this.elements[i].addEventListener('keypress', placeholderWrapper); + this.on(this.elements[i], 'blur', placeholderWrapper); + this.on(this.elements[i], 'keypress', placeholderWrapper); } return this; }, diff --git a/vendor/assets/stylesheets/medium-editor/medium-editor.css b/vendor/assets/stylesheets/medium-editor/medium-editor.css index 6244319..3ee85de 100644 --- a/vendor/assets/stylesheets/medium-editor/medium-editor.css +++ b/vendor/assets/stylesheets/medium-editor/medium-editor.css @@ -99,8 +99,7 @@ font-size: 14px; line-height: 1.33; text-decoration: none; - -moz-box-sizing: border-box; - box-sizing: border-box; } + box-sizing: border-box; } .medium-editor-toolbar li .medium-editor-action-underline, .medium-editor-anchor-preview li .medium-editor-action-underline { text-decoration: underline; } .medium-editor-toolbar li .medium-editor-action-pre, .medium-editor-anchor-preview li .medium-editor-action-pre { @@ -140,8 +139,7 @@ width: 316px; border: none; font-size: 14px; - -moz-box-sizing: border-box; - box-sizing: border-box; } + box-sizing: border-box; } .medium-editor-toolbar-form-anchor .medium-editor-toolbar-anchor-input:focus, .medium-editor-toolbar-form-anchor label:focus { outline: 0; border: none; diff --git a/vendor/assets/stylesheets/medium-editor/themes/bootstrap.css b/vendor/assets/stylesheets/medium-editor/themes/bootstrap.css index 6b67dea..8d258af 100644 --- a/vendor/assets/stylesheets/medium-editor/themes/bootstrap.css +++ b/vendor/assets/stylesheets/medium-editor/themes/bootstrap.css @@ -18,8 +18,7 @@ border-right: 1px solid #357ebd; background-color: transparent; color: #fff; - -moz-box-sizing: border-box; - box-sizing: border-box; + box-sizing: border-box; -webkit-transition: background-color 0.2s ease-in, color 0.2s ease-in; transition: background-color 0.2s ease-in, color 0.2s ease-in; } .medium-editor-toolbar li button:hover { diff --git a/vendor/assets/stylesheets/medium-editor/themes/default.css b/vendor/assets/stylesheets/medium-editor/themes/default.css index e7d4917..676a1a8 100755 --- a/vendor/assets/stylesheets/medium-editor/themes/default.css +++ b/vendor/assets/stylesheets/medium-editor/themes/default.css @@ -52,8 +52,7 @@ height: 50px; background: #242424; color: #ccc; - -moz-box-sizing: border-box; - box-sizing: border-box; } + box-sizing: border-box; } .medium-editor-toolbar-form-anchor a { color: #fff; } diff --git a/vendor/assets/stylesheets/medium-editor/themes/flat.css b/vendor/assets/stylesheets/medium-editor/themes/flat.css index 043740e..5a76ede 100644 --- a/vendor/assets/stylesheets/medium-editor/themes/flat.css +++ b/vendor/assets/stylesheets/medium-editor/themes/flat.css @@ -14,13 +14,13 @@ min-width: 60px; height: 60px; border: none; - border-right: 1px solid #9ccea5; + border-right: 1px solid #9ccea6; background-color: transparent; color: #fff; -webkit-transition: background-color 0.2s ease-in, color 0.2s ease-in; transition: background-color 0.2s ease-in, color 0.2s ease-in; } .medium-editor-toolbar li button:hover { - background-color: #346a3e; + background-color: #346a3f; color: #fff; } .medium-editor-toolbar li .medium-editor-button-active { background-color: #23482a; diff --git a/vendor/assets/stylesheets/medium-editor/themes/mani.css b/vendor/assets/stylesheets/medium-editor/themes/mani.css index b1ad382..3d25d3e 100644 --- a/vendor/assets/stylesheets/medium-editor/themes/mani.css +++ b/vendor/assets/stylesheets/medium-editor/themes/mani.css @@ -43,8 +43,7 @@ height: 50px; background: #dee7f0; color: #40648a; - -moz-box-sizing: border-box; - box-sizing: border-box; } + box-sizing: border-box; } .medium-editor-toolbar-form-anchor a { color: #40648a; }