Skip to content

Commit

Permalink
5.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Aug 11, 2016
1 parent 3203dcd commit 1ae7fd4
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 27 deletions.
115 changes: 93 additions & 22 deletions dist/js/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3858,7 +3858,8 @@ MediumEditor.extensions = {};
// Matches any alphabetical characters followed by ://
// Matches protocol relative "//"
// Matches common external protocols "mailto:" "tel:" "maps:"
var urlSchemeRegex = /^([a-z]+:)?\/\/|^(mailto|tel|maps):/i,
// Matches relative hash link, begins with "#"
var urlSchemeRegex = /^([a-z]+:)?\/\/|^(mailto|tel|maps):|^\#/i,
// var te is a regex for checking if the string is a telephone number
telRegex = /^\+?\s?\(?(?:\d\s?\-?\)?){3,20}$/;
if (telRegex.test(value)) {
Expand Down Expand Up @@ -4060,13 +4061,15 @@ MediumEditor.extensions = {};

positionPreview: function (activeAnchor) {
activeAnchor = activeAnchor || this.activeAnchor;
var buttonHeight = this.anchorPreview.offsetHeight,
var containerWidth = this.window.innerWidth,
buttonHeight = this.anchorPreview.offsetHeight,
boundary = activeAnchor.getBoundingClientRect(),
middleBoundary = (boundary.left + boundary.right) / 2,
diffLeft = this.diffLeft,
diffTop = this.diffTop,
halfOffsetWidth,
defaultLeft;
elementsContainer = this.getEditorOption('elementsContainer'),
elementsContainerAbsolute = ['absolute', 'fixed'].indexOf(window.getComputedStyle(elementsContainer).getPropertyValue('position')) > -1,
relativeBoundary = {},
halfOffsetWidth, defaultLeft, middleBoundary, elementsContainerBoundary, top;

halfOffsetWidth = this.anchorPreview.offsetWidth / 2;
var toolbarExtension = this.base.getExtensionByName('toolbar');
Expand All @@ -4076,12 +4079,35 @@ MediumEditor.extensions = {};
}
defaultLeft = diffLeft - halfOffsetWidth;

this.anchorPreview.style.top = Math.round(buttonHeight + boundary.bottom - diffTop + this.window.pageYOffset - this.anchorPreview.offsetHeight) + 'px';
// If container element is absolute / fixed, recalculate boundaries to be relative to the container
if (elementsContainerAbsolute) {
elementsContainerBoundary = elementsContainer.getBoundingClientRect();
['top', 'left'].forEach(function (key) {
relativeBoundary[key] = boundary[key] - elementsContainerBoundary[key];
});

relativeBoundary.width = boundary.width;
relativeBoundary.height = boundary.height;
boundary = relativeBoundary;

containerWidth = elementsContainerBoundary.width;

// Adjust top position according to container scroll position
top = elementsContainer.scrollTop;
} else {
// Adjust top position according to window scroll position
top = this.window.pageYOffset;
}

middleBoundary = boundary.left + boundary.width / 2;
top += buttonHeight + boundary.top + boundary.height - diffTop - this.anchorPreview.offsetHeight;

this.anchorPreview.style.top = Math.round(top) + 'px';
this.anchorPreview.style.right = 'initial';
if (middleBoundary < halfOffsetWidth) {
this.anchorPreview.style.left = defaultLeft + halfOffsetWidth + 'px';
this.anchorPreview.style.right = 'initial';
} else if ((this.window.innerWidth - middleBoundary) < halfOffsetWidth) {
} else if ((containerWidth - middleBoundary) < halfOffsetWidth) {
this.anchorPreview.style.left = 'auto';
this.anchorPreview.style.right = 0;
} else {
Expand Down Expand Up @@ -5068,13 +5094,13 @@ MediumEditor.extensions = {};
[new RegExp(/<br class="Apple-interchange-newline">/g), '<br>'],

// replace google docs italics+bold with a span to be replaced once the html is inserted
[new RegExp(/<span[^>]*(font-style:italic;font-weight:bold|font-weight:bold;font-style:italic)[^>]*>/gi), '<span class="replace-with italic bold">'],
[new RegExp(/<span[^>]*(font-style:italic;font-weight:(bold|700)|font-weight:(bold|700);font-style:italic)[^>]*>/gi), '<span class="replace-with italic bold">'],

// replace google docs italics with a span to be replaced once the html is inserted
[new RegExp(/<span[^>]*font-style:italic[^>]*>/gi), '<span class="replace-with italic">'],

//[replace google docs bolds with a span to be replaced once the html is inserted
[new RegExp(/<span[^>]*font-weight:bold[^>]*>/gi), '<span class="replace-with bold">'],
[new RegExp(/<span[^>]*font-weight:(bold|700)[^>]*>/gi), '<span class="replace-with bold">'],

// replace manually entered b/i/a tags with real ones
[new RegExp(/&lt;(\/?)(i|b|a)&gt;/gi), '<$1$2>'],
Expand Down Expand Up @@ -6306,35 +6332,66 @@ MediumEditor.extensions = {};
}
}

var windowWidth = this.window.innerWidth,
middleBoundary = (boundary.left + boundary.right) / 2,
var containerWidth = this.window.innerWidth,
toolbarElement = this.getToolbarElement(),
toolbarHeight = toolbarElement.offsetHeight,
toolbarWidth = toolbarElement.offsetWidth,
halfOffsetWidth = toolbarWidth / 2,
buttonHeight = 50,
defaultLeft = this.diffLeft - halfOffsetWidth;
defaultLeft = this.diffLeft - halfOffsetWidth,
elementsContainer = this.getEditorOption('elementsContainer'),
elementsContainerAbsolute = ['absolute', 'fixed'].indexOf(window.getComputedStyle(elementsContainer).getPropertyValue('position')) > -1,
positions = {},
relativeBoundary = {},
middleBoundary, elementsContainerBoundary;

// If container element is absolute / fixed, recalculate boundaries to be relative to the container
if (elementsContainerAbsolute) {
elementsContainerBoundary = elementsContainer.getBoundingClientRect();
['top', 'left'].forEach(function (key) {
relativeBoundary[key] = boundary[key] - elementsContainerBoundary[key];
});

relativeBoundary.width = boundary.width;
relativeBoundary.height = boundary.height;
boundary = relativeBoundary;

containerWidth = elementsContainerBoundary.width;

// Adjust top position according to container scroll position
positions.top = elementsContainer.scrollTop;
} else {
// Adjust top position according to window scroll position
positions.top = this.window.pageYOffset;
}

middleBoundary = boundary.left + boundary.width / 2;
positions.top += boundary.top - toolbarHeight;

if (boundary.top < buttonHeight) {
toolbarElement.classList.add('medium-toolbar-arrow-over');
toolbarElement.classList.remove('medium-toolbar-arrow-under');
toolbarElement.style.top = buttonHeight + boundary.bottom - this.diffTop + this.window.pageYOffset - toolbarHeight + 'px';
positions.top += buttonHeight + boundary.height - this.diffTop;
} else {
toolbarElement.classList.add('medium-toolbar-arrow-under');
toolbarElement.classList.remove('medium-toolbar-arrow-over');
toolbarElement.style.top = boundary.top + this.diffTop + this.window.pageYOffset - toolbarHeight + 'px';
positions.top += this.diffTop;
}

if (middleBoundary < halfOffsetWidth) {
toolbarElement.style.left = defaultLeft + halfOffsetWidth + 'px';
toolbarElement.style.right = 'initial';
} else if ((windowWidth - middleBoundary) < halfOffsetWidth) {
toolbarElement.style.left = 'auto';
toolbarElement.style.right = 0;
positions.left = defaultLeft + halfOffsetWidth;
positions.right = 'initial';
} else if ((containerWidth - middleBoundary) < halfOffsetWidth) {
positions.left = 'auto';
positions.right = 0;
} else {
toolbarElement.style.left = defaultLeft + middleBoundary + 'px';
toolbarElement.style.right = 'initial';
positions.left = defaultLeft + middleBoundary;
positions.right = 'initial';
}

['top', 'left', 'right'].forEach(function (key) {
toolbarElement.style[key] = positions[key] + (isNaN(positions[key]) ? '' : 'px');
});
}
});

Expand Down Expand Up @@ -6541,6 +6598,20 @@ MediumEditor.extensions = {};
// then pressing backspace key should change the <blockquote> to a <p> tag
event.preventDefault();
MediumEditor.util.execFormatBlock(this.options.ownerDocument, 'p');
} else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.ENTER) &&
(MediumEditor.util.getClosestTag(node, 'blockquote') !== false) &&
MediumEditor.selection.getCaretOffsets(node).right === 0) {

// when cursor is at the end of <blockquote>,
// then pressing enter key should create <p> tag, not <blockquote>
p = this.options.ownerDocument.createElement('p');
p.innerHTML = '<br>';
node.parentElement.insertBefore(p, node.nextSibling);

// move the cursor into the new paragraph
MediumEditor.selection.moveCursor(this.options.ownerDocument, p);

event.preventDefault();
}
}

Expand Down Expand Up @@ -7697,7 +7768,7 @@ MediumEditor.parseVersionString = function (release) {

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

return MediumEditor;
Expand Down
6 changes: 3 additions & 3 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.21.0",
"version": "5.21.1",
"author": "Davi Ferreira <hi@daviferreira.com>",
"contributors": [
{
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.21.0'
'version': '5.21.1'
}).version);

0 comments on commit 1ae7fd4

Please sign in to comment.