From 1cf141b3362c5c44f27a8b65775d3db27ac5756a Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Mon, 20 Jun 2016 17:00:49 +0200 Subject: [PATCH] Squashed 'libs/editor/' changes from c5f3e9c..b012dc8 b012dc8 Moved removeAllFailedMediaUploads() to generic media method group b910b97 Fixes issue where removeAllFailedMediaUploads only worked for images REVERT: c5f3e9c Merge pull request #420 from wordpress-mobile/issue/409-cursor-under-media REVERT: 4851a46 Merge branch 'develop' into issue/409-cursor-under-media REVERT: 3a88793 Fixed matching for media at the end of posts to work on API18 and below REVERT: 5850256 Add an empty paragraph after media items at the end of posts when converting from HTML git-subtree-dir: libs/editor git-subtree-split: b012dc8446d09fe1721825cdc83cc56b0ddc788d --- .../editor-common/assets/ZSSRichTextEditor.js | 24 ++++++++++++------- .../assets/editor-utils-formatter.js | 4 ---- .../assets/test/test-formatter.js | 6 ++--- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/libs/editor-common/assets/ZSSRichTextEditor.js b/libs/editor-common/assets/ZSSRichTextEditor.js index d6a412fd6a72..6ddf5e9d796c 100755 --- a/libs/editor-common/assets/ZSSRichTextEditor.js +++ b/libs/editor-common/assets/ZSSRichTextEditor.js @@ -1147,6 +1147,22 @@ ZSSEditor.sendOptimisticProgressUpdate = function(mediaNodeIdentifier, nCall) { ZSSEditor.setupOptimisticProgressUpdate(mediaNodeIdentifier, nCall + 1); }; +ZSSEditor.removeAllFailedMediaUploads = function() { + console.log("Remove all failed media"); + var failedMediaArray = ZSSEditor.getFailedMediaIdArray(); + for (var i = 0; i < failedMediaArray.length; i++) { + ZSSEditor.removeMedia(failedMediaArray[i]); + } +}; + +ZSSEditor.removeMedia = function(mediaNodeIdentifier) { + if (this.getImageNodeWithIdentifier(mediaNodeIdentifier).length != 0) { + this.removeImage(mediaNodeIdentifier); + } else if (this.getVideoNodeWithIdentifier(mediaNodeIdentifier).length != 0) { + this.removeVideo(mediaNodeIdentifier); + } +}; + ZSSEditor.sendMediaRemovedCallback = function(mediaNodeIdentifier) { var arguments = ['id=' + encodeURIComponent(mediaNodeIdentifier)]; var joinedArguments = arguments.join(defaultCallbackSeparator); @@ -1514,14 +1530,6 @@ ZSSEditor.removeImage = function(imageNodeIdentifier) { } }; -ZSSEditor.removeAllFailedMediaUploads = function() { - console.log("Remove all failed media"); - var failedMediaArray = ZSSEditor.getFailedMediaIdArray(); - for (var i = 0; i < failedMediaArray.length; i++) { - ZSSEditor.removeImage(failedMediaArray[i]); - } -} - /** * @brief Inserts a video tag using the videoURL as source and posterURL as the * image to show while video is loading. diff --git a/libs/editor-common/assets/editor-utils-formatter.js b/libs/editor-common/assets/editor-utils-formatter.js index d235aec985d0..dc4f67764c57 100644 --- a/libs/editor-common/assets/editor-utils-formatter.js +++ b/libs/editor-common/assets/editor-utils-formatter.js @@ -22,10 +22,6 @@ Formatter.convertPToDiv = function(html) { mutatedHTML = mutatedHTML.replace(/(]*>|<\/a>|<\/video>|<\/span>)
/igm, function replaceBrWithDivs(match) { return match.substr(0, match.length - 6) + '
'; }); - // Append paragraph-wrapped break tag under media at the end of a post - mutatedHTML = mutatedHTML.replace(/(]*>|<\/a>|<\/video>|<\/span>)[^<>]*<\/div>\s$/igm, - function replaceBrWithDivs(match) { return match + '

'; }); - return mutatedHTML; } diff --git a/libs/editor-common/assets/test/test-formatter.js b/libs/editor-common/assets/test/test-formatter.js index a59e61ec0f4d..3bdc8a35f5f9 100644 --- a/libs/editor-common/assets/test/test-formatter.js +++ b/libs/editor-common/assets/test/test-formatter.js @@ -56,7 +56,7 @@ function testMediaParagraphWrapping(mediaType, htmlModeMediaHtml, visualModeMedi assert.equal('

' + visualModeMediaHtml + '

\n', visualFormattingApplied); var convertedToDivs = formatter.convertPToDiv(visualFormattingApplied).replace(/\n/g, ''); - assert.equal('
' + visualModeMediaHtml + '

', convertedToDivs); + assert.equal('
' + visualModeMediaHtml + '
', convertedToDivs); }); it('with paragraphs above and below', function () { @@ -106,7 +106,7 @@ function testMediaParagraphWrapping(mediaType, htmlModeMediaHtml, visualModeMedi assert.equal('

Line 1

\n

' + visualModeMediaHtml + '

\n', visualFormattingApplied); var convertedToDivs = formatter.convertPToDiv(visualFormattingApplied).replace(/\n/g, ''); - assert.equal('
Line 1
' + visualModeMediaHtml + '

', convertedToDivs); + assert.equal('
Line 1
' + visualModeMediaHtml + '
', convertedToDivs); }); it('end of post, with line break above', function () { @@ -116,7 +116,7 @@ function testMediaParagraphWrapping(mediaType, htmlModeMediaHtml, visualModeMedi assert.equal('

Line 1
\n' + visualModeMediaHtml + '

\n', visualFormattingApplied); var convertedToDivs = formatter.convertPToDiv(visualFormattingApplied).replace(/\n/g, ''); - assert.equal('
Line 1
' + visualModeMediaHtml + '

', convertedToDivs); + assert.equal('
Line 1
' + visualModeMediaHtml + '
', convertedToDivs); }); }); }