PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.37
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.37
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Tabs / script.js

script.js in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.37, at includes/widgets/Tabs/script.js

89 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 (function ($) {
3 $(window).on("elementor/frontend/init", function () {
4 elementorFrontend.hooks.addAction(
5 "frontend/element_ready/king-addons-tabs.default",
6 function ($scope) {
7 elementorFrontend.elementsHandler.addHandler(
8 elementorModules.frontend.handlers.Base.extend({
9 onInit: function () {
10 const $scope = this.$element;
11 const $tabs = $(".king-addons-tabs", $scope).first();
12 const $tabsWrap = $(".king-addons-tabs-wrap", $tabs).first();
13 const $contentWrap = $(".king-addons-tabs-content-wrap", $tabs).first();
14 const $tabItems = $tabsWrap.children(".king-addons-tab");
15 const $contentItems = $contentWrap.children(".king-addons-tab-content");
16 const tabsData = $tabs.data("options");
17
18 // Determine active tab from settings or URL
19 let activeTabIndex = tabsData.activeTab - 1;
20 const urlActiveTabPos = window.location.href.indexOf("active_tab=");
21 if (urlActiveTabPos > -1) {
22 activeTabIndex = parseInt(
23 window.location.href
24 .substring(urlActiveTabPos, window.location.href.lastIndexOf("#"))
25 .replace("active_tab=", "")
26 ) - 1;
27 }
28
29 // Mark initial active tab and content
30 $tabItems.eq(activeTabIndex).addClass("king-addons-tab-active");
31 $contentItems.eq(activeTabIndex).addClass(
32 "king-addons-tab-content-active king-addons-animation-enter"
33 );
34
35 // Optional autoplay
36 let autoplayInterval;
37 if (tabsData.autoplay === "yes") {
38 let startIndex = activeTabIndex;
39 autoplayInterval = setInterval(() => {
40 startIndex = startIndex < $tabItems.length - 1 ? startIndex + 1 : 0;
41 switchTab(startIndex);
42 }, tabsData.autoplaySpeed);
43 }
44
45 // Hover or click trigger
46 const eventName = tabsData.trigger === "hover" ? "mouseenter" : "click";
47 $tabItems.on(eventName, function () {
48 const index = $(this).data("tab") - 1;
49 clearInterval(autoplayInterval);
50 switchTab(index);
51 });
52
53 // Switch tab utility
54 const switchTab = (index) => {
55 const $activeTab = $tabItems.eq(index);
56 const $activeContent = $contentItems.eq(index);
57
58 // Fix wrapper height during transition
59 $contentWrap.css("height", $contentWrap.outerHeight(true));
60
61 $tabItems.removeClass("king-addons-tab-active");
62 $activeTab.addClass("king-addons-tab-active");
63 $contentItems.removeClass("king-addons-tab-content-active king-addons-animation-enter");
64
65 // Calculate target height including container borders
66 const targetHeight =
67 $activeContent.outerHeight(true) +
68 parseInt($contentWrap.css("border-top-width"), 10) +
69 parseInt($contentWrap.css("border-bottom-width"), 10);
70
71 // Apply active classes and animate
72 $activeContent.addClass(
73 "king-addons-tab-content-active king-addons-animation-enter"
74 );
75 $contentWrap.css("height", targetHeight);
76
77 // Set back to auto after transition
78 setTimeout(() => {
79 $contentWrap.css("height", "auto");
80 }, 500);
81 };
82 },
83 }),
84 { $element: $scope }
85 );
86 }
87 );
88 });
89 })(jQuery);