Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1208 and #1209 #1224

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions dist/js/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,28 @@ MediumEditor.extensions = {};
}
},

getComputedStyle: function () {
var range = document.getSelection().getRangeAt(0),
parentNode = range.commonAncestorContainer.parentNode,
parentNodeCSS = window.getComputedStyle(parentNode, null),
containerNode = range.startContainer,
containerNodeCSS;
try {
containerNodeCSS = window.getComputedStyle(containerNode, null);
} catch (e) {
}
var fontStyles = {
'fontFamily': containerNodeCSS && containerNodeCSS.getPropertyValue('font-family') || parentNodeCSS.getPropertyValue('font-family'),
'fontSize': containerNodeCSS && containerNodeCSS.getPropertyValue('font-size') || parentNodeCSS.getPropertyValue('font-size'),
'color': containerNodeCSS && containerNodeCSS.getPropertyValue('color') || parentNodeCSS.getPropertyValue('color')
};
parentNodeCSS.setProperty('font-family', fontStyles.fontFamily);
parentNodeCSS.setProperty('font-size', fontStyles.fontSize);
parentNodeCSS.setProperty('color', fontStyles.color);

return parentNodeCSS;
},

// Cleaning up

destroy: function () {
Expand Down Expand Up @@ -2957,6 +2979,7 @@ MediumEditor.extensions = {};
},

handleClick: function (event) {
event.computedStyle = this.getComputedStyle();
this.triggerCustomEvent('editableClick', event, event.currentTarget);
},

Expand All @@ -2981,6 +3004,7 @@ MediumEditor.extensions = {};
},

handleKeyup: function (event) {
event.computedStyle = this.getComputedStyle();
this.triggerCustomEvent('editableKeyup', event, event.currentTarget);
},

Expand Down Expand Up @@ -4305,7 +4329,8 @@ MediumEditor.extensions = {};
var WHITESPACE_CHARS,
KNOWN_TLDS_FRAGMENT,
LINK_REGEXP_TEXT,
KNOWN_TLDS_REGEXP;
KNOWN_TLDS_REGEXP,
LINK_REGEXP;

WHITESPACE_CHARS = [' ', '\t', '\n', '\r', '\u00A0', '\u2000', '\u2001', '\u2002', '\u2003',
'\u2028', '\u2029'];
Expand All @@ -4327,6 +4352,8 @@ MediumEditor.extensions = {};

KNOWN_TLDS_REGEXP = new RegExp('^(' + KNOWN_TLDS_FRAGMENT + ')$', 'i');

LINK_REGEXP = new RegExp(LINK_REGEXP_TEXT, 'gi');

function nodeIsNotInsideAnchorTag(node) {
return !MediumEditor.util.getClosestTag(node, 'a');
}
Expand Down Expand Up @@ -4508,12 +4535,11 @@ MediumEditor.extensions = {};
},

findLinkableText: function (contenteditable) {
var linkRegExp = new RegExp(LINK_REGEXP_TEXT, 'gi'),
textContent = contenteditable.textContent,
var textContent = contenteditable.textContent,
match = null,
matches = [];

while ((match = linkRegExp.exec(textContent)) !== null) {
while ((match = LINK_REGEXP.exec(textContent)) !== null) {
var matchOk = true,
matchEnd = match.index + match[0].length;
// If the regexp detected something as a link that has text immediately preceding/following it, bail out.
Expand Down Expand Up @@ -7826,7 +7852,7 @@ MediumEditor.parseVersionString = function (release) {

MediumEditor.version = MediumEditor.parseVersionString.call(this, ({
// grunt-bump looks for this:
'version': '5.22.1'
'version': '5.23.0'
}).version);

return MediumEditor;
Expand Down
8 changes: 4 additions & 4 deletions dist/js/medium-editor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medium-editor",
"version": "5.22.1",
"version": "5.23.0",
"author": "Davi Ferreira <[email protected]>",
"contributors": [
{
Expand Down
24 changes: 24 additions & 0 deletions src/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,28 @@
}
},

getComputedStyle: function () {
var range = document.getSelection().getRangeAt(0),
parentNode = range.commonAncestorContainer.parentNode,
parentNodeCSS = window.getComputedStyle(parentNode, null),
containerNode = range.startContainer,
containerNodeCSS;
try {
containerNodeCSS = window.getComputedStyle(containerNode, null);
} catch (e) {
}
var fontStyles = {
'fontFamily': containerNodeCSS && containerNodeCSS.getPropertyValue('font-family') || parentNodeCSS.getPropertyValue('font-family'),
'fontSize': containerNodeCSS && containerNodeCSS.getPropertyValue('font-size') || parentNodeCSS.getPropertyValue('font-size'),
'color': containerNodeCSS && containerNodeCSS.getPropertyValue('color') || parentNodeCSS.getPropertyValue('color')
};
parentNodeCSS.setProperty('font-family', fontStyles.fontFamily);
parentNodeCSS.setProperty('font-size', fontStyles.fontSize);
parentNodeCSS.setProperty('color', fontStyles.color);

return parentNodeCSS;
},

// Cleaning up

destroy: function () {
Expand Down Expand Up @@ -524,6 +546,7 @@
},

handleClick: function (event) {
event.computedStyle = this.getComputedStyle();
this.triggerCustomEvent('editableClick', event, event.currentTarget);
},

Expand All @@ -548,6 +571,7 @@
},

handleKeyup: function (event) {
event.computedStyle = this.getComputedStyle();
this.triggerCustomEvent('editableKeyup', event, event.currentTarget);
},

Expand Down
2 changes: 1 addition & 1 deletion src/js/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ MediumEditor.parseVersionString = function (release) {

MediumEditor.version = MediumEditor.parseVersionString.call(this, ({
// grunt-bump looks for this:
'version': '5.22.1'
'version': '5.23.0'
}).version);