summaryrefslogtreecommitdiffstats
path: root/public/ng/js/lib/tabs.js
blob: 98216720505ea7867d64190cf1512ee9a968b3f4 (plain)
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
/**
 * Created by fuxiaohei on 14-6-26.
 */

function Tabs(selector) {

    function hide($nav) {
        console.log("hide", $nav);
        $nav.removeClass("js-tab-nav-show");
        $($nav.data("tab-target")).removeClass("js-tab-show").hide();
    }

    function show($nav) {
        console.log("show", $nav);
        $nav.addClass("js-tab-nav-show");
        $($nav.data("tab-target")).addClass("js-tab-show").show();
    }

    var $e = $(selector);
    if ($e.length) {
        // pre-assign init index
        var $current = $e.find('.js-tab-nav-show');
        if ($current.length) {
            $($current.data("tab-target")).addClass("js-tab-show");
        }
        // bind nav click
        $e.on("click", ".js-tab-nav", function () {
            var $this = $(this);
            // is showing, not change.
            if ($this.hasClass("js-tab-nav-show")) {
                return;
            }
            $current = $e.find(".js-tab-nav-show").eq(0);
            hide($current);
            show($this);
        });
        console.log("init tabs @", selector)
    }
}