/* ////////////////////////////////////////////////////////////////////////////////////////////////////// ///// Code mixing by Molokoloco ..... 2011 ......... [EVER IN PROGRESS (it's not done yet)] //////////// //////////////////////////////////////////////////////////////////////////////////////////////////// */ /* // Add Or Switch Stylesheet // Ressources : * Source here : http://home.b2bweb.fr/js/jquery.style.js * Official : http://plugins.jquery.com/project/AddOrSwitchStylesheet * Use cookie manager from : http://plugins.jquery.com/project/cookie // Plugin who load (at the first demand) and switch stylesheet, with cookie : * Manage links to change style * Add stylesheet to head, if not exist * If already exist, switch style with the disabled attribute * Prevent changing styles who are not related to theme : No modification on styles without id attribute * Prevent changing other styles who are not related to theme * Stock and autoload user style preference, with a cookie // HTML
// JS USE CASE $('a.css').styleInit(); // That all ! Wait user click... $.fn.styleSwitch('css/styles.css'); // Direct style change with JS call */ (function($){ $.fn.extend({ styleDisable: function (disabled) { setTimeout(function () { $(disabled).each(function () { $(this).attr('disabled', 'disabled'); }); }, 250); }, styleLoad: function (stylePath) { $('head').append(''); }, styleSwitch: function (stylePath) { var exist = false; var disabled = []; $('link[@rel*=style][id]').each(function () { if (stylePath == $(this).attr('href')) { $(this).removeAttr('disabled'); exist = true; } else disabled.push(this); }); if (exist == false) $.fn.styleLoad(stylePath); $.fn.styleDisable(disabled); $.cookie('css', stylePath, { expires: 365, path: '/' }); }, styleInit: function () { if ($.cookie('css')) { var isSet = false; $('link[rel*=style][id]').each(function () { if ($.cookie('css') == $(this).attr('href')) isSet = true; }); if (isSet == false) $.fn.styleSwitch($.cookie('css')); } return $(this).click(function (event) { event.preventDefault(); $.fn.styleSwitch($(this).attr('rel')); $(this).blur(); }); } }); })(jQuery);