Skip to content

Commit 58f582e

Browse files
open external links in new window
1 parent 7caac5c commit 58f582e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Client/ContentsViewer/ContentsViewerStandard.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ document.addEventListener("DOMContentLoaded", function() {
6363
searchResultsParent.removeChild(searchResults);
6464
searchBoxInputClearButton.style.display = "none";
6565

66+
document.querySelectorAll('#content-summary a.link, #content-body a.link').forEach(link => OpenExternalLinksInNewWindow(link));
67+
6668
if (relatedResults) {
6769
relatedViewObserver = new IntersectionObserver(function(entries) {
6870
// If intersectionRatio is 0, the target is out of view
@@ -200,12 +202,6 @@ document.addEventListener("DOMContentLoaded", function() {
200202
false
201203
);
202204

203-
// var contentSummary = document.getElementById("content-summary");
204-
// if (contentSummary && contentSummary.textContent.trim() != "") {
205-
// // this.console.log(contentSummary.textContent);
206-
// contentSummary.style.borderBottomColor = "black";
207-
// }
208-
209205
// UpdateCurrentSectionSelection();
210206
JumpToHash(window.location.hash);
211207
OnScroll();
@@ -795,4 +791,9 @@ function OnClickLayerSelector(element, event) {
795791
function RemoveChildElements(parent) {
796792
while (parent.firstChild) parent.removeChild(parent.firstChild);
797793
}
798-
794+
795+
function OpenExternalLinksInNewWindow(link) {
796+
if (link.href.indexOf(location.protocol + '//' + location.hostname) != 0) {
797+
link.target = '_blank';
798+
}
799+
}

Module/OutlineText.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ class Parser {
12891289
["/__(.*?)__/", '<mark>{0}</mark>', null],
12901290
["/~~(.*?)~~/", '<del>{0}</del>', null],
12911291
["/\^\[(.*?)\]/", null, ['OutlineText\Parser','DecodeReferenceElementCallback']],
1292-
["/<((http|https):\/\/[0-9a-z\-\._~%\:\/\?\#\[\]@\!\$&'\(\)\*\+,;\=]+)>/i", '<a href="{0}" class="bare">{0}</a>', null],
1292+
["/<((http|https):\/\/[0-9a-z\-\._~%\:\/\?\#\[\]@\!\$&'\(\)\*\+,;\=]+)>/i", '<a href="{0}" class="bare link">{0}</a>', null],
12931293
["/<(([a-zA-Z0-9])+([a-zA-Z0-9\?\*\[|\]%'=~^\{\}\/\+!#&\$\._-])*@([a-zA-Z0-9_-])+\.([a-zA-Z0-9\._-]+)+)>/", '<a href="mailto:{0}">{0}</a>', null],
12941294
// ["/:([^:]*?)-solid:/",'<i class="fas fa-{0}" title="{0}" aria-hidden="true"></i><span class="sr-only">{0}</span>', null],
12951295
// ["/:([^:]*?)-light:/",'<i class="fal fa-{0}" title="{0}" aria-hidden="true"></i><span class="sr-only">{0}</span>', null],
@@ -1734,7 +1734,7 @@ private static function DecodeLinkElementCallback($matches, $context){
17341734
$linkText = $matches[1][0];
17351735
$url = $context->ReplacePathMacros($matches[2][0]);
17361736

1737-
return '<a href="' . $url .'">' . $linkText . '</a>';
1737+
return '<a href="' . $url .'" class="link">' . $linkText . '</a>';
17381738
}
17391739

17401740
private static function EscapeSpecialCharacters($text) {

0 commit comments

Comments
 (0)