/** * jQuery Theme Switcher plugin * * Copyright (c) 2011 Dave Hoff (davehoff.com) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ (function( $ ){ $.fn.themeswitcher = function( options ) { var switcherDiv = this, switcherOptions = {}; var settings = { loadtheme : "", height: 200, width: 175, rounded: true, imgpath: "", jqueryuiversion: "1.8.10", initialtext: "Switch Theme", buttonpretext: "Theme:", closeonselect: true, buttonheight: 14, themes: [], additionalthemes: [], onopen: null, onclose: null, onselect: null, }; if(options) { //lowercase all options passed in $.each(options, function(k,v){ switcherOptions[k.toLowerCase()] = v; }); $.extend( settings, switcherOptions ); } if( ! settings.themes.length ){ var themes = [ { title: "Black Tie", name: "black-tie", icon: "theme_90_black_tie.png" }, { title: "Blitzer", name: "blitzer", icon: "theme_90_blitzer.png" }, { title: "Cupertino", name: "cupertino", icon: "theme_90_cupertino.png" }, { title: "Dark Hive", name: "dark-hive", icon: "theme_90_dark_hive.png" }, { title: "Dot Luv", name: "dot-luv", icon: "theme_90_dot_luv.png" }, { title: "Eggplant", name: "eggplant", icon: "theme_90_eggplant.png" }, { title: "Excite Bike", name: "excite-bike", icon: "theme_90_excite_bike.png" }, { title: "Flick", name: "flick", icon: "theme_90_flick.png" }, { title: "Hot Sneaks", name: "hot-sneaks", icon: "theme_90_hot_sneaks.png" }, { title: "Humanity", name: "humanity", icon: "theme_90_humanity.png" }, { title: "Le Frog", name: "le-frog", icon: "theme_90_le_frog.png" }, { title: "Mint Choc", name: "mint-choc", icon: "theme_90_mint_choco.png" }, { title: "Overcast", name: "overcast", icon: "theme_90_overcast.png" }, { title: "Pepper Grinder", name: "pepper-grinder", icon: "theme_90_pepper_grinder.png" }, { title: "Redmond", name: "redmond", icon: "theme_90_windoze.png" }, { title: "Smoothness", name: "smoothness", icon: "theme_90_smoothness.png" }, { title: "South Street", name: "south-street", icon: "theme_90_south_street.png" }, { title: "Start", name: "start", icon: "theme_90_start_menu.png" }, { title: "Sunny", name: "sunny", icon: "theme_90_sunny.png" }, { title: "Swanky Purse", name: "swanky-purse", icon: "theme_90_swanky_purse.png" }, { title: "Trontastic", name: "trontastic", icon: "theme_90_trontastic.png" }, { title: "UI Darkness", name: "ui-darkness", icon: "theme_90_ui_dark.png" }, { title: "UI Lightness", name: "ui-lightness", icon: "theme_90_ui_light.png" }, { title: "Vader", name: "vader", icon: "theme_90_black_matte.png" } ] }else{ var themes = settings.themes; } if( settings.additionalthemes.length ){ $.extend( themes, settings.additionalthemes ); } // Switcher link var switcherLinkStyle = { "cursor": "pointer", "font-family": "'Trebuchet MS', Verdana, sans-serif", "font-size": "11px", "color": "#666", "background": "#eee url("+settings.imgpath+"buttonbg.png) repeat-x 50% 50%", "border": "1px solid #CCC", "text-decoration": "none", "padding": "3px 3px 3px 8px", "width": settings.width+"px", "display": "block", "height": settings.buttonheight+"px", "outline": "0px" , "line-height": settings.buttonheight+"px" } if( settings.rounded ){ switcherLinkStyle['border-radius'] = "6px"; switcherLinkStyle['-moz-border-radius'] = "6px"; switcherLinkStyle['-webkit-border-radius'] = "6px"; } var switcherLink = $("") .addClass("jquery-ui-switcher-link") .css(switcherLinkStyle) .bind({ mouseenter: function(){ $(this).css({ "background": "#eee" }) }, mouseleave: function(){ if( ! switcherDiv.find(".jquery-ui-switcher-list-hldr").is(":visible") ){ $(this).css({ "background":"#eee url("+settings.imgpath+"buttonbg.png) repeat-x 50% 50%" }) } }, click: function(){ (!switcherDiv.find(".jquery-ui-switcher-list-hldr").is(":visible")) ? openSwitcher() : closeSwitcher(); } }); // Title & Icon for switcher link var switcherTitle = $("").addClass("jquery-ui-switcher-title").appendTo(switcherLink); $("").addClass("jquery-ui-switcher-arrow") .css({ "float": "right", "width": "16px", "height": "16px", "background": "url("+settings.imgpath+"icon_color_arrow.gif) no-repeat 50% 50%" }) .appendTo(switcherLink); if( settings.loadtheme.length ){ updateTheme( findTheme(settings.loadtheme) ); }else{ switcherTitle.text(settings.initialtext); } var switcherListHldr = $("
") .addClass("jquery-ui-switcher-list-hldr") .css({ "width": eval(settings.width+8)+"px", "background": "#000", "color": "#FFF", "font-family": "'Trebuchet MS', Verdana, sans-serif", "font-size": "12px", "border": "1px solid #CCC", "border-top": "none", "z-index": "999999", "position": "absolute", "top": eval(settings.buttonheight+3)+"px", "left": "0px", "padding": "3px 3px 3px 0", "display": "none" }) .bind({ mouseleave: function(){ closeSwitcher(); } }); if( settings.rounded ){ switcherListHldr.css("border-radius","0 0 6px 6px"); switcherListHldr.css("-moz-border-radius","0 0 6px 6px"); switcherListHldr.css("-webkit-border-radius","0 0 6px 6px"); } var switcherList = $("