/* ****************************** * * StyleSwitcher Script * * Author: Pixel Industry * ******************************* */ jQuery(document).ready(function ($) { var relativeDir = VolcannoConfigLive.styleswitcher_relative + "/"; var themeName = VolcannoConfigLive.theme_name; /* *************************************** * Reading Cookies for stored values *******************************************/ (function () { var styleSwitcherCookie = "ss" + themeName + "WpStyleSwitcher"; if (readCookie(styleSwitcherCookie) != "0") { var status = readCookie(styleSwitcherCookie); //$('#style-switcher').removeClass('opened'); pi_switcher_slide(0); } var styleCookie = "ss" + themeName + "WpStyle"; if (readCookie(styleCookie) != null) { var styleVal = readCookie(styleCookie); changeStyle(styleVal); } })(); /* *************************************** * SlideIn and SlideOut animation on click *******************************************/ $('#styles-button').on('click', function (e) { e.preventDefault(); if ($('#style-switcher').hasClass('opened')) { pi_switcher_slide("1"); } else { pi_switcher_slide("0"); } }); /* ****************** * Style Changing *********************/ $('.styles-list li').on('click', function (e) { e.preventDefault(); var styleCookie = "ss" + themeName + "WpStyle"; var styleVal = $(this).attr('class'); changeStyle(styleVal); createCookie(styleCookie, styleVal, 7); }); function changeStyle(styleVal) { var colorStyle = relativeDir + '/css/' + styleVal + '.css'; $('#volcanno-color-style-css').attr('href', colorStyle); } function pi_switcher_slide(status) { var switcherWidth = $('#style-switcher').width(); var styleSwitcherCookie = "ss" + themeName + "WpStyleSwitcher"; if (status == "1") { $('#style-switcher').animate({ left: -switcherWidth }, 700, function () { $(this).removeClass('opened'); }); createCookie(styleSwitcherCookie, '0', 7); } else { $('#style-switcher').animate({ left: 0 }, 700, function () { $(this).addClass('opened'); }); createCookie(styleSwitcherCookie, '1', 7); } } function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else var expires = ""; document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { var nameEQ = name + "="; 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, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function eraseCookie(name) { createCookie(name, "", -1); } });