dwz.theme.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Theme Plugins
  3. * @author ZhangHuihua@msn.com
  4. */
  5. (function($){
  6. $.fn.extend({
  7. theme: function(options){
  8. var op = $.extend({themeBase:"themes"}, options);
  9. var _themeHref = op.themeBase + "/#theme#/style.css";
  10. return this.each(function(){
  11. var jThemeLi = $(this).find(">li[theme]");
  12. var setTheme = function(themeName){
  13. $("head").find("link[href$='style.css']").attr("href", _themeHref.replace("#theme#", themeName));
  14. jThemeLi.find(">div").removeClass("selected");
  15. jThemeLi.filter("[theme="+themeName+"]").find(">div").addClass("selected");
  16. if ($.isFunction($.cookie)) $.cookie("dwz_theme", themeName);
  17. }
  18. jThemeLi.each(function(index){
  19. var $this = $(this);
  20. var themeName = $this.attr("theme");
  21. $this.addClass(themeName).click(function(){
  22. setTheme(themeName);
  23. });
  24. });
  25. if ($.isFunction($.cookie)){
  26. var themeName = $.cookie("dwz_theme");
  27. if (themeName) {
  28. setTheme(themeName);
  29. }
  30. }
  31. });
  32. }
  33. });
  34. })(jQuery);