Skip to content

Commit

Permalink
1.3.1 + formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Davi Ferreira committed Nov 19, 2013
1 parent e668b4a commit 8dde775
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.3.1 / 2013-11-19
==================

* Fixes toolbar binding button issue with multi-editor mode


1.3.0 / 2013-11-18
==================

Expand All @@ -9,13 +15,15 @@
* Improves allowMultiParagraphSelection filter by removing empty tags elements before counting
* Considers header tags has a paragraph too (same as medium)


1.2.2 / 2013-11-07
==================

* Removes blur event listener when disabling the toolbar
* Adds a light gradient opacity to the toolbar
* Fixes bug that would keep toolbar alive when moving out of the anchor input


1.2.1 / 2013-11-07
==================

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medium-editor",
"version": "1.3.0",
"version": "1.3.1",
"homepage": "http://daviferreira.github.io/medium-editor/",
"authors": [
"Davi Ferreira <hi@daviferreira.com>"
Expand Down
2 changes: 0 additions & 2 deletions demo/multieditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ <h2>Second Editor </h2>
<div class="secondEditable" id="c">
<h2>Third Editor in another instance </h2>
<p>This text is another paragraph in another editor instance.<br>
It's working but not recommended.
</p>
</div>
<div class="editable" id="d" data-disable-toolbar="true">
Expand All @@ -37,7 +36,6 @@ <h2>Non editable Div</h2>
</div>

</div>
<p style="text-align: center;"><small><a style="color: #333;" target="_blank" href="http://www.goodreads.com/reader/475-great-expectations">Source</a></small></p>

<script src="../dist/js/medium-editor.js"></script>
<script>
Expand Down
24 changes: 15 additions & 9 deletions dist/js/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,21 @@ if (window.module !== undefined) {
}
return this;
},

bindParagraphCreation: function (index) {
var self = this;
this.elements[index].addEventListener('keyup', function (e) {
var node = getSelectionStart(),
tagName;
if (node && node.getAttribute('data-medium-element') && node.children.length === 0 && !(self.options.disableReturn || node.getAttribute('data-disable-return'))) {
if (node && node.getAttribute('data-medium-element') && node.children.length === 0
&& !(self.options.disableReturn || node.getAttribute('data-disable-return'))) {
document.execCommand('formatBlock', false, 'p');
}
if (e.which === 13 && !e.shiftKey) {
node = getSelectionStart();
tagName = node.tagName.toLowerCase();
if (!(self.options.disableReturn || this.getAttribute('data-disable-return')) && tagName !== 'li') {
if (!(self.options.disableReturn || this.getAttribute('data-disable-return'))
&& tagName !== 'li') {
document.execCommand('formatBlock', false, 'p');
if (tagName === 'a') {
document.execCommand('unlink', false, null);
Expand Down Expand Up @@ -204,7 +207,8 @@ if (window.module !== undefined) {
}
html += '</ul>' +
'<div class="medium-editor-toolbar-form-anchor" id="medium-editor-toolbar-form-anchor">' +
' <input type="text" value="" placeholder="' + this.options.anchorInputPlaceholder + '"><a href="#">&times;</a>' +
' <input type="text" value="" placeholder="' + this.options.anchorInputPlaceholder + '">' +
' <a href="#">&times;</a>' +
'</div>';
return html;
},
Expand Down Expand Up @@ -253,17 +257,18 @@ if (window.module !== undefined) {
checkSelection: function () {
var i,
newSelection,
pCount,
hasMultiParagraphs,
selectionHtml,
selectionElement;
if (this.keepToolbarAlive !== true && !this.options.disableToolbar) {
newSelection = window.getSelection();
selectionHtml = getSelectionHtml();
selectionHtml = selectionHtml.replace(/<[\S]+><\/[\S]+>/gim, '');
// Check if selection is between multi paragraph <p>.
pCount = selectionHtml.match(/<(p|h[0-6]|blockquote)>([\s\S]*?)<\/(p|h[0-6]|blockquote)>/g);
pCount = pCount ? pCount.length : 0;
if (newSelection.toString().trim() === '' || (this.options.allowMultiParagraphSelection === false && pCount)) {
hasMultiParagraphs = selectionHtml.match(/<(p|h[0-6]|blockquote)>([\s\S]*?)<\/(p|h[0-6]|blockquote)>/g);
hasMultiParagraphs = hasMultiParagraphs ? hasMultiParagraphs.length : 0;
if (newSelection.toString().trim() === ''
|| (this.options.allowMultiParagraphSelection === false && hasMultiParagraphs)) {
this.hideToolbarActions();
} else {
selectionElement = this.getSelectionElement();
Expand Down Expand Up @@ -312,7 +317,7 @@ if (window.module !== undefined) {
result = getMediumElement(parent);
}
// If not search in the parent nodes.
} catch (erra) {
} catch (err) {
result = getMediumElement(parent);
}
return result;
Expand Down Expand Up @@ -434,7 +439,8 @@ if (window.module !== undefined) {
// FF handles blockquote differently on formatBlock
// allowing nesting, we need to use outdent
// https://developer.mozilla.org/en-US/docs/Rich-Text_Editing_in_Mozilla
if (el === 'blockquote' && selectionData.el && selectionData.el.parentNode.tagName.toLowerCase() === 'blockquote') {
if (el === 'blockquote' && selectionData.el
&& selectionData.el.parentNode.tagName.toLowerCase() === 'blockquote') {
return document.execCommand('outdent', false, null);
}
if (selectionData.tagName === el) {
Expand Down
2 changes: 1 addition & 1 deletion 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": "1.3.0",
"version": "1.3.1",
"description": "Medium.com WYSIWYG editor clone.",
"main": "src/js/medium-editor.js",
"repository": {
Expand Down
24 changes: 15 additions & 9 deletions src/js/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,21 @@ if (window.module !== undefined) {
}
return this;
},

bindParagraphCreation: function (index) {
var self = this;
this.elements[index].addEventListener('keyup', function (e) {
var node = getSelectionStart(),
tagName;
if (node && node.getAttribute('data-medium-element') && node.children.length === 0 && !(self.options.disableReturn || node.getAttribute('data-disable-return'))) {
if (node && node.getAttribute('data-medium-element') && node.children.length === 0
&& !(self.options.disableReturn || node.getAttribute('data-disable-return'))) {
document.execCommand('formatBlock', false, 'p');
}
if (e.which === 13 && !e.shiftKey) {
node = getSelectionStart();
tagName = node.tagName.toLowerCase();
if (!(self.options.disableReturn || this.getAttribute('data-disable-return')) && tagName !== 'li') {
if (!(self.options.disableReturn || this.getAttribute('data-disable-return'))
&& tagName !== 'li') {
document.execCommand('formatBlock', false, 'p');
if (tagName === 'a') {
document.execCommand('unlink', false, null);
Expand Down Expand Up @@ -206,7 +209,8 @@ if (window.module !== undefined) {
}
html += '</ul>' +
'<div class="medium-editor-toolbar-form-anchor" id="medium-editor-toolbar-form-anchor">' +
' <input type="text" value="" placeholder="' + this.options.anchorInputPlaceholder + '"><a href="#">&times;</a>' +
' <input type="text" value="" placeholder="' + this.options.anchorInputPlaceholder + '">' +
' <a href="#">&times;</a>' +
'</div>';
return html;
},
Expand Down Expand Up @@ -255,17 +259,18 @@ if (window.module !== undefined) {
checkSelection: function () {
var i,
newSelection,
pCount,
hasMultiParagraphs,
selectionHtml,
selectionElement;
if (this.keepToolbarAlive !== true && !this.options.disableToolbar) {
newSelection = window.getSelection();
selectionHtml = getSelectionHtml();
selectionHtml = selectionHtml.replace(/<[\S]+><\/[\S]+>/gim, '');
// Check if selection is between multi paragraph <p>.
pCount = selectionHtml.match(/<(p|h[0-6]|blockquote)>([\s\S]*?)<\/(p|h[0-6]|blockquote)>/g);
pCount = pCount ? pCount.length : 0;
if (newSelection.toString().trim() === '' || (this.options.allowMultiParagraphSelection === false && pCount)) {
hasMultiParagraphs = selectionHtml.match(/<(p|h[0-6]|blockquote)>([\s\S]*?)<\/(p|h[0-6]|blockquote)>/g);
hasMultiParagraphs = hasMultiParagraphs ? hasMultiParagraphs.length : 0;
if (newSelection.toString().trim() === ''
|| (this.options.allowMultiParagraphSelection === false && hasMultiParagraphs)) {
this.hideToolbarActions();
} else {
selectionElement = this.getSelectionElement();
Expand Down Expand Up @@ -314,7 +319,7 @@ if (window.module !== undefined) {
result = getMediumElement(parent);
}
// If not search in the parent nodes.
} catch (erra) {
} catch (err) {
result = getMediumElement(parent);
}
return result;
Expand Down Expand Up @@ -436,7 +441,8 @@ if (window.module !== undefined) {
// FF handles blockquote differently on formatBlock
// allowing nesting, we need to use outdent
// https://developer.mozilla.org/en-US/docs/Rich-Text_Editing_in_Mozilla
if (el === 'blockquote' && selectionData.el && selectionData.el.parentNode.tagName.toLowerCase() === 'blockquote') {
if (el === 'blockquote' && selectionData.el
&& selectionData.el.parentNode.tagName.toLowerCase() === 'blockquote') {
return document.execCommand('outdent', false, null);
}
if (selectionData.tagName === el) {
Expand Down

0 comments on commit 8dde775

Please sign in to comment.