A jQueryplugin
that sets a div or span to allow the user to select
a CSS theme to apply to your site.
The current version is 1.3.0 and is available
under the MIT licence.
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
https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/themes/.
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.
The following list shows the current themes with their IDs:
To be filled
var html = '';
$.each($.themes.getThemes(), function(id, theme) {
if (id != 'bright') {
html += '<li>' + id + ' - ' + theme.display + '</li>';
}
});
$('#themesList').html(html);
Persistence via Cookies
The theme selection is saved as a cookie so that the next time the user returns
their chosen theme is automatically loaded. If none is set, the
defaultTheme setting is used, or,
if that is blank, the first in the theme list.
You can control the expiry of the cookie by setting cookieExpiry
to be either an actual date or the number of days in the future. Leave it at
the default of 0 to expire at the end of the current session.
You can also set how much of the site the theme applies to by using the
cookiePath and cookieDomain settings.
These default to '/' and '' respectively
to indicate the full site under the current domain.
This tab highlights examples of this plugin in use "in the wild".
None as yet.
To add another example, please contact me (wood.keith{at}optusnet.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.
$(selector).themes({
themes: [], // List of theme IDs to use, empty for all
themeBase: '', // The base URL for all the theme files
themeFile: 'jquery-ui.css', // Name of the theme file
defaultTheme: '', // The ID of the default theme, first one if blank
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
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
});
$.themes.setDefaults(settings) // Change settings for all instances
$(selector).themes('option', settings) // Change the instance settings
$(selector).themes('option', name, value) // Change an instance setting
$(selector).themes('option', name) // Retrieve an instance setting
$(selector).themes('destroy') // Remove the themes functionality
Theme SamplerUsage
Include the jQuery library in the head section of your page.