1
1
mirror of https://github.com/go-gitea/gitea synced 2024-12-26 02:24:27 +00:00
gitea/public/ng/js/utils/tabs.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-09-25 13:52:58 +00:00
/*
js tabs and tabbed content plugin
2014-07-26 04:24:27 +00:00
*/
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
2014-09-25 13:52:58 +00:00
$e.on("click", ".js-tab-nav", function (e) {
e.preventDefault();
2014-07-26 04:24:27 +00:00
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)
}
2014-09-25 13:52:58 +00:00
}
$.fn.extend({
tabs: function () {
Tabs(this);
}
});