JAVASCRIPT   63

general 2012

Guest on 20th August 2022 12:55:00 AM

  1. // AJM  - cloned general-2012.js from general.js
  2. //                   as part of new responsive web design (RWD) functionality.
  3. //                   Only used by main  layouts, not forms, harbours or TDA.
  4. // AJM - removed Jquery try/catch from bottom for .external links
  5.  
  6. function setViewportWidth(width)
  7. {
  8.   var metatags = document.getElementsByTagName('meta');
  9.   for (i = 0; i < metatags.length; i++)
  10.   {
  11.     var element = metatags[i];
  12.     if (element.getAttribute('name') == 'viewport')
  13.         {
  14.       element.setAttribute('content','width=' + width);
  15.     }
  16.   }
  17. }
  18.  
  19. function jsCookieWrite(name, value, daysToExpiry)
  20. {
  21.   var cookie = name + "=" + value + ";path=/;";
  22.   var expires = new Date((new Date()).getTime() + (daysToExpiry * 24 * 60 * 60 * 1000));
  23.   cookie += "expires=" + expires.toGMTString() + ";";
  24.   document.cookie = cookie;
  25. }
  26.  
  27. function jsCookieRead(name) {
  28.   var value = null;
  29.   var reg = new RegExp("\\b" + name + "\\b");
  30.   var cookies = document.cookie.split(";");
  31.   for (var i = 0; i < cookies.length; i++)
  32.   {
  33.     var cookie = cookies[i].split("=");
  34.     if (reg.test(cookie[0]))
  35.     {
  36.       value = cookie[1];
  37.       break;
  38.     }
  39.   }
  40.   return value;
  41. }
  42.  
  43. function viewMobile()
  44. {
  45.   var i, ss;
  46.   var ss = document.getElementsByTagName("link");
  47.   for (i = 0; i < ss.length; i++)
  48.   {
  49.     if (ss[i].getAttribute("rel").indexOf("style") != -1 &&
  50.             ss[i].getAttribute("title") == "mobilecss")
  51.     {
  52.       ss[i].disabled = false;
  53.     }
  54.   }
  55.   jsCookieWrite('DisableMobileStyle', 'no', -7);
  56.   setViewportWidth('device-width, initial-scale=1');
  57. }
  58.  
  59. function viewDesktop()
  60. {
  61.   var i, ss;
  62.   var ss = document.getElementsByTagName("link");
  63.   for (i = 0; i < ss.length; i++)
  64.   {
  65.     if (ss[i].getAttribute("rel").indexOf("style") != -1 &&
  66.             ss[i].getAttribute("title") == "mobilecss");
  67.     {
  68.       ss[i].disabled = true;
  69.          
  70.     }
  71.   }
  72.   jsCookieWrite('DisableMobileStyle', 'yes', 7);
  73.   setViewportWidth('1180');
  74. }

Raw Paste


Login or Register to edit or fork this paste. It's free.