Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Update Medium Editor files
Browse files Browse the repository at this point in the history
  • Loading branch information
marjinal1st committed May 7, 2014
1 parent 7154369 commit 1338bb4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
45 changes: 39 additions & 6 deletions vendor/assets/javascripts/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ if (typeof module === 'object') {

bindParagraphCreation: function (index) {
var self = this;
this.elements[index].addEventListener('keypress', function (e) {
var node = getSelectionStart(),
tagName;
if (e.which === 32) {
tagName = node.tagName.toLowerCase();
if (tagName === 'a') {
document.execCommand('unlink', false, null);
}
}
});

this.elements[index].addEventListener('keyup', function (e) {
var node = getSelectionStart(),
tagName;
Expand Down Expand Up @@ -596,10 +607,7 @@ if (typeof module === 'object') {

checkActiveButtons: function () {
var elements = Array.prototype.slice.call(this.elements),
parentNode = this.selection.anchorNode;
if (!parentNode.tagName) {
parentNode = this.selection.anchorNode.parentNode;
}
parentNode = this.getSelectedParentElement();
while (parentNode.tagName !== undefined && this.parentElements.indexOf(parentNode.tagName.toLowerCase) === -1) {
this.activateButton(parentNode.tagName.toLowerCase());
this.callExtensions('checkState', parentNode);
Expand Down Expand Up @@ -668,8 +676,31 @@ if (typeof module === 'object') {
}
},

// http://stackoverflow.com/questions/15867542/range-object-get-selection-parent-node-chrome-vs-firefox
rangeSelectsSingleNode: function (range) {
var startNode = range.startContainer;
return startNode === range.endContainer &&
startNode.hasChildNodes() &&
range.endOffset === range.startOffset + 1;
},

getSelectedParentElement: function () {
var selectedParentElement = null,
range = this.selectionRange;
if (this.rangeSelectsSingleNode(range)) {
selectedParentElement = range.startContainer.childNodes[range.startOffset];
} else if (range.startContainer.nodeType === 3) {
selectedParentElement = range.startContainer.parentNode;
} else {
selectedParentElement = range.startContainer;
}
return selectedParentElement;
},

triggerAnchorAction: function () {
if (this.selection.anchorNode.parentNode.tagName.toLowerCase() === 'a') {
var selectedParentElement = this.getSelectedParentElement();
if (selectedParentElement.tagName &&
selectedParentElement.tagName.toLowerCase() === 'a') {
document.execCommand('unlink', false, null);
} else {
if (this.anchorForm.style.display === 'block') {
Expand Down Expand Up @@ -1000,6 +1031,7 @@ if (typeof module === 'object') {
if (this.options.targetBlank) {
this.setTargetBlank();
}
this.checkSelection();
this.showToolbarActions();
input.value = '';
},
Expand Down Expand Up @@ -1106,7 +1138,8 @@ if (typeof module === 'object') {
setPlaceholders: function () {
var i,
activatePlaceholder = function (el) {
if (el.textContent.replace(/^\s+|\s+$/g, '') === '') {
if (!(el.querySelector('img')) &&
el.textContent.replace(/^\s+|\s+$/g, '') === '') {
el.classList.add('medium-editor-placeholder');
}
},
Expand Down
5 changes: 0 additions & 5 deletions vendor/assets/stylesheets/medium-editor/medium-editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,26 @@
@keyframes pop-upwards {
0% {
-webkit-transform: matrix(0.97, 0, 0, 1, 0, 12);
-ms-transform: matrix(0.97, 0, 0, 1, 0, 12);
transform: matrix(0.97, 0, 0, 1, 0, 12);
opacity: 0; }

20% {
-webkit-transform: matrix(0.99, 0, 0, 1, 0, 2);
-ms-transform: matrix(0.99, 0, 0, 1, 0, 2);
transform: matrix(0.99, 0, 0, 1, 0, 2);
opacity: 0.7; }

40% {
-webkit-transform: matrix(1, 0, 0, 1, 0, -1);
-ms-transform: matrix(1, 0, 0, 1, 0, -1);
transform: matrix(1, 0, 0, 1, 0, -1);
opacity: 1; }

70% {
-webkit-transform: matrix(1, 0, 0, 1, 0, 0);
-ms-transform: matrix(1, 0, 0, 1, 0, 0);
transform: matrix(1, 0, 0, 1, 0, 0);
opacity: 1; }

100% {
-webkit-transform: matrix(1, 0, 0, 1, 0, 0);
-ms-transform: matrix(1, 0, 0, 1, 0, 0);
transform: matrix(1, 0, 0, 1, 0, 0);
opacity: 1; } }

Expand Down

0 comments on commit 1338bb4

Please sign in to comment.