Skip to content

Commit 6c76952

Browse files
committed
Open links on new tab
1 parent 32e222f commit 6c76952

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

ESSArch_TA/frontend/static/frontend/scripts/controllers/VersionCtrl.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,18 @@ angular.module('myApp').controller('VersionCtrl', function($scope, myService, $w
3030
$window.open('http://www.essolutions.se', '_blank');
3131
};
3232
$scope.scrollToLink = function(link) {
33-
$location.hash(link);
34-
$anchorScroll();
33+
if(!isURL(link)) {
34+
$location.hash(link);
35+
$anchorScroll();
36+
} else {
37+
$window.open(link, '_blank');
38+
return true;
39+
}
40+
}
41+
function isURL(str) {
42+
var urlRegex = '^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$';
43+
var url = new RegExp(urlRegex, 'i');
44+
return str.length < 2083 && url.test(str);
3545
}
3646
$scope.docs = $translate.instant('DOCS');
3747
$scope.sysInfo = $translate.instant('SYSTEMINFORMATION');

0 commit comments

Comments
 (0)