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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * @author zhanghuihua@msn.com
 */
(function($){
    $.fn.navMenu = function(){
        return this.each(function(){
            var $box = $(this);
            $box.find("li>a").click(function(){
                var $a = $(this);
                $.post($a.attr("href"), {}, function(html){
                    $("#sidebar").find(".accordion").remove().end().append(html).initUI();
                    $box.find("li").removeClass("selected");
                    $a.parent().addClass("selected");
                    navTab.closeAllTab();
                });
                return false;
            });
        });
    }
    
    $.fn.switchEnv = function(){
        var op = {cities$:">ul>li", boxTitle$:">a>span"};
        return this.each(function(){
            var $this = $(this);
            $this.click(function(){
                if ($this.hasClass("selected")){
                    _hide($this);
                } else {
                    _show($this);
                }
                return false;
            });
            
            $this.find(op.cities$).click(function(){
                var $li = $(this);
 
                $.post($li.find(">a").attr("href"), {}, function(html){
                    _hide($this);
                    $this.find(op.boxTitle$).html($li.find(">a").html());
                    navTab.closeAllTab();
                    $("#sidebar").find(".accordion").remove().end().append(html).initUI();
                });
                return false;
            });
        });
    }
    
    function _show($box){
        $box.addClass("selected");
        $(document).bind("click",{box:$box}, _handler);
    }
    function _hide($box){
        $box.removeClass("selected");
        $(document).unbind("click", _handler);
    }
    
    function _handler(event){
        _hide(event.data.box);
    }
})(jQuery);