Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setCookie(cname, cvalue, exdays) {
- var d = new Date();
- d.setTime(d.getTime() + (exdays*24*60*60*1000));
- var expires = "expires="+d.toUTCString();
- document.cookie = cname + "=" + cvalue + "; " + expires;
- }
- function getCookie(cname) {
- var name = cname + "=";
- var ca = document.cookie.split(';');
- for(var i=0; i<ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0)==' ') c = c.substring(1);
- if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
- }
- return "";
- }
- function getUrlVar(key){
- var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
- return result && unescape(result[1]) || "";
- }
- // this controls the user dialog modal.
- function launchModal(id) {
- //Get the screen height and width
- var maskHeight = $(document).height();
- var maskWidth = $(window).width();
- //Set height and width to mask to fill up the whole screen
- $('#mask').css({'width':maskWidth,'height':maskHeight});
- //transition effect
- $('#mask').fadeIn(200);
- $('#mask').fadeTo("slow",0.8);
- //Get the window height and width
- var winH = $(window).height();
- var winW = $(window).width();
- //Set the popup window to center
- $(id).css('top', winH/2-$(id).height()/2);
- $(id).css('left', winW/2-$(id).width()/2);
- //transition effect
- $(id).fadeIn(200);
- //if close button is clicked
- $('.window .close').click(function (e) {
- //Cancel the link behavior
- e.preventDefault();
- $('#mask, .window').hide();
- });
- //if mask is clicked
- $('#mask').click(function () {
- $(this).hide();
- $('.window').hide();
- });
- };
- // this sets cookie = to url params season and designplatform
- // keeps the cookie until it is set again by url variables
- var season = getUrlVar('season');
- var dp = getUrlVar('designplatform');
- var booksize = getUrlVar('booksize');
- // if url param is set put it in the cookie.
- if(season) {
- this.setCookie('season', season, 365);
- }
- if(dp) {
- this.setCookie('designplatform', dp, 365);
- }
- if(booksize) {
- this.setCookie('booksize', booksize, 365);
- }
- // if cookie is set show hide classes
- var seaCookie = getCookie('season');
- var dpCookie = getCookie('designplatform');
- var booksizeCookie = getCookie('booksize');
- /* hide all DOM elements that have either sping, fall, indesign or online */
- $( '.spring, .fall, .indesign, .online' ).addClass( 'yb-hidden' );
- /* now remove that class from the one that matches both selected settings only */
- $( '.' + seaCookie + '.' + dpCookie ).removeClass( 'yb-hidden' );
- /* Add classes for season and design platform to body */
- $('body').addClass('season-' + seaCookie);
- $('body').addClass('dp-' + dpCookie);
- if(booksizeCookie) {
- /* reset all bs-* classes to hide */
- $( '[class^="bs-"]').css( 'display' , 'none' );
- /* display the size set in booksizeCookie */
- $( '[class="bs-'+ booksizeCookie +'"]' ).css( 'display', 'block' );
- }
- $('body').addClass('booksize-' + booksizeCookie);
- // if no cookies are set pop modal
- if(!seaCookie || !dpCookie || !booksizeCookie){
- this.launchModal('#userPrefsDialog');
- }
- /*
- callback to open the plugin page with the booksize set in the Cookie
- use booksize 7 when not set for some reason as a default
- */
- function plugin_page_opener() {
- // booksizeCookie should be set available because it is set on a higher scope. If not, revert to default.
- if (booksizeCookie) {
- window.location = '/indesign-size-' + booksizeCookie + '-enhancements/';
- } else {
- window.location = "/indesign-size-7-enhancements/";
- }
- return void(0);
- }
- // This code adds multiple columns for the accordion menu on the landing page
- function menuColumnWrapper(menuDiv, columnSize) {
- // gets list of menu items
- var $menuItems = $(menuDiv + " > li");
- for (var x = 0; x < $menuItems.length; x++) {
- // get the class of each menu item
- var $menuItemClass = $($menuItems[x]).attr("class");
- // get the last class from each menu item
- var $lastClass = $menuItemClass.split(' ').pop();
- // gets list of li under the menu item
- var $li = $(menuDiv + " li." + $lastClass + " ul li");
- // console.log($li);
- // defines wrapper div
- var $div = $("<div/>", { class: 'menuColumnDiv' });
- // loops over each li increments i by columnSize
- for (var i = 0; i < $li.length; i = i + columnSize) {
- // console.log(i);
- // wraps the current li group into a div
- $li.slice(i, i + columnSize).wrapAll($div);
- }
- }
- }
- // wraps the top menu
- menuColumnWrapper('#menu-landing', 5);
- // wraps the accordion menu
- menuColumnWrapper('#menu-landing-1', 5);
Add Comment
Please, Sign In to add comment