You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
10 years ago
|
/*
|
||
|
js tabs and tabbed content plugin
|
||
11 years ago
|
*/
|
||
|
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
|
||
10 years ago
|
$e.on("click", ".js-tab-nav", function (e) {
|
||
|
e.preventDefault();
|
||
11 years ago
|
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)
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
$.fn.extend({
|
||
|
tabs: function () {
|
||
|
Tabs(this);
|
||
|
}
|
||
|
});
|