jQuery Themes

A jQuery plugin that sets a div or span to allow the user to select a CSS theme to apply to your site. If you find this plugin useful please vote for it on the jQuery site.

The current version is 1.2.0 and is available under the GPL and MIT licences. Download the jQuery ThemeRoller themes separately. For more detail see the documentation reference page. Or see a minimal page that you can use as a basis for your own investigations.

Default Settings

This plugin allows the user to select one of a number of CSS themes to apply to the current site. The selection is immediately used and is also persisted in a cookie so that it applies to future visits. The standard themes come from the jQuery ThemeRoller tool and can be referenced at http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/.

First you need to initialise the themes so as to pick up any saved setting (see Cookies tab).

$.themes.init({themeBase:
	'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/',
	onSelect: displayName});

You can set any global settings for the themes that are different from the defaults.

$.themes.setDefaults({cookieExpiry: 7});

Finally, the theme selection functionality can easily be added to a division with appropriate default settings. The resulting links allow the user to easily change the theme for this site. See the results in the sampler below.

You can also remove the themeing functionality if it is no longer required.

All themes:

$('#defaultThemes').themes();

$('#removeThemes').toggle(function() {
		$(this).text('Re-attach');
		$('#defaultThemes').themes('destroy');
	},
	function() {
		$(this).text('Remove');
		$('#defaultThemes').themes();
	}
);

Processed fields are marked with a class of hasThemes and are not re-processed if targetted a second time.

Appearance

Control how the theme selection is presented.

Full view:

$('#fullThemes').themes({compact: false});

Appear on hover: Select a theme...

$('#selectLabel').mouseover(function() { $('#selectThemes').show(); });
	
$('#selectThemes').themes();

Click for a popup: Select a theme... Close

$('#popupTheme').click(function() {
	var offset = $(this).offset();
	$('#popupThemes').css('left', offset.left).
		css('top', offset.top + $(this).outerHeight());
	$('#popupThemes,#popupClose').toggle();
});

$('#popupThemes').themes();

A select few with no preview:

$('#namedThemes').themes({showPreview: false,
	themes: ['smoothness', 'humanity', 'mintchoc']});
	
$('#changeThemes').toggle(
	function() { $('#namedThemes').themes('change', {showPreview: false,
		themes: ['southstreet', 'cupertino', 'blacktie']}); },
	function() { $('#namedThemes').themes('change', {showPreview: false,
		themes: ['smoothness', 'humanity', 'mintchoc']}); }
);

Additional Themes

You can add new themes to the list as shown below.
The parameters are the id, display name, icon index/URL, preview index/URL, and theme CSS URL.

Add your own:

$.themes.addTheme('bright', 'Bright Eyes',
	'img/bright.png', 'img/bright-big.png', 'bright/ui.all.css');
$('#addTheme').themes({themes: ['smoothness', 'bright'], compact: false});

The following list shows the current themes with their IDs:

var html = '';
$.each($.themes.getThemes(), function(id, theme) {
	if (id != 'bright') {
		html += '<li>' + id + ' - ' + theme.display + '</li>';
	}
});
$('#themesList').html(html);

In the Wild

This tab highlights examples of this plugin in use "in the wild".

To add another example, please contact me (kbwood{at}iinet.com.au) and provide the plugin name, the URL of your site, its title, and a short description of its purpose and where/how the plugin is used.

Quick Reference

A full list of all possible settings is shown below. Note that not all would apply in all cases. For more detail see the documentation reference page.

$.themes.setDefaults({
	themeBase: '',  // The base URL for all the theme files
	defaultTheme: '', // The ID of the default theme, first one if blank
	cookieExpiry: 0,  // The expiry time for the theme cookie, date or number of days
	cookiePath: '/',  // The path that the cookie applies to
	cookieDomain: '',  // The domain that the cookie applies to
	onSelect: null  // Callback on theme selection, theme ID and URL are passed as parameters
});
$(selector).themes({
	themes: [],  // List of theme IDs to use, empty for all
	icons: 'img/themes.gif', // Horizontal amalgamation of all theme icons
	iconSize: [23, 20],  // The width and height of the individual icons
	previews: 'img/themes-preview.gif', // Horizontal amalgamation of all theme previews
	previewSize: [90, 80],  // The width and height of the individual previews
	showPreview: true,  // True to display a popup preview, false to not show it
	compact: true  // True if a compact presentation should be used, false for full
});

Theme Sampler

Theme Sampler

Accordion

First

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Second

Third

Tabs

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Phasellus mattis tincidunt nibh. Cras orci urna, blandit id, pretium vel, aliquet ornare, felis. Maecenas scelerisque sem non nisl. Fusce sed lorem in enim dictum bibendum.
Nam dui erat, auctor a, dignissim quis, sollicitudin eu, felis. Pellentesque nisi urna, interdum eget, sagittis et, consequat vestibulum, lacus. Mauris porttitor ullamcorper augue.

Dialog

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur consequat.

Nam congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id, sem. Morbi in orci.

Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec, quam. Nam molestie scelerisque quam. Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur consequat.

Nam congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id, sem. Morbi in orci. Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec, quam. Nam molestie scelerisque quam.

Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare, ultrices ut, nisi. Aliquam ante.

Suspendisse scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id, sem. Morbi in orci. Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec, quam. Nam molestie scelerisque quam. Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare, ultrices ut, nisi.

Dialog Title Close

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Slider

Datepicker

Prev Next
December 2008
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

Progressbar

Highlight / Error

Hey! Sample ui-state-highlight style.


Alert: Sample ui-state-error style.

Usage

  1. Include the jQuery library in the head section of your page.
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
  2. Download and include the jQuery Themes CSS and JavaScript in the head section of your page.
    <style type="text/css">@import "jquery.themes.css";</style>
    <script type="text/javascript" src="jquery.themes.js"></script>
    Alternately, you can use the packed version jquery.themes.pack.js (6.1K vs 13.6K), or the minified version jquery.themes.min.js (6.7K, 2.6K when zipped).
  3. Connect the themes functionality to your divs.
    $(selector).themes();
    You can include custom settings as part of this process.
    $(selector).themes({themes: ['cupertino', 'smoothness']});

For more detail see the documentation reference page. Or see a minimal page that you can use as a basis for your own investigations.

Comments

Great job on the plugin - it's tops!

Beren Longstreet

Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.

Change History

VersionDateChanges
1.2.002 Jan 2010
  • Updated themes to jQuery UI 1.7.2 offerings
  • Moved default images to img subdirectory
  • Converted images to GIF to reduce size
1.1.024 Jan 2009
  • Updated themes to jQuery UI 1.6 offerings
1.0.006 Sep 2008
  • Initial release

Valid HTML 4.01 Strict