Esanders has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/344680 )
Change subject: Resolve URLs in DiffElement links and target at new window
......................................................................
Resolve URLs in DiffElement links and target at new window
Introduces ve.targetLinksToNewWindow utility function as we now
have use 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
3 files changed, 16 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/80/344680/1
diff --git a/src/ui/elements/ve.ui.DiffElement.js
b/src/ui/elements/ve.ui.DiffElement.js
index ed363cf..447ccdb 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 00dc8a0..0268b98 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.
--
To view, visit https://gerrit.wikimedia.org/r/344680
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3088e8b95d9032b8e8fd5bff58a8b97ffaa15f98
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits