1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-30 09:41:11 -05:00
forgejo/public/ng/js/lib/tabs.js
2014-07-26 00:24:27 -04:00

39 lines
No EOL
1.1 KiB
JavaScript

/**
* 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)
}
}