Advertisement
CarterFromSL

FJ Location Javascript

Feb 16th, 2021
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*-- this code runs on each page of the site --*/
  2.  
  3. window.onload = function() {
  4.  
  5.     /*-- gets the current year for the footer copyright text --*/
  6.     document.getElementById("getYear").innerHTML = new Date().getFullYear();
  7.  
  8.     /*-- checks if the cookie "userhome" is present with a set value, then unhides header and footer elements if a cookie with that value is found --*/
  9.     if (document.cookie.split(';').some((item) => item.includes('userhome=rochdale'))) {
  10.         document.getElementById('menu-item-2542').classList.remove("hidden");
  11.         document.getElementById("footerRochdale").classList.remove("footer-hidden");
  12.     }
  13.     else if (document.cookie.split(';').some((item) => item.includes('userhome=aurora'))) {
  14.         document.getElementById('menu-item-2556').classList.remove("hidden");
  15.         document.getElementById("footerAurora").classList.remove("footer-hidden");
  16.     }
  17.     else if (document.cookie.split(';').some((item) => item.includes('userhome=grantpark'))) {
  18.         document.getElementById('menu-item-2541').classList.remove("hidden");
  19.         document.getElementById("footerGrantpark").classList.remove("footer-hidden");
  20.     }
  21.     else if (document.cookie.split(';').some((item) => item.includes('userhome=southdale'))) {
  22.         document.getElementById('menu-item-2558').classList.remove("hidden");
  23.         document.getElementById("footerSouthdale").classList.remove("footer-hidden");
  24.     }
  25.     else if (document.cookie.split(';').some((item) => item.includes('userhome=eighth'))) {
  26.         document.getElementById('menu-item-2557').classList.remove("hidden");
  27.         document.getElementById("footerEighth").classList.remove("footer-hidden");
  28.     }
  29.  
  30.     /*-- else: if no "userhome" cookie is found, unhides the CTA to select a location --*/
  31.     else {
  32.         document.getElementById('menu-item-2554').classList.remove("hidden");
  33.         document.getElementById("footerNohome").classList.remove("footer-hidden");
  34.     }
  35. }
  36.  
  37.  
  38. /*-- this code is only present on individual location pages --*/
  39.  
  40. /*-- defines the function to create cookies, runs when a button is clicked, then hides the button and displays a welcome message --*/
  41. function setCookie(cname,cvalue,exdays) {
  42.         var d = new Date();
  43.         d.setTime(d.getTime() + (exdays*24*60*60*1000));
  44.         var expires = "; expires="+d.toUTCString();
  45.         document.cookie = cname+"="+cvalue+expires+"; path=/";
  46.         var setLocation = document.getElementById('setlocation');
  47.         var welcomeMsg = document.getElementById('welcome');
  48.         setLocation.className = "current";
  49.         welcomeMsg.className = "display";
  50. }
  51.  
  52. /*-- this code runs when a location page is loaded, it checks if the cookie for that location is present, then hides the button and displays a welcome message if it is found --*/
  53. function isCurrent() {
  54.     if (document.cookie.split(';').some((item) => item.includes('userhome=LOCATION'))) {
  55.         var setLocation = document.getElementById('setlocation');
  56.         var welcomeMsg = document.getElementById('welcome');
  57.         setLocation.className = "current";
  58.         welcomeMsg.className = "display";
  59.     }
  60. }
  61.  
  62. window.onload = isCurrent();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement