Created
December 20, 2021 02:57
-
-
Save bryanjvolz/a63a28c02d4f3cda0ff76fa9eca3b7af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** CWS Custom Pathing | |
** listen for incoming traffic from corp site and if it contains the department filter query, set localStorage, and make sure the value persists on search | |
** unless deselected or homepage is visited | |
*/ | |
function cwsCustomPathing(){ | |
const queryString = window.location.search; | |
const urlParams = new URLSearchParams(queryString); | |
var department = urlParams.getAll('department[]');//requires brackets per search api | |
if ( (document.referrer.toLowerCase().indexOf('www.CORPSITEURL.com') > -1) && (department) ) { | |
if ( (sessionStorage.getItem('pathingCatalog') === null) || (typeof sessionStorage.getItem('pathingCatalog') === "undefined")) { | |
var params = JSON.stringify(urlParams.getAll('department[]')); | |
sessionStorage.setItem('pathingCatalog', params); | |
} | |
} else if ( (document.referrer.toLowerCase().indexOf('www.CORPSITEURL.com') > -1) && (queryString === "") ){ | |
//remove local storage if referred from corp site but no params | |
removePathing(); | |
} | |
//Remove on filter update | |
$('#cws_quickjobsearch_department').on('change',function(){ | |
console.log('cws_quickjobsearch_department change event'); | |
removePathing(); | |
}); | |
$('body.home .quicksearch-submit').on('click',function(){ | |
removePathing(); | |
}); | |
function removePathing(){ | |
sessionStorage.removeItem('pathingCatalog'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment