2022-11-15 15:05:32 +08:00
|
|
|
|
/**
|
|
|
|
|
* YourTeam 上方 Tab 頁籤
|
|
|
|
|
*
|
|
|
|
|
* 使用方式:
|
|
|
|
|
* <button type="button" data-tabname="testTab" data-target="testDiv1">頁籤按鈕1</button>
|
|
|
|
|
* <button type="button" data-tabname="testTab" data-target="testDiv2">頁籤按鈕2</button>
|
|
|
|
|
*
|
|
|
|
|
* <div id="testDiv1" data-tabname="testTab" data-tabrole="child"></div>
|
|
|
|
|
* <div id="testDiv2" data-tabname="testTab" data-tabrole="child"></div>
|
|
|
|
|
* */
|
|
|
|
|
var YT = YT || {};
|
2022-11-15 12:59:27 +08:00
|
|
|
|
|
|
|
|
|
var _ytTabInited = []
|
|
|
|
|
$(function () {
|
2022-11-16 14:53:22 +08:00
|
|
|
|
|
2022-11-15 18:47:16 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function initTabsByEle() {
|
|
|
|
|
$("[data-tabname][data-target]:not([data-tabrole=child])").each(function (index, value) {
|
2022-11-15 12:59:27 +08:00
|
|
|
|
let tabName = $(value).data("tabname");
|
2022-11-15 18:47:16 +08:00
|
|
|
|
if (_ytTabInited.indexOf(tabName) == -1) {
|
|
|
|
|
var ytTab = new YT.Tab({ tabName: tabName })
|
2022-11-15 12:59:27 +08:00
|
|
|
|
_ytTabInited.push(tabName);
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-11-15 18:47:16 +08:00
|
|
|
|
}
|
2022-11-15 12:59:27 +08:00
|
|
|
|
|
2022-11-15 15:05:32 +08:00
|
|
|
|
class YourTeamTab {
|
2022-11-15 12:59:27 +08:00
|
|
|
|
constructor(option = {}) {
|
|
|
|
|
this.tabName = option.tabName ?? null;
|
2022-11-15 15:05:32 +08:00
|
|
|
|
this.init()
|
2022-11-15 12:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 14:53:22 +08:00
|
|
|
|
init = function () {
|
|
|
|
|
if (_ytTabInited.indexOf(this.tabName) != -1) {
|
|
|
|
|
_ytTabInited.splice($.inArray(this.tabName, _ytTabInited), 1);
|
|
|
|
|
$(`[data-tabname=${this.tabName}][data-target]`).off("click").unbind("click");
|
|
|
|
|
}
|
2022-11-15 12:59:27 +08:00
|
|
|
|
this.event();
|
2022-11-15 18:47:16 +08:00
|
|
|
|
$(`[data-tabname=${this.tabName}][data-tabrole=child]`).css("display", "none");
|
2022-11-16 14:53:22 +08:00
|
|
|
|
$(`[data-tabname=${this.tabName}][data-target]`).first().trigger("click","fromInit");
|
|
|
|
|
_ytTabInited.push(this.tabName);
|
2022-11-15 12:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-15 15:05:32 +08:00
|
|
|
|
event = function () {
|
|
|
|
|
let clsObj = this;
|
2022-11-15 12:59:27 +08:00
|
|
|
|
// custom tab
|
|
|
|
|
// example :
|
|
|
|
|
// <button id="test" data-target="#okDiv" data-tabname="tab1"></button>
|
|
|
|
|
// <div id="okDiv" data-tabrole="child" data-tabname="tab1"></div>
|
2022-11-16 14:53:22 +08:00
|
|
|
|
$(`[data-tabname=${this.tabName}][data-target]`).off("click").on("click", function (e, arg) {
|
|
|
|
|
console.log(e)
|
2022-11-15 12:59:27 +08:00
|
|
|
|
let target = $(this).data("target");
|
|
|
|
|
let obj = this;
|
2022-11-15 15:05:32 +08:00
|
|
|
|
$(`[data-tabname=${clsObj.tabName}][data-target]:not([data-tabrole=child])`).removeClass("active")
|
|
|
|
|
$(obj).addClass("active")
|
2022-11-16 14:53:22 +08:00
|
|
|
|
$(obj).trigger("yt:tab:change")
|
2022-11-15 12:59:27 +08:00
|
|
|
|
let tabName = $(target).data("tabname");
|
|
|
|
|
if (tabName) {
|
|
|
|
|
if ($(target).data("tabrole") == "child") {
|
|
|
|
|
$(obj).trigger("yt:tab:show");
|
|
|
|
|
$(`[data-tabname='${tabName}'][data-tabrole='child']`).css("opacity", 0).hide();
|
|
|
|
|
$(target).show().animate({ opacity: 1 }, 200, function () {
|
|
|
|
|
$(obj).trigger("yt:tab:shown");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-15 15:05:32 +08:00
|
|
|
|
|
|
|
|
|
YT.Tab = YT.Tab || YourTeamTab;
|