jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/344680 )
Change subject: DiffElement: Resolve URLs in links and target at new window
......................................................................
DiffElement: Resolve URLs in links and target at new window
Introduces ve.targetLinksToNewWindow utility function as we now
have use of this method in three places.
Change-Id: I3088e8b95d9032b8e8fd5bff58a8b97ffaa15f98
---
M src/ui/elements/ve.ui.DiffElement.js
M src/ui/elements/ve.ui.PreviewElement.js
M src/ve.utils.js
M tests/ui/ve.ui.DiffElement.test.js
4 files changed, 18 insertions(+), 6 deletions(-)
Approvals:
jenkins-bot: Verified
Jforrester: Looks good to me, approved
diff --git a/src/ui/elements/ve.ui.DiffElement.js
b/src/ui/elements/ve.ui.DiffElement.js
index e06287e..379735a 100644
--- a/src/ui/elements/ve.ui.DiffElement.js
+++ b/src/ui/elements/ve.ui.DiffElement.js
@@ -284,6 +284,9 @@
}
}
+ ve.resolveAttributes( documentNode, this.newDoc.getHtmlDocument(),
ve.dm.Converter.static.computedAttributes );
+ ve.targetLinksToNewWindow( documentNode );
+
if ( !anyChanges ) {
noChanges = document.createElement( 'div' );
noChanges.setAttribute( 'class', 've-ui-diffElement-no-changes'
);
diff --git a/src/ui/elements/ve.ui.PreviewElement.js
b/src/ui/elements/ve.ui.PreviewElement.js
index 204040c..33f889e 100644
--- a/src/ui/elements/ve.ui.PreviewElement.js
+++ b/src/ui/elements/ve.ui.PreviewElement.js
@@ -76,10 +76,7 @@
ve.dm.Converter.static.computedAttributes
);
- // Make all links open in a new window (sync view)
- Array.prototype.forEach.call( body.querySelectorAll( 'a[href]' ),
function ( el ) {
- el.setAttribute( 'target', '_blank' );
- } );
+ ve.targetLinksToNewWindow( body );
// Move content to element
element.innerHTML = '';
diff --git a/src/ve.utils.js b/src/ve.utils.js
index 5967eb9..434ca63 100644
--- a/src/ve.utils.js
+++ b/src/ve.utils.js
@@ -1016,6 +1016,18 @@
};
/**
+ * Make all links within a DOM element open in a new window
+ *
+ * @param {HTMLElement} container DOM element to search for links
+ */
+ve.targetLinksToNewWindow = function ( container ) {
+ // Make all links open in a new window
+ Array.prototype.forEach.call( container.querySelectorAll( 'a[href]' ),
function ( el ) {
+ el.setAttribute( 'target', '_blank' );
+ } );
+};
+
+/**
* Check if a string is a valid URI component.
*
* A URI component is considered invalid if decodeURIComponent() throws an
exception.
diff --git a/tests/ui/ve.ui.DiffElement.test.js
b/tests/ui/ve.ui.DiffElement.test.js
index 287800f..13c5984 100644
--- a/tests/ui/ve.ui.DiffElement.test.js
+++ b/tests/ui/ve.ui.DiffElement.test.js
@@ -286,7 +286,7 @@
newDoc: '<p>foo <a href="whee">bar</a> baz</p>',
expected:
'<div
class="ve-ui-diffElement-doc-child-change">' +
- '<p>foo <span
data-diff-action="change-remove"><a href="quuz">bar</a></span><span
data-diff-action="change-insert" data-diff-id="0"><a href="whee">bar</a></span>
baz</p>' +
+ '<p>foo <span
data-diff-action="change-remove"><a href="quuz"
target="_blank">bar</a></span><span data-diff-action="change-insert"
data-diff-id="0"><a href="whee" target="_blank">bar</a></span> baz</p>' +
'</div>'
},
{
@@ -295,7 +295,7 @@
newDoc: '<p><a href="#">foo <b>bar</b>
baz</a></p>',
expected:
'<div
class="ve-ui-diffElement-doc-child-change">' +
- '<p><a href="#">foo <del
data-diff-action="remove">bar</del><ins
data-diff-action="insert"><b>bar</b></ins> baz</a></p>' +
+ '<p><a href="#"
target="_blank">foo <del data-diff-action="remove">bar</del><ins
data-diff-action="insert"><b>bar</b></ins> baz</a></p>' +
'</div>'
},
{
--
To view, visit https://gerrit.wikimedia.org/r/344680
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3088e8b95d9032b8e8fd5bff58a8b97ffaa15f98
Gerrit-PatchSet: 3
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits