Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TUP-703 TACC Home Banner Links Open in New Window #805

Merged
merged 7 commits into from
Mar 1, 2024
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
/**
* Whether to log debug info to console
* @const {string}
*/
const SHOULD_DEBUG = window.DEBUG;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah. Control the burn. The SHOULD_DEBUG is still used. Also, the jsDoc block (a docblock) is still accurate.

Copy link
Collaborator Author

@R-Tomas-Gonzalez R-Tomas-Gonzalez Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored via cbad538


/**
* Function to perform after setting link target
* @callback setTargetCallback
* @param {HTMLElement} link
*/

/**
* Set external links (automatically discovered) to open in new tab
* @param {object} [options] - Optional parameters
* @param {array.<string>} [options.pathsToExernalSite=[]] - (DEPRECATED) A list of relative URL paths that should be treated like external URLs
* @param {array.<string|RegExp>} [options.pathsToForceSetTarget=[]] - A list of relative URL paths (or patterns) that should trigger setting a target
* @param {HTMLElement|Document} [options.scopeElement=document] - The element within which to search for links
* @param {setTargetCallback} [options.setTargetCallback] - A callback for after a target is set
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please retain the docblock sans @param lines. The function description is still accurate.

Docblocks are written in jsDoc format. They provide manual definitions (in lieu of TypeScript), and can be used to auto-generate documentation e.g. vite.js on jsdocs.io.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored via cbad538 without params.

export default function findLinksAndSetTargets(options) {
const defaults = {
target: '_blank',
pathsToExernalSite: [],
pathsToForceSetTarget: [],
scopeElement: document
}
const {target, pathsToExernalSite, scopeElement, setTargetCallback} = {...defaults, ...options};
let {pathsToForceSetTarget} = {...defaults, ...options};

if ( pathsToExernalSite.length && ! pathsToForceSetTarget.length ) {
pathsToForceSetTarget = pathsToExernalSite;
}

export default function findLinksAndSetTargets() {
const links = scopeElement.getElementsByTagName('a');
const baseDocumentHost = document.location.host;
const baseDocumentHostWithSubdomain= `www.${baseDocumentHost}`;
Expand Down