Skip to content

Commit

Permalink
Merge pull request #117 from Lombiq/issue/OSOE-576
Browse files Browse the repository at this point in the history
OSOE-576: Fixing target-blank.js
  • Loading branch information
0liver authored Feb 22, 2023
2 parents 5af1a3d + dbbe57e commit 7a3d02c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1,322 deletions.
18 changes: 8 additions & 10 deletions Lombiq.HelpfulExtensions/Assets/Scripts/target-blank.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
(function initTargetBlank() {
function targetBlank() {
function addTargetBlank() {
const links = document.querySelectorAll('a');
const currentHostname = window.location.hostname;

for (let i = 0; i < links.length; i++) {
if (!links[i].href.match(/^mailto:/) &&
(links[i].hostname !== currentHostname &&
(!links[i].href.match(/^javascript:/i)))) {
if (links[i].hostname !== currentHostname &&
// The no-script-url rule triggers to prevent the usage of javascript: URLs.
// In the current script, we are not using them.
// eslint-disable-next-line no-script-url
!links[i].href.startsWith('javascript:') &&
!links[i].href.startsWith('mailto:')) {
links[i].setAttribute('target', '_blank');
}
}
}
window.addEventListener(
'load',
() => {
window.setTimeout(targetBlank, 100);
},
false);
document.addEventListener('DOMContentLoaded', addTargetBlank);
})();
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Lombiq.HelpfulExtensions;

public class ResourceManagementOptionsConfiguration : IConfigureOptions<ResourceManagementOptions>
{
private const string WwwRoot = "~/Lombiq.HelpfulExtensions/";
private const string ScriptRoot = "~/Lombiq.HelpfulExtensions/js/";
private static readonly ResourceManifest _manifest = new();

static ResourceManagementOptionsConfiguration() =>
_manifest
.DefineScript(TargetBlank)
.SetUrl(WwwRoot + "scripts/target-blank.min.js", WwwRoot + "scripts/target-blank.js")
.SetUrl(ScriptRoot + "target-blank.min.js", ScriptRoot + "target-blank.js")
.SetVersion("1.0.0");

public void Configure(ResourceManagementOptions options) => options.ResourceManifests.Add(_manifest);
Expand Down
14 changes: 0 additions & 14 deletions Lombiq.HelpfulExtensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,5 @@
"build:scripts": "npm explore nodejs-extensions -- pnpm build:scripts",
"clean:scripts": "npm explore nodejs-extensions -- pnpm clean:scripts",
"watch:scripts": "npm explore nodejs-extensions -- pnpm watch:scripts"
},
"nodejsExtensions": {
"scripts": {
"source": "Assets/Scripts",
"target": "wwwroot/scripts"
}
},
"devDependencies": {
"eslint": "^8.25.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-only-warn": "^1.0.3",
"eslint-plugin-promise": "^6.1.0"
}
}
Loading

0 comments on commit 7a3d02c

Please sign in to comment.