| 1 |
(function($) { |
| 2 |
"use strict"; |
| 3 |
|
| 4 |
function initEeTabs($scope) { |
| 5 |
const tabsWrapper = $scope[0].querySelector(".ee-tabs-wrapper"); |
| 6 |
if (!tabsWrapper) return; |
| 7 |
|
| 8 |
const tabs = tabsWrapper.querySelectorAll(".eel-tab-titles li"); |
| 9 |
const contents = tabsWrapper.querySelectorAll(".ee-tab-content"); |
| 10 |
|
| 11 |
function slideOut(element, duration = 300) { |
| 12 |
return new Promise((resolve) => { |
| 13 |
element.style.transition = `opacity ${duration}ms, transform ${duration}ms`; |
| 14 |
element.style.opacity = 0; |
| 15 |
element.style.transform = "translateY(20px)"; |
| 16 |
setTimeout(() => { |
| 17 |
element.style.display = "none"; |
| 18 |
resolve(); |
| 19 |
}, duration); |
| 20 |
}); |
| 21 |
} |
| 22 |
|
| 23 |
function slideIn(element, duration = 300) { |
| 24 |
return new Promise((resolve) => { |
| 25 |
element.style.display = "block"; |
| 26 |
element.style.opacity = 0; |
| 27 |
element.style.transform = "translateY(20px)"; |
| 28 |
element.style.transition = `opacity ${duration}ms, transform ${duration}ms`; |
| 29 |
setTimeout(() => { |
| 30 |
element.style.opacity = 1; |
| 31 |
element.style.transform = "translateY(0)"; |
| 32 |
}, 10); |
| 33 |
setTimeout(() => { |
| 34 |
resolve(); |
| 35 |
}, duration); |
| 36 |
}); |
| 37 |
} |
| 38 |
|
| 39 |
tabs.forEach(tab => { |
| 40 |
tab.addEventListener("click", async function () { |
| 41 |
tabs.forEach(t => t.classList.remove("active")); |
| 42 |
|
| 43 |
const currentContent = Array.from(contents).find(c => c.style.display !== "none"); |
| 44 |
const targetContent = tabsWrapper.querySelector("#" + this.dataset.tab); |
| 45 |
|
| 46 |
if (!targetContent || currentContent === targetContent) { |
| 47 |
this.classList.add("active"); |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
if (currentContent) { |
| 52 |
await slideOut(currentContent, 300); |
| 53 |
} |
| 54 |
|
| 55 |
contents.forEach(c => c.classList.remove("active")); |
| 56 |
|
| 57 |
this.classList.add("active"); |
| 58 |
|
| 59 |
await slideIn(targetContent, 300); |
| 60 |
targetContent.classList.add("active"); |
| 61 |
}); |
| 62 |
}); |
| 63 |
|
| 64 |
// Default active |
| 65 |
if (tabs.length && contents.length) { |
| 66 |
tabs[0].classList.add("active"); |
| 67 |
contents.forEach(c => { |
| 68 |
c.style.display = "none"; |
| 69 |
c.style.opacity = 0; |
| 70 |
c.style.transform = "translateY(20px)"; |
| 71 |
}); |
| 72 |
contents[0].style.display = "block"; |
| 73 |
contents[0].style.opacity = 1; |
| 74 |
contents[0].style.transform = "translateY(0)"; |
| 75 |
contents[0].classList.add("active"); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
function handleTabDirection($scope) { |
| 80 |
const wrapper = $scope.find(".ee-tabs-wrapper"); |
| 81 |
if (!wrapper.length) return; |
| 82 |
const direction = wrapper.data("tab-direction"); |
| 83 |
const settings = $scope.data("settings") || {}; |
| 84 |
if (settings && settings.tab_layout_direction) { |
| 85 |
wrapper.addClass("direction-" + settings.tab_layout_direction); |
| 86 |
} |
| 87 |
const iconPosition = wrapper.data("icon-position"); |
| 88 |
if (iconPosition) { |
| 89 |
wrapper.addClass("icon-position-" + iconPosition); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
$(window).on("elementor/frontend/init", function () { |
| 94 |
elementorFrontend.hooks.addAction("frontend/element_ready/global", initEeTabs); |
| 95 |
elementorFrontend.hooks.addAction("frontend/element_ready/global", handleTabDirection); |
| 96 |
}); |
| 97 |
|
| 98 |
})(jQuery); |
| 99 |
|