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