styleswitch.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Styleswitch stylesheet switcher built on jQuery
  3. * Under an Attribution, Share Alike License
  4. * Download by http://www.codefans.net
  5. * By Kelvin Luck ( http://www.kelvinluck.com/ )
  6. **/
  7. (function($)
  8. {
  9. $(document).ready(function() {
  10. $('.styleswitch').click(function()
  11. {
  12. switchStylestyle(this.getAttribute("rel"));
  13. return false;
  14. });
  15. var c = readCookie('style');
  16. if (c) switchStylestyle(c);
  17. });
  18. function switchStylestyle(styleName)
  19. {
  20. var ifrm = $("#rightMain").contents();
  21. $('link[rel*=style][title]').each(function(i)
  22. {
  23. this.disabled = true;
  24. if (this.getAttribute('title') == styleName) this.disabled = false;
  25. });
  26. ifrm.find('link[rel*=style][title]').each(function(i)
  27. {
  28. this.disabled = true;
  29. if (this.getAttribute('title') == styleName) this.disabled = false;
  30. });
  31. createCookie('style', styleName, 365);
  32. }
  33. })(jQuery);
  34. // cookie functions http://www.quirksmode.org/js/cookies.html
  35. function createCookie(name,value,days)
  36. {
  37. if (days)
  38. {
  39. var date = new Date();
  40. date.setTime(date.getTime()+(days*24*60*60*1000));
  41. var expires = "; expires="+date.toGMTString();
  42. }
  43. else var expires = "";
  44. document.cookie = name+"="+value+expires+"; path=/";
  45. }
  46. function readCookie(name)
  47. {
  48. var nameEQ = name + "=";
  49. var ca = document.cookie.split(';');
  50. for(var i=0;i < ca.length;i++)
  51. {
  52. var c = ca[i];
  53. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  54. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  55. }
  56. return null;
  57. }
  58. function eraseCookie(name)
  59. {
  60. createCookie(name,"",-1);
  61. }
  62. // /cookie functions