/** * YourTeam 上方 Tab 頁籤 * * 使用方式: * * * *
*
* */ var YT = YT || {}; var _ytTabInited = [] $(function () { $("[data-tabname][data-target]:not([data-tabrole='child'])").each(function (index, value) { let tabName = $(value).data("tabname"); if (_ytTabInited.indexOf(tabName) == -1) { var ytTab = new YTTab({ tabName: tabName }) _ytTabInited.push(tabName); } }) }) class YourTeamTab { constructor(option = {}) { this.tabName = option.tabName ?? null; this.init() } init = function() { $(`[data-tabname=${this.tabName}][data-tabrole=child]`).css("display", "none"); $(`[data-tabname=${this.tabName}][data-tabrole=child]`).first().show(); console.log("inited") this.event(); } event = function () { let clsObj = this; // custom tab // example : // //
$("body").on("click", `[data-tabname=${this.tabName}][data-target]`, function () { let target = $(this).data("target"); let obj = this; $(`[data-tabname=${clsObj.tabName}][data-target]:not([data-tabrole=child])`).removeClass("active") $(obj).addClass("active") 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"); }); } } }) } } YT.Tab = YT.Tab || YourTeamTab;