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.
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.
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...
$('#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']}); }
);
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);
This tab highlights examples of this plugin in use "in the wild".
None as yet.
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.
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
});
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script><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).$(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.
Great job on the plugin - it's tops!
Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.
| Version | Date | Changes |
|---|---|---|
| 1.2.0 | 02 Jan 2010 |
|
| 1.1.0 | 24 Jan 2009 |
|
| 1.0.0 | 06 Sep 2008 |
|