-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 1 commit
cb8aa4a
02d04ee
0a46845
72e3d15
cbad538
d295fac
9b2a0a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
||
/** | ||
* 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 | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please retain the docblock sans 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}`; | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Click this: 🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restored via cbad538