Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from 8818dd1..0b74389
Browse files Browse the repository at this point in the history
0b74389 Merge pull request #364 from wordpress-mobile/issue/227-list-paragraph-formatting
2d1ea2a Merge pull request #363 from wordpress-mobile/issue/345-blockquote-links
b6a7d2e Merge pull request #366 from wordpress-mobile/issue/365-link-indexsizeerror
a3af084 Fixed IndexSizeError issue when inserting links in an empty post
c4c8986 Adjusted spacing for text expansion methods
b518a34 When exiting a list while the current list item is not empty, wrap the un-listed text in a paragraph node
ca00128 Fixed mistake in method call in ZSSEditor.previousNode
0a14286 Ignore break tags when finding the end of a range container
a25bf35 Don't wrap links inside blockquotes in paragraph tags if they're not at either end of the line
8420ab5 Don't wrap links in paragraph tags when the blockquote is empty
67939fa Wrap links in paragraph tags when inside blockquotes
6abc921 Merge pull request #362 from wordpress-mobile/issue/361-old-api-upload-css
b392660 Add 'uploading' class to media regardless of progress bar status
a13b162 Merge pull request #4024 from wordpress-mobile/feature/update-gradle-plugin
bfb702a Updating gradle plugin to 2.1.0 for Android Studio 2.1.0
e0e7156 Merge commit 'ac1a4af3be8b6e95d1799ce2f82fca06a73577c0' into develop
8bbe028 Merge pull request #3967 from wordpress-mobile/issue/328editor-track-reflection-failure
423bbb2 Merge pull request #3961 from wordpress-mobile/issue/3930-crash-when-adding-invalid-image
13c5880 Merge commit 'be4aac09995c4a35b2354854ef0f3ff5b1ae07e7' into develop
2bc7b91 Use a static listener to handle reflection failures
3754128 Updates the p/div conversion regex to more strictly match tags
43bab5e Move the addMediaFile logic in an AsyncTask, only WPEditImageSpan construction now lives in a background thread

git-subtree-dir: libs/editor
git-subtree-split: 0b74389ff2200e00d3db27be6087261638dafcca
  • Loading branch information
maxme committed May 1, 2016
1 parent 9907504 commit 4542685
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 32 deletions.
2 changes: 1 addition & 1 deletion WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:2.1.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:2.1.0'
}
}

Expand Down
99 changes: 69 additions & 30 deletions libs/editor-common/assets/ZSSRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,29 +411,39 @@ ZSSEditor.getSelectedText = function() {
};

ZSSEditor.canExpandBackward = function(range) {
var caretRange = range.cloneRange();
if (range.startOffset == 0) {
return false;
}
caretRange.setStart(range.startContainer, range.startOffset - 1);
caretRange.setEnd(range.startContainer, range.startOffset);
if (!caretRange.toString().match(/\w/)) {
return false;
}
return true;
// Can't expand if focus is not a text node
if (!range.endContainer.nodeType == 3) {
return false;
}
var caretRange = range.cloneRange();
if (range.startOffset == 0) {
return false;
}
caretRange.setStart(range.startContainer, range.startOffset - 1);
caretRange.setEnd(range.startContainer, range.startOffset);
if (!caretRange.toString().match(/\w/)) {
return false;
}
return true;
};

ZSSEditor.canExpandForward = function(range) {
var caretRange = range.cloneRange();
if (range.endOffset == range.endContainer.length) {
return false;
}
caretRange.setStart(range.endContainer, range.endOffset);
caretRange.setEnd(range.endContainer, range.endOffset + 1);
if (!caretRange.toString().match(/\w/)) {
return false;
}
return true;
// Can't expand if focus is not a text node
if (!range.endContainer.nodeType == 3) {
return false;
}
var caretRange = range.cloneRange();
if (range.endOffset == range.endContainer.length) {
return false;
}
caretRange.setStart(range.endContainer, range.endOffset);
if (range.endOffset )
caretRange.setEnd(range.endContainer, range.endOffset + 1);
var strin = caretRange.toString();
if (!caretRange.toString().match(/\w/)) {
return false;
}
return true;
};

ZSSEditor.getSelectedTextToLinkify = function() {
Expand Down Expand Up @@ -818,12 +828,25 @@ ZSSEditor.insertHTMLWrappedInParagraphTags = function(html) {
this.insertHTML(paragraphOpenTag + space + paragraphCloseTag);
};

// Needs addClass method

ZSSEditor.insertLink = function(url, title) {
var html = '<a href="' + url + '">' + title + "</a>";

if (this.getFocusedField().getHTML().length == 0) {
var parentBlockQuoteNode = ZSSEditor.closerParentNodeWithName('blockquote');

var currentRange = document.getSelection().getRangeAt(0);
var currentNode = currentRange.startContainer;
var currentNodeIsEmpty = (currentNode.innerHTML == '' || currentNode.innerHTML == '<br>');

var selectionIsAtStartOrEnd = Util.rangeIsAtStartOfParent(currentRange) || Util.rangeIsAtEndOfParent(currentRange);

if (this.getFocusedField().getHTML().length == 0
|| (parentBlockQuoteNode && !currentNodeIsEmpty && selectionIsAtStartOrEnd)) {
// Wrap the link tag in paragraph tags when the post is empty, and also when inside a blockquote
// The latter is to fix a bug with document.execCommand('insertHTML') inside a blockquote, where the div inside
// the blockquote is ignored and the link tag is inserted outside it, on a new line with no wrapping div
// Wrapping the link in paragraph tags makes insertHTML join it to the existing div, for some reason
// We exclude being on an empty line inside a blockquote and when the selection isn't at the beginning or end
// of the line, as the fix is unnecessary in both those cases and causes paragraph formatting issues
html = Util.buildOpeningTag(this.defaultParagraphSeparator) + html;
}

Expand Down Expand Up @@ -1037,15 +1060,15 @@ ZSSEditor.setProgressOnMedia = function(mediaNodeIdentifier, progress) {
var mediaNode = this.getMediaNodeWithIdentifier(mediaNodeIdentifier);
var mediaProgressNode = this.getMediaProgressNodeWithIdentifier(mediaNodeIdentifier);

if (progress == 0) {
mediaNode.addClass("uploading");
}

// Don't allow the progress bar to move backward
if (mediaNode.length == 0 || mediaProgressNode.length == 0 || mediaProgressNode.attr("value") > progress) {
return;
}

if (progress == 0) {
mediaNode.addClass("uploading");
}

// Revert to non-compatibility image container once image upload has begun. This centers the overlays on the image
// (instead of the screen), while still circumventing the small container bug the compat class was added to fix
if (progress > 0) {
Expand Down Expand Up @@ -2579,7 +2602,7 @@ ZSSEditor.previousNode = function(node) {
return node;
}
var parent = node.parentNode;
if (parent && parent.nodeType.hasChildNodes()) {
if (parent && parent.hasChildNodes()) {
return parent;
}
return null;
Expand All @@ -2606,8 +2629,24 @@ ZSSEditor.completeListEditing = function() {
if (node.nodeType == 1 &&
(node.tagName.toUpperCase() == NodeName.UL
|| node.tagName.toUpperCase() == NodeName.OL)) {
// Make a new P node as a sibling to the parent node
document.execCommand('insertParagraph', false);

var focusedNode = document.getSelection().getRangeAt(0).startContainer;

if (focusedNode.nodeType == 3) {
// If the focused node is a text node, the list item was not empty when toggled off
// Wrap the text in a div and attach it as a sibling to the div wrapping the list
var parentParagraph = focusedNode.parentNode;
var paragraph = document.createElement('div');

paragraph.appendChild(focusedNode);
parentParagraph.insertAdjacentElement('afterEnd', paragraph);

ZSSEditor.giveFocusToElement(paragraph, 1);
} else {
// Attach a new paragraph node as a sibling to the parent node
document.execCommand('insertParagraph', false);
}

// Remove any superfluous <br> tags that are created
ZSSEditor.scrubBRFromNode(node.parentNode);
break;
Expand Down
13 changes: 13 additions & 0 deletions libs/editor-common/assets/editor-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function Util () {}

/* Tag building */

Util.buildOpeningTag = function(tagName) {
return '<' + tagName + '>';
};
Expand All @@ -10,4 +12,15 @@ Util.buildClosingTag = function(tagName) {

Util.wrapHTMLInTag = function(html, tagName) {
return Util.buildOpeningTag(tagName) + html + Util.buildClosingTag(tagName);
};

/* Selection */

Util.rangeIsAtStartOfParent = function(range) {
return (range.startContainer.previousSibling == null && range.startOffset == 0);
};

Util.rangeIsAtEndOfParent = function(range) {
return ((range.startContainer.nextSibling == null || range.startContainer.nextSibling == "<br>")
&& range.endOffset == range.endContainer.length);
};

0 comments on commit 4542685

Please sign in to comment.