PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.24
Post Grid Gutenberg Blocks – PostX v5.0.24
5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 All 238 releases
ultimate-post / assets / js / ultp-tab-block.js

ultp-tab-block.js in Post Grid Gutenberg Blocks – PostX 5.0.24, at assets/js/ultp-tab-block.js

333 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 ("use strict");
3 const isFront = $("body.postx-admin-page").length == 0;
4
5 if (isFront && $(".wp-block-ultimate-post-tabs").length) {
6 handleTabBlock();
7 $(window).on("resize", function () {
8 if ($(".wp-block-ultimate-post-tabs").length) {
9 handleTabBlock();
10 }
11 });
12 }
13 // Tab Block Function
14 function handleTabBlock() {
15 const rootTabSelector = (element) =>
16 element.closest(".wp-block-ultimate-post-tabs");
17
18 $(".wp-block-ultimate-post-tabs").each(function () {
19 let tab = $(this);
20 const responsiveType = tab.data("responsive");
21 const tabNavMain = tab.find(".ultp-tabs-nav").first();
22
23 const tabContent = tab
24 .find(".ultp-tab-content")
25 .first()
26 .children(".wp-block-ultimate-post-tab-item");
27
28 const isTabVertical =
29 tab.children().children(".ultp-nav-right").length > 0 ||
30 tab.children().children(".ultp-nav-left").length > 0;
31
32 if (tab.parent(".wp-block-ultimate-post-tab-item").length > 0) {
33 tab.closest(".ultp-tab-content").css({ overflow: "hidden" });
34 }
35
36 // Responsive
37 if (responsiveType == "slider" && tab.width() < 600) {
38 tab.find(".ultp-tabs-nav").css({ flexWrap: "nowrap" });
39 }
40
41 // Accordion
42 if (
43 tab.width() < 600 &&
44 tab.data("responsive") == "accordion" &&
45 !tab.hasClass("ultp-tab-accordion-active")
46 ) {
47 tab.addClass("ultp-tab-accordion-active");
48 tab.find(".ultp-tabs-nav-element").each(function (i) {
49 if ($(this).data("order")) {
50 $(this).css({ order: (i + 1) * 2 - 1 });
51 }
52 });
53 tabContent.each(function (i) {
54 $(this).css({ order: (i + 1) * 2 });
55 });
56 }
57
58 // Active Accordion
59 if (tab.hasClass("ultp-tab-accordion-active")) {
60 tabNavMain
61 .css("display", "contents")
62 .parent()
63 .css("display", "contents");
64 tabContent
65 .addClass("ultp-tab-content")
66 .parent()
67 .css("display", "contents");
68 }
69
70 // initial active - Clear all active states first
71 if (tabContent.filter(".active").length === 0) {
72 const activeTabIndex = tab.data("activetab");
73 tabContent.each(function () {
74 if ($(this).data("tabindex") == activeTabIndex) {
75 $(this).addClass("active");
76 tab.find(".ultp-tabs-nav-element").each(function () {
77 if ($(this).data("tabindex") == activeTabIndex) {
78 $(this).addClass("ultp-tab-active");
79 }
80 });
81 }
82 });
83 }
84
85 const tabNavContainer = tab.find(".ultp-tabs-nav-wrapper");
86 const leftArrow = tab.find(".ultp-tab-left-arrow").first();
87 const rightArrow = tab.find(".ultp-tab-right-arrow").first();
88
89 const tabevent =
90 tab.data("tabevent") == "autoplay" ? "click" : tab.data("tabevent");
91
92 let tabOverflow =
93 responsiveType == "slider" ||
94 tab.find(".ultp-tab-wrapper").hasClass("ultp-nav-left") ||
95 tab.find(".ultp-tab-wrapper").hasClass("ultp-nav-right");
96
97 let navContainerSize = isTabVertical
98 ? tabNavMain.height()
99 : tabNavMain.width();
100
101 let singleElementWidth = navContainerSize / tabNavMain?.children().length;
102 let navParenTContainer = isTabVertical
103 ? tabNavContainer.height()
104 : tabNavContainer.width();
105
106 let shiftValue = 0;
107 // let SlideshitValue = singleElementWidth;
108
109 // on Click/Hover Element Show
110 tab
111 .find(".ultp-tabs-nav-element")
112 .off(tabevent)
113 .on(tabevent, function (event) {
114 event.stopPropagation();
115
116 const navContent = $(this);
117
118 navContent
119 .addClass("ultp-tab-active")
120 .siblings()
121 .removeClass("ultp-tab-active");
122
123 rootTabSelector($(this))
124 .find(".wp-block-ultimate-post-tab-item")
125 .each(function () {
126 $(this).removeClass("active");
127 if ($(this).data("tabindex") == navContent.data("tabindex")) {
128 $(this).addClass("active");
129 }
130 });
131
132 navContainerSize = isTabVertical
133 ? tabNavMain.height()
134 : tabNavMain.width();
135
136 singleElementWidth = navContainerSize / tabNavMain?.children().length;
137
138 navParenTContainer = isTabVertical
139 ? tabNavContainer.height()
140 : tabNavContainer.width();
141
142 if (navContainerSize > navParenTContainer && tabOverflow) {
143 handleTabArrowControl();
144 }
145 });
146
147 if (navContainerSize > navParenTContainer && tabOverflow) {
148 handleTabArrowControl();
149 }
150
151 // Left Right Arrow Slide
152 function handleTabArrowControl() {
153 if (shiftValue == 0) {
154 rightArrow.addClass("ultp-arrow-active");
155 }
156 rightArrow.off("click").on("click", function (event) {
157 event.stopPropagation();
158 const parentSize = isTabVertical
159 ? $(this).closest(".ultp-tabs-nav-wrapper").height()
160 : $(this).closest(".ultp-tabs-nav-wrapper").width();
161
162 const size = isTabVertical
163 ? $(this).siblings().find(".ultp-tabs-nav").height()
164 : $(this).siblings().find(".ultp-tabs-nav").width();
165
166 const shiftValueLimit = size - parentSize;
167
168 const singleWidth =
169 size / $(this).siblings().find(".ultp-tabs-nav")?.children().length;
170
171 if (
172 shiftValueLimit > shiftValue &&
173 shiftValueLimit - shiftValue > singleWidth
174 ) {
175 shiftValue = shiftValue + singleWidth;
176 }
177
178 if (shiftValueLimit - shiftValue < singleWidth + 1) {
179 shiftValue = shiftValue + (shiftValueLimit - shiftValue);
180 $(this).removeClass("ultp-arrow-active");
181 }
182
183 if (shiftValue > 0) {
184 $(this)
185 .siblings(".ultp-tab-left-arrow")
186 .addClass("ultp-arrow-active");
187 }
188
189 let transformStyle = isTabVertical
190 ? `translate(0px, -${shiftValue}px)`
191 : `translate(-${shiftValue}px, 0px)`;
192
193 $(this)
194 .siblings()
195 .find(".ultp-tabs-nav")
196 .css({ transform: transformStyle });
197 });
198
199 leftArrow.off("click").on("click", function (event) {
200 const size = isTabVertical
201 ? $(this).siblings().find(".ultp-tabs-nav").height()
202 : $(this).siblings().find(".ultp-tabs-nav").width();
203
204 const singleWidth =
205 size / $(this).siblings().find(".ultp-tabs-nav")?.children().length;
206
207 if (shiftValue > singleWidth) {
208 shiftValue = shiftValue - singleWidth;
209 } else {
210 shiftValue = 0;
211 }
212
213 if (shiftValue > 0) {
214 $(this)
215 .siblings(".ultp-tab-right-arrow")
216 .addClass("ultp-arrow-active");
217 } else {
218 $(this).removeClass("ultp-arrow-active");
219 }
220
221 let transformStyle = isTabVertical
222 ? `translate(0px, -${shiftValue}px)`
223 : `translate(-${shiftValue}px, 0px)`;
224
225 $(this)
226 .siblings()
227 .find(".ultp-tabs-nav")
228 .css({ transform: transformStyle });
229 });
230 }
231
232 // Auto Play function
233 function handleTabSlider(tab, tabContent, tabNavMain) {
234 const parentBlock =
235 tab.parent(".wp-block-ultimate-post-tab-item").length > 0
236 ? tab.parent(".wp-block-ultimate-post-tab-item").hasClass("active")
237 : true;
238 if (parentBlock) {
239 navContainerSize = isTabVertical
240 ? tabNavMain.height()
241 : tabNavMain.width();
242
243 singleElementWidth = navContainerSize / tabNavMain?.children().length;
244
245 navParenTContainer = isTabVertical
246 ? tabNavContainer.height()
247 : tabNavContainer.width();
248 const navContent = tabNavMain.find(".ultp-tabs-nav-element");
249 // SlideshitValue = SlideshitValue + singleElementWidth;
250
251 if (slideIndex * singleElementWidth < navParenTContainer) {
252 tabNavMain.css({ transform: `translate(0px, 0px)` });
253 if (responsiveType == "slider") {
254 rightArrow.addClass("ultp-arrow-active");
255 leftArrow.removeClass("ultp-arrow-active");
256 }
257 }
258
259 if (slideIndex * singleElementWidth > navParenTContainer) {
260 if (tabOverflow) {
261 leftArrow.addClass("ultp-arrow-active");
262 rightArrow.addClass("ultp-arrow-active");
263 }
264 let transformStyle = isTabVertical
265 ? `translate(0px, ${
266 navParenTContainer - slideIndex * singleElementWidth
267 }px)`
268 : `translate(${
269 navParenTContainer - slideIndex * singleElementWidth
270 }px, 0px)`;
271 tabNavMain.css({ transform: transformStyle });
272 }
273
274 const totalElementCount = navContent.parent().children().length;
275
276 navContent.each(function (idx) {
277 if (progressbarEnable) {
278 $(this).removeClass("tab-progressbar-active");
279 }
280 if (idx + 1 == slideIndex) {
281 $(this).addClass("ultp-tab-active");
282 if (progressbarEnable) {
283 $(this).addClass("tab-progressbar-active");
284 }
285 } else {
286 $(this).removeClass("ultp-tab-active");
287 }
288 });
289
290 tabContent.each(function (idx) {
291 $(this).each(function () {
292 if (idx + 1 == slideIndex) {
293 $(this).addClass("active");
294 } else {
295 $(this).removeClass("active");
296 }
297 });
298 });
299
300 if (totalElementCount == slideIndex) {
301 rightArrow.removeClass("ultp-arrow-active");
302 slideIndex = 0;
303 }
304 slideIndex++;
305 }
306 }
307
308 // Auto Play
309 const progressbarEnable = tab.data("progressbar");
310 const duration = $(this).data("duration") * 1000;
311
312 let slideIndex = rootTabSelector($(this)).data("activetab") - 1 || 1;
313 if ($(this).data("tabevent") == "autoplay") {
314 let tabSlider = setInterval(
315 () => handleTabSlider(tab, tabContent, tabNavMain),
316 duration,
317 );
318
319 tab.off("mouseleave").on("mouseleave", function () {
320 tabSlider = setInterval(
321 () => handleTabSlider(tab, tabContent, tabNavMain),
322 duration,
323 );
324 });
325
326 tab.off("mouseenter").on("mouseenter", function () {
327 clearInterval(tabSlider);
328 });
329 }
330 });
331 }
332 })(jQuery);
333