Skip to content

Instantly share code, notes, and snippets.

@jdgamble555
Last active August 29, 2015 14:21
Show Gist options
  • Save jdgamble555/38483e811a869a31b26d to your computer and use it in GitHub Desktop.
Save jdgamble555/38483e811a869a31b26d to your computer and use it in GitHub Desktop.
This code will allow you to initiate a theme changer in your site for jQuery UI.
/*
* Author: Jonathan Gamble
* jQuery UI Theme Changer
*/
$(document).ready(function() {
// id of your theme selector <div>
themeSelector('#themeSelector');
});
function themeSelector(e) {
// Get all themes
var themes = [
'Black Tie', 'Blitzer', 'Cupertino',
'Dark Hive', 'Dot Luv', 'Eggplant',
'Excite Bike', 'Flick', 'Hot Sneaks',
'Humanity', 'Le Frog', 'Mint Choc',
'Overcast', 'Pepper Grinder', 'Redmond',
'Smoothness', 'South Street', 'Start',
'Sunny', 'Swanky Purse', 'Trontastic',
'UI darkness', 'UI lightness', 'Vader'
];
// Source
var jVersion = '1.11.4';
var google_src = 'https://ajax.googleapis.com/ajax/libs/jqueryui/';
// Create select
var changer = $('<select>').appendTo(e);
$(themes).each(function() {
changer.append($("<option>").attr('value', this.replace(' ', '-').toLowerCase()).text(this));
});
// Add change event
$(changer).selectmenu({
change: function() {
var css = google_src + jVersion + '/themes/' + this.value +'/jquery-ui.min.css';
$('link[href*="jquery-ui."]').attr('href', css);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment