jQuery(document).ready(function ($) { var $chooser = jQuery("#stylechooser"); var $container = jQuery("#slideContainer") var $body = jQuery('body'); var isLoaded = false; var pathname = window.location.pathname; var themeName = 'ct_corpress.' + pathname; //hidden by default if (getCookie(themeName + '.switcher') != 'show') { hideStyleswitcher(); } /** style chooser show/hide **/ jQuery("#stylechooser #styleToggle").click(function () { if(jQuery("body").is(".navbar-sidebar")) { setCookie(themeName + '.switcher', $chooser.css('right') == '0px' || $chooser.css('right') == '-1px' ? 'hide' : 'show'); } else { setCookie(themeName + '.switcher', $chooser.css('left') == '0px' || $chooser.css('left') == '-1px' ? 'hide' : 'show'); } hideStyleswitcher(); return false; }); jQuery('#demoReset').click(function () { setCookie('ct_corpress', false); location.reload(true); return false; }); jQuery('#stylechooser [data-value]').click(function (event) { var a = jQuery(this); if (a.attr('data-dependent')) { jQuery(a.attr('data-dependent')).click(); } var c = a.attr('data-value'); var off = $body.hasClass(c) && !a.hasClass('btn'); jQuery('[data-value]', a.parents('div.mkSpace')).each(function () { var t = jQuery(this).removeClass('demoActive btn-primary'); $body.removeClass(t.attr('data-value')); }); if (off) { $body.removeClass(c); a.removeClass('demoActive'); a.removeAttr('checked'); //clear container if (a.attr('data-clear-container-deselected') !== undefined) { jQuery(a.attr('data-clear-container-deselected')).find('.demoActive').toggleClass('demoActive'); } store(); if (isLoaded && a.attr('data-refresh')) { location.reload(true); } return false; } $body.addClass(c); if (a.hasClass('btn')) { a.addClass('btn-primary'); } else { a.toggleClass('demoActive'); } if (a.attr('type') == 'checkbox') { a.attr('checked', true); } store(); if (isLoaded && a.attr('data-refresh')) { location.reload(true); } return false; }); /** * Store data */ function store() { var r = ''; jQuery('a[data-value].btn-primary, [data-value].demoActive', $chooser).each(function () { var a = jQuery(this); r = r + a.attr('data-value') + '.'; }); setCookie('ct_corpress', r); } function load() { d = getCookie('ct_corpress'); if (d) { var data = jQuery(d.split('.')); jQuery.each(data, function (e, val) { $e = jQuery('[data-value="' + val + '"]', $chooser); /*if($e.attr('type')=='checkbox'){ $e.attr('checked','checked'); } else {*/ $e.click(); /*}*/ }); } isLoaded = true; } function hideStyleswitcher() { var $switcher = jQuery("#stylechooser"); if(jQuery("body").is(".navbar-sidebar")) { var right = -222; if (parseInt($switcher.css("right")) == right) { right = 0; } if (!isLoaded) { $switcher.css('right', right); } else { $switcher.animate({ right: right }); } } else { var left = -222; if (parseInt($switcher.css("left")) == left) { left = 0; } if (!isLoaded) { $switcher.css('left', left); } else { $switcher.animate({ left: left }); } } } load(); }); /** * Cookie handler - setter */ var setCookie = function (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=/"; }; /** * Cookie handler -getter */ var getCookie = function (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; };