jlStyleSheet is a CSS stylesheet changer jQuery plugin I designed which allows you to preview or switch the CSS stylesheet for your webpage with a click.
You can try jlStyleSheet on this webpage. You can also download the source-code by following the download link below.
Download: Git The Source Code
Changelog:
- 1.0.4 – 9.15.10 – Cookie is set only if a default theme is present or a switch has occurred.
- 1.0.3 – 9.14.10 – Preview stylesheet is removed if no default is present.
- 1.0.2 – 9.13.10 – Had to revisit the cookies. Fixed the bugs. Cleaned up the code some by removing some unnecessary variables and combining the preview and switch functions.
- 1.0.1 – 9.13.10 – Fixed a bug which caused cookies to not work as intended. Fixed a bug in the default cookie options. Fixed an error in the documentation (the default cookie name was incorrect).
- 1.0.0 – 8.9.10 – Initial release
Example Use:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Jason Lau" />
<title>jlStyleSheet Test Page</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="jquery.jlstylesheet.js"></script>
<script>
jQuery(function(){
var mySelect = function(){
alert('Theme selected!');
};
$('body').jlstylesheet({
defaultTheme: 'test1',
onSelect: mySelect
});
});
</script>
</head>
<body>
<a href="javascript:void(0)" rel="test1" id="test1" class="jlstylesheet-option">Test 1</a> <a href="javascript:void(0)" rel="test2" id="test2" class="jlstylesheet-option">Test 2</a> <a href="javascript:void(0)" rel="test3" id="test3" class="jlstylesheet-option">Test 3</a><br /><br />
<span class="test1"><strong>Test 1</strong></span><br />
<span class="test2"><strong>Test 2</strong></span><br />
<span class="test3"><strong>Test 3</strong></span>
</body>
</html>
Call jlstylesheet() on the body selector. Use the class .jlstylesheet-option on any object that is a stylesheet option. Use the rel=”" attribute to hold the stylesheet filename.
<a href="javascript:void(0)" class="jlstylesheet-option" rel="mystylesheet">Change Stylesheet</a> <input type="button" class="jlstylesheet-option" rel="mystylesheet" value="Change Stylesheet" /> <img src="mypic.png" class="jlstylesheet-option" rel="mystylesheet" />
Available Options:
jlStyleSheet has the following options available for customization.