Skip to content

Instantly share code, notes, and snippets.

@joeldenning
Last active July 6, 2018 03:29
Show Gist options
  • Save joeldenning/80ea0a4b5bdd302ae2eb01cb4d300b61 to your computer and use it in GitHub Desktop.
Save joeldenning/80ea0a4b5bdd302ae2eb01cb4d300b61 to your computer and use it in GitHub Desktop.
/* Util functions
*/
/* Use this function to check that the hash begins with a certain prefix
*/
export function hashPrefix(location, ...prefixes) {
return prefixes.some(prefix => location.hash.indexOf(`#/${prefix}`) === 0);
}
/* App-specific implementations that determine if they are active or not.
*/
export function endUserFormsUI(location) {
return hashPrefix(location, 'forms') && !pageNotFound();
}
export function smeQAUI(location) {
return hashPrefix(location, 'testing') && !pageNotFound();
}
export function lettersUI(location) {
return hashPrefix(location, 'letters') && !pageNotFound();
}
export function docsUI(location) {
return (hashPrefix(location, "docs") || hashPrefix(location, "files")) && !pageNotFound();
}
export function notificationsUI(location) {
return hashPrefix(location, "notifications") && !pageNotFound();
}
export function pageNotFound() {
//This try catch is to help us with some undiagnosable IE/Edge issue.
//Some how this code was causing an "Unspecified error"
//So we're going to make the assumption that we should return false if it were to die here.
try {
return window.history && window.history.state && window.history.state.pageNotFound;
} catch(e) {
return false;
}
}
export function communicationsUI(location) {
return hashPrefix(location, "communications") && !pageNotFound();
}
// .... And more like this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment