DidouS

walsworth yearbook js

Aug 26th, 2020 (edited)
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function setCookie(cname, cvalue, exdays) {
  2.     var d = new Date();
  3.     d.setTime(d.getTime() + (exdays*24*60*60*1000));
  4.     var expires = "expires="+d.toUTCString();
  5.     document.cookie = cname + "=" + cvalue + "; " + expires;
  6. }
  7.  
  8. function getCookie(cname) {
  9.     var name = cname + "=";
  10.     var ca = document.cookie.split(';');
  11.     for(var i=0; i<ca.length; i++) {
  12.         var c = ca[i];
  13.         while (c.charAt(0)==' ') c = c.substring(1);
  14.         if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
  15.     }
  16.     return "";
  17. }
  18.  
  19.  function getUrlVar(key){
  20.     var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
  21.     return result && unescape(result[1]) || "";
  22. }
  23.  
  24.  
  25. // this controls the user dialog modal.
  26. function launchModal(id) {
  27.  
  28.         //Get the screen height and width
  29.         var maskHeight = $(document).height();
  30.         var maskWidth = $(window).width();
  31.  
  32.         //Set height and width to mask to fill up the whole screen
  33.         $('#mask').css({'width':maskWidth,'height':maskHeight});
  34.  
  35.         //transition effect
  36.         $('#mask').fadeIn(200);
  37.         $('#mask').fadeTo("slow",0.8);
  38.  
  39.         //Get the window height and width
  40.         var winH = $(window).height();
  41.         var winW = $(window).width();
  42.  
  43.         //Set the popup window to center
  44.         $(id).css('top',  winH/2-$(id).height()/2);
  45.         $(id).css('left', winW/2-$(id).width()/2);
  46.  
  47.         //transition effect
  48.         $(id).fadeIn(200);
  49.  
  50.     //if close button is clicked
  51.     $('.window .close').click(function (e) {
  52.         //Cancel the link behavior
  53.         e.preventDefault();
  54.         $('#mask, .window').hide();
  55.     });
  56.  
  57.     //if mask is clicked
  58.     $('#mask').click(function () {
  59.         $(this).hide();
  60.         $('.window').hide();
  61.     });
  62.  
  63. };
  64.  
  65.  
  66. // this sets cookie = to url params season and designplatform
  67. // keeps the cookie until it is set again by url variables
  68. var season = getUrlVar('season');
  69. var dp = getUrlVar('designplatform');
  70. var booksize = getUrlVar('booksize');
  71.  
  72. // if url param is set put it in the cookie.
  73. if(season) {
  74.     this.setCookie('season', season, 365);
  75. }
  76.  
  77. if(dp) {
  78.     this.setCookie('designplatform', dp, 365);
  79. }
  80.  
  81. if(booksize) {
  82.     this.setCookie('booksize', booksize, 365);
  83. }
  84.  
  85. //  if cookie is set show hide classes
  86. var seaCookie = getCookie('season');
  87. var dpCookie = getCookie('designplatform');
  88. var booksizeCookie = getCookie('booksize');
  89.  
  90. /* hide all DOM elements that have either sping, fall, indesign or online */
  91. $( '.spring, .fall, .indesign, .online' ).addClass( 'yb-hidden' );
  92. /* now remove that class from the one that matches both selected settings only */
  93. $( '.' + seaCookie + '.' + dpCookie ).removeClass( 'yb-hidden' );
  94.  
  95. /* Add classes for season and design platform to body */
  96. $('body').addClass('season-' + seaCookie);
  97. $('body').addClass('dp-' + dpCookie);
  98.  
  99. if(booksizeCookie) {
  100.     /* reset all bs-* classes to hide */
  101.     $( '[class^="bs-"]').css( 'display' , 'none' );
  102.     /* display the size set in booksizeCookie */
  103.     $( '[class="bs-'+ booksizeCookie +'"]' ).css( 'display', 'block' );
  104. }
  105.  
  106. $('body').addClass('booksize-' + booksizeCookie);
  107.  
  108. // if no cookies are set pop modal
  109. if(!seaCookie || !dpCookie || !booksizeCookie){
  110.     this.launchModal('#userPrefsDialog');
  111. }
  112.  
  113. /*
  114.     callback to open the plugin page with the booksize set in the Cookie
  115.     use booksize 7 when not set for some reason as a default
  116. */
  117. function plugin_page_opener() {
  118.     // booksizeCookie should be set available because it is set on a higher scope. If not, revert to default.
  119.     if (booksizeCookie) {
  120.         window.location = '/indesign-size-' + booksizeCookie + '-enhancements/';
  121.     } else {
  122.         window.location = "/indesign-size-7-enhancements/";
  123.     }
  124.     return void(0);
  125. }
  126.  
  127. // This code adds multiple columns for the accordion menu on the landing page
  128. function menuColumnWrapper(menuDiv, columnSize) {
  129.  
  130.     // gets list of menu items
  131.     var $menuItems = $(menuDiv + " > li");
  132.  
  133.     for (var x = 0; x < $menuItems.length; x++) {
  134.  
  135.             // get the class of each menu item
  136.             var $menuItemClass = $($menuItems[x]).attr("class");
  137.  
  138.             // get the last class from each menu item
  139.             var $lastClass = $menuItemClass.split(' ').pop();
  140.  
  141.             // gets list of li under the menu item
  142.             var $li = $(menuDiv + " li." + $lastClass + " ul li");
  143.  
  144.             // console.log($li);
  145.  
  146.             // defines wrapper div
  147.             var $div = $("<div/>", { class: 'menuColumnDiv' });
  148.  
  149.                 // loops over each li increments i by columnSize
  150.                 for (var i = 0; i < $li.length; i = i + columnSize) {
  151.  
  152.                     // console.log(i);
  153.  
  154.                     // wraps the current li group into a div
  155.                     $li.slice(i, i + columnSize).wrapAll($div);
  156.                 }
  157.  
  158.     }
  159. }
  160.  
  161. // wraps the top menu
  162. menuColumnWrapper('#menu-landing', 5);
  163.  
  164. // wraps the accordion menu
  165. menuColumnWrapper('#menu-landing-1', 5);
  166.  
  167.  
Add Comment
Please, Sign In to add comment