/************************************************************************* (c) 2008-2012 Martin Wendt *************************************************************************/ /******************************************************************************* * jQuery.skinswitcher plugin. * * Change CSS include when combobox selection changes. * Copyright (c) 2012 Martin Wendt * * Usage: $("select#skinswitcher").skinswitcher({ base: "../src/", choices: [{name: "XP", value: "xp", href: "skin/ui.fancytree.css"}, {name: "Vista", value: "vista", href: "skin-vista/ui.fancytree.css"}, {name: "Lion", value: "lion", href: "skin-lion/ui.fancytree.css"} ], init: "lion" }); */ (function( $ ) { var PLUGIN_NAME = "skinswitcher", defaultOptions = { /**RegEx that returns prefix, tag, and suffix of the CSS href.*/ skinPattern: "^(\W/skin-)().css$", mode: "combo", // {String} mode 'combo' or 'radio' base: "", choices: [] }, methods = { init: function(options) { var opts = $.extend({}, defaultOptions, options), hrefs = [], $link = null, initialChoice = undefined; this.data("options", opts); // Find tag, figure out current setting and mark for // later access $.each(opts.choices, function(){ hrefs.push(this.href.toLowerCase()); }); $("head link").each(function(){ for(var i=0; i= 0){ $link = $(this); $link.addClass(PLUGIN_NAME); initialChoice = opts.choices[i]; } } }); return this.each(function() { // Add options to dropdown list var $combo = $(this); $combo.empty(); $.each(opts.choices, function(i, choice){ var $opt = $("