PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.5.0
Easy Elements for Elementor – Addons & Website Templates v1.5.0
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / tab / js / tab.js

tab.js in Easy Elements for Elementor – Addons & Website Templates 1.5.0, at widgets/tab/js/tab.js

99 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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