PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.41
Post Grid Gutenberg Blocks – PostX v5.0.41
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.js

ultp.js in Post Grid Gutenberg Blocks – PostX 5.0.41, at assets/js/ultp.js

2,039 lines 55.6 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 const isFront = $("body.postx-admin-page").length == 0;
5 // *************************************
6 // Nonce Generation for AJAX
7 // *************************************
8 async function getUltpNonce() {
9 const nonce = sessionStorage.getItem("ultp_nonce");
10 if (nonce) return nonce;
11
12 try {
13 const response = await $.ajax({
14 url: ultp_data_frontend.ajax,
15 type: "POST",
16 data: { action: "ultp_get_nonce" },
17 });
18
19 if (response?.success && response?.data?.nonce) {
20 sessionStorage.setItem("ultp_nonce", response.data.nonce);
21 return response.data.nonce;
22 }
23
24 console.log("Failed to fetching nonce");
25 return null;
26 } catch (xhr) {
27 console.log(
28 "Error occured.please try again" + xhr.statusText + xhr.responseText,
29 );
30 console.log("Nonce Not Generating Properly");
31 return null;
32 }
33 }
34
35 // *************************************
36 // Social Share window
37 // *************************************
38 $(".ultp-post-share-item a").each(function () {
39 $(this).on("click", function () {
40 // For Share window opening
41 let share_url = $(this).attr("url");
42 let width = 800;
43 let height = 500;
44 let leftPosition, topPosition;
45 //Allow for borders.
46 leftPosition = window.screen.width / 2 - (width / 2 + 10);
47 //Allow for title and status bars.
48 topPosition = window.screen.height / 2 - (height / 2 + 50);
49 let windowFeatures =
50 "height=" +
51 height +
52 ",width=" +
53 width +
54 ",resizable=yes,left=" +
55 leftPosition +
56 ",top=" +
57 topPosition +
58 ",screenX=" +
59 leftPosition +
60 ",screenY=" +
61 topPosition;
62 window.open(share_url, "sharer", windowFeatures);
63 // For Share count add
64 let id = $(this)
65 .parents(".ultp-post-share-item-inner-block")
66 .attr("postId");
67 let count = $(this)
68 .parents(".ultp-post-share-item-inner-block")
69 .attr("count");
70 $.ajax({
71 url: ultp_data_frontend.ajax,
72 type: "POST",
73 data: {
74 action: "ultp_share_count",
75 shareCount: count,
76 postId: id,
77 wpnonce: ultp_data_frontend.security,
78 },
79 error: function (xhr) {
80 console.log(
81 "Error occured.please try again" +
82 xhr.statusText +
83 xhr.responseText,
84 );
85 },
86 });
87
88 return false;
89 });
90 });
91 // remove sticky behavior when footer is visible
92 $(window).on("scroll", function () {
93 if (
94 $(window).scrollTop() + window.innerHeight >=
95 $("footer")?.offset()?.top
96 ) {
97 $(
98 ".wp-block-ultimate-post-post_share .ultp-block-wrapper .ultp-disable-sticky-footer",
99 ).addClass("remove-sticky");
100 } else {
101 $(
102 ".wp-block-ultimate-post-post_share .ultp-block-wrapper .ultp-disable-sticky-footer",
103 ).removeClass("remove-sticky");
104 }
105 });
106
107 // *************************************
108 // News Ticker
109 // *************************************
110 $(".ultp-news-ticker").each(function () {
111 $(this).UltpSlider({
112 type: $(this).data("type"),
113 direction: $(this).data("direction"),
114 speed: $(this).data("speed"),
115 pauseOnHover: $(this).data("hover") == 1 ? true : false,
116 controls: {
117 prev: $(this)
118 .closest(".ultp-newsTicker-wrap")
119 .find(".ultp-news-ticker-prev"),
120 next: $(this)
121 .closest(".ultp-newsTicker-wrap")
122 .find(".ultp-news-ticker-next"),
123 toggle: $(this)
124 .closest(".ultp-newsTicker-wrap")
125 .find(".ultp-news-ticker-pause"),
126 },
127 });
128 });
129
130 // *************************************
131 // Table of Contents
132 // *************************************
133 $(".ultp-toc-backtotop").on("click", function (e) {
134 e.preventDefault();
135 $("html, body").animate({ scrollTop: 0 }, "slow");
136 });
137
138 $(window).on("scroll", function () {
139 scrollTopButton();
140 });
141
142 function scrollTopButton() {
143 if ($(document).scrollTop() > 1000) {
144 $(".ultp-toc-backtotop").addClass("tocshow");
145 $(".wp-block-ultimate-post-table-of-content").addClass("ultp-toc-scroll");
146 } else {
147 $(".ultp-toc-backtotop").removeClass("tocshow");
148 $(".wp-block-ultimate-post-table-of-content").removeClass(
149 "ultp-toc-scroll",
150 );
151 }
152 }
153 scrollTopButton();
154
155 $(".ultp-collapsible-open").on("click", function (e) {
156 $(this)
157 .closest(".ultp-collapsible-toggle")
158 .removeClass("ultp-toggle-collapsed");
159 $(this).parents(".ultp-block-toc").find(".ultp-block-toc-body").show();
160 });
161
162 $(".ultp-collapsible-hide").on("click", function (e) {
163 $(this)
164 .closest(".ultp-collapsible-toggle")
165 .addClass("ultp-toggle-collapsed");
166 $(this).parents(".ultp-block-toc").find(".ultp-block-toc-body").hide();
167 });
168
169 $(".ultp-toc-lists li a").on("click", function () {
170 $([document.documentElement, document.body]).animate(
171 {
172 scrollTop: $($(this).attr("href")).offset().top - 50,
173 },
174 500,
175 );
176 });
177
178 // *************************************
179 // Flex Menu
180 // *************************************
181 $(document).ready(function () {
182 if ($(".ultp-flex-menu").length > 0) {
183 const menuText = $("ul.ultp-flex-menu").data("name");
184 $("ul.ultp-flex-menu").flexMenu({
185 linkText: menuText,
186 linkTextAll: menuText,
187 linkTitle: menuText,
188 });
189 }
190 });
191 $(document).on("click", function (e) {
192 if ($(e.target).closest(".flexMenu-viewMore").length === 0) {
193 $(".flexMenu-viewMore").removeClass("active");
194 $(".flexMenu-viewMore")
195 .children("ul.flexMenu-popup")
196 .css("display", "none");
197 }
198 });
199 $(document).on(
200 "click",
201 ".ultp-filter-navigation .flexMenu-popup .filter-item",
202 function (e) {
203 $(".flexMenu-viewMore").removeClass("active");
204 $(".flexMenu-viewMore")
205 .children("ul.flexMenu-popup")
206 .css("display", "none");
207 },
208 );
209
210 // *************************************
211 // Pagination Block
212 // *************************************
213 $(".ultp-post-grid-parent").each(function () {
214 const grid = $(this).find(".ultp-post-grid-block");
215 const pagiWrapper = $(this).find(".ultp-pagination-block");
216 const pagi = grid.find(".pagination-block-html > div");
217
218 if (pagiWrapper.length < 1 || pagi.length < 1) {
219 return;
220 }
221
222 pagiWrapper
223 .attr("class")
224 .split(" ")
225 .forEach((cl) => {
226 pagi.addClass(cl);
227 });
228
229 pagiWrapper.html(pagi);
230 });
231
232 // *************************************
233 // Previous Next
234 // *************************************
235
236 $(document).off(
237 "click",
238 ".ultp-pagination-ajax-action li, .ultp-loadmore-action, .ultp-prev-action, .ultp-next-action",
239 function (e) {},
240 );
241 $(document).on("click", ".ultp-prev-action, .ultp-next-action", function (e) {
242 e.preventDefault();
243 let parents = $(this).closest(".ultp-next-prev-wrap"),
244 wrap = parents
245 .closest(".ultp-block-wrapper")
246 .find(".ultp-block-items-wrap"),
247 paged = parseInt(parents.data("pagenum")),
248 pages = parseInt(parents.data("pages")),
249 blockWrapper = parents.closest(".ultp-block-wrapper");
250
251 const postBlock = parents.parents(".ultp-post-grid-parent");
252
253 // Pagination block integration
254 if (wrap.length < 1) {
255 const pagiFor = parents.data("for");
256 if (pagiFor) {
257 wrap = $("." + pagiFor + " .ultp-block-items-wrap");
258 }
259 }
260
261 if (parents.is(".ultp-disable-editor-click")) {
262 return;
263 }
264 if ($(this).hasClass("ultp-prev-action")) {
265 if ($(this).hasClass("ultp-disable")) {
266 return;
267 } else {
268 paged--;
269 parents.data("pagenum", paged);
270 parents
271 .find(".ultp-prev-action, .ultp-next-action")
272 .removeClass("ultp-disable");
273 if (paged == 1) {
274 $(this).addClass("ultp-disable");
275 }
276 }
277 }
278 if ($(this).hasClass("ultp-next-action")) {
279 if ($(this).hasClass("ultp-disable")) {
280 return;
281 } else {
282 paged++;
283 parents.data("pagenum", paged);
284 parents
285 .find(".ultp-prev-action, .ultp-next-action")
286 .removeClass("ultp-disable");
287 if (paged == pages) {
288 $(this).addClass("ultp-disable");
289 }
290 }
291 }
292
293 let post_ID =
294 parents.parents(".ultp-shortcode").length != 0 &&
295 parents.data("selfpostid") == "no"
296 ? parents.parents(".ultp-shortcode").data("postid")
297 : parents.data("postid");
298
299 if ($(this).closest(".ultp-builder-content").length > 0) {
300 post_ID = $(this).closest(".ultp-builder-content").data("postid");
301 }
302 let widgetBlockId = "";
303 let widgetBlock = $(this).parents(".widget_block:first");
304 if (widgetBlock.length > 0) {
305 let widget_items = widgetBlock.attr("id").split("-");
306 widgetBlockId = widget_items[widget_items.length - 1];
307 }
308 const ultpUniqueIds = sessionStorage.getItem("ultp_uniqueIds");
309 const ultpCurrentUniquePosts = JSON.stringify(
310 wrap.find(".ultp-current-unique-posts").data("current-unique-posts"),
311 );
312
313 // Adv Filter Integration
314 const filterValue = parents.data("filter-value") || "";
315 const advFilterData = {};
316
317 if (Array.isArray(filterValue) && filterValue.length > 0) {
318 advFilterData.filterShow = true;
319 advFilterData.checkFilter = true;
320 advFilterData.isAdv = true;
321 advFilterData.author = parents.data("filter-author") || "";
322 advFilterData.order = parents.data("filter-order") || "";
323 advFilterData.orderby = parents.data("filter-orderby") || "";
324 advFilterData.adv_sort = parents.data("filter-adv-sort") || "";
325 }
326
327 $.ajax({
328 url: ultp_data_frontend.ajax,
329 type: "POST",
330 data: {
331 action: "ultp_next_prev",
332 paged: paged,
333 blockId: parents.data("blockid"),
334 postId: post_ID,
335 exclude: parents.data("expost"),
336 blockName: parents.data("blockname"),
337 builder: parents.data("builder"),
338 filterValue: filterValue,
339 filterType: parents.data("filter-type") || "",
340 widgetBlockId: widgetBlockId,
341 ultpUniqueIds: ultpUniqueIds || [],
342 ultpCurrentUniquePosts: ultpCurrentUniquePosts || [],
343
344 ...advFilterData,
345
346 wpnonce: ultp_data_frontend.security,
347 },
348 beforeSend: function () {
349 if (blockWrapper.length < 1 && postBlock.length > 0) {
350 postBlock.find(".ultp-block-wrapper").addClass("ultp-loading-active");
351 } else {
352 blockWrapper.addClass("ultp-loading-active");
353 }
354 },
355 success: function (data) {
356 if (data) {
357 wrap.html(data);
358 setSession(
359 "ultp_uniqueIds",
360 JSON.stringify(
361 wrap.find(".ultp-current-unique-posts").data("ultp-unique-ids"),
362 ),
363 );
364 if ($(window).scrollTop() > wrap.offset().top) {
365 $([document.documentElement, document.body]).animate(
366 {
367 scrollTop: wrap.offset().top - 80,
368 },
369 100,
370 );
371 }
372 }
373 },
374 complete: function () {
375 if (blockWrapper.length < 1 && postBlock.length > 0) {
376 postBlock
377 .find(".ultp-block-wrapper")
378 .removeClass("ultp-loading-active");
379 } else {
380 blockWrapper.removeClass("ultp-loading-active");
381 }
382 handleDailyMotion();
383 },
384 error: function (xhr) {
385 console.log(
386 "Error occured.please try again" + xhr.statusText + xhr.responseText,
387 );
388 parents
389 .closest(".ultp-block-wrapper")
390 .removeClass("ultp-loading-active");
391 },
392 });
393 });
394
395 // *************************************
396 // Loadmore Append
397 // *************************************
398
399 $(document).on("click", ".ultp-loadmore-action", function (e) {
400 if ($(this).is(".ultp-disable-editor-click")) {
401 return;
402 }
403 e.preventDefault();
404 let that = $(this);
405 let parents = that.closest(".ultp-block-wrapper");
406 let isPagiBlock = false;
407
408 // Pagination block integration
409 if (parents.length < 1) {
410 const pagiFor = that.data("for");
411 if (pagiFor) {
412 parents = $("." + pagiFor + " .ultp-block-wrapper");
413 isPagiBlock = parents.length > 0;
414 }
415 }
416
417 let paged = parseInt(that.data("pagenum"));
418 let pages = parseInt(that.data("pages"));
419
420 if (that.hasClass("ultp-disable")) {
421 return;
422 } else {
423 paged++;
424 that.data("pagenum", paged);
425 if (paged == pages) {
426 $(this).addClass("ultp-disable");
427 } else {
428 $(this).removeClass("ultp-disable");
429 }
430 }
431
432 let post_ID =
433 that.parents(".ultp-shortcode").length != 0 &&
434 that.data("selfpostid") == "no"
435 ? that.parents(".ultp-shortcode").data("postid")
436 : that.data("postid");
437
438 if (that.closest(".ultp-builder-content").length > 0) {
439 post_ID = that.closest(".ultp-builder-content").data("postid");
440 }
441 let widgetBlockId = "";
442 let widgetBlock = $(this).parents(".widget_block:first");
443 if (widgetBlock.length > 0) {
444 let widget_items = widgetBlock.attr("id").split("-");
445 widgetBlockId = widget_items[widget_items.length - 1];
446 }
447
448 const ultpUniqueIds = sessionStorage.getItem("ultp_uniqueIds");
449 const ultpCurrentUniquePosts = JSON.stringify(
450 parents.find(".ultp-current-unique-posts").data("current-unique-posts"),
451 );
452
453 // Adv Filter Integration
454 const filterValue = that.data("filter-value") || "";
455 const advFilterData = {};
456
457 if (Array.isArray(filterValue) && filterValue.length > 0) {
458 advFilterData.filterShow = true;
459 advFilterData.checkFilter = true;
460 advFilterData.isAdv = true;
461 advFilterData.author = that.data("filter-author") || "";
462 advFilterData.order = that.data("filter-order") || "";
463 advFilterData.orderby = that.data("filter-orderby") || "";
464 advFilterData.adv_sort = that.data("filter-adv-sort") || "";
465 }
466
467 $.ajax({
468 url: ultp_data_frontend.ajax,
469 type: "POST",
470 data: {
471 action: "ultp_next_prev",
472 paged: paged,
473 blockId: that.data("blockid"),
474 postId: post_ID,
475 blockName: that.data("blockname"),
476 builder: that.data("builder"),
477 exclude: that.data("expost"),
478 filterValue: filterValue,
479 filterType: that.data("filter-type") || "",
480 widgetBlockId: widgetBlockId,
481 ultpUniqueIds: ultpUniqueIds || [],
482 ultpCurrentUniquePosts: ultpCurrentUniquePosts || [],
483
484 ...advFilterData,
485
486 wpnonce: ultp_data_frontend.security,
487 },
488 beforeSend: function () {
489 parents.addClass("ultp-loading-active");
490
491 if (isPagiBlock) {
492 that.find(".ultp-spin").css("display", "flex");
493 }
494 },
495
496 success: function (data) {
497 if (data) {
498 // Fix for grids that have fixed max-height (Adv Pagination Block integration)
499 parents.find(".ultp-block-row").css("max-height", "unset");
500
501 parents.find(".ultp-current-unique-posts").remove();
502
503 const insertPoint = parents.find(".ultp-loadmore-insert-before");
504
505 if (insertPoint.length) {
506 // Adv Pagination block loadmore fix for post modules
507 if (that.data("blockname").includes("post-module")) {
508 $(
509 '<div style="clear:left;width:100%;padding-block:15px;"></div>',
510 ).insertBefore(insertPoint);
511 }
512
513 $(data).insertBefore(insertPoint);
514 } else {
515 const cardDiv = parents.find(".ultp-block-items-wrap");
516
517 if (that.data("blockname").includes("post-module")) {
518 cardDiv.append(
519 $(
520 '<div style="clear:left;width:100%;padding-block:15px;"></div>',
521 ),
522 );
523 }
524
525 cardDiv.append(data);
526 }
527
528 setSession(
529 "ultp_uniqueIds",
530 JSON.stringify(
531 parents
532 .find(".ultp-current-unique-posts")
533 .data("ultp-unique-ids"),
534 ),
535 );
536 }
537 },
538
539 complete: function () {
540 parents.removeClass("ultp-loading-active");
541
542 if (isPagiBlock) {
543 that.find(".ultp-spin").css("display", "none");
544 }
545 },
546
547 error: function (xhr) {
548 console.log(
549 "Error occured.please try again" + xhr.statusText + xhr.responseText,
550 );
551 parents.removeClass("ultp-loading-active");
552
553 if (isPagiBlock) {
554 that.find(".ultp-spin").css("display", "none");
555 }
556 },
557 });
558 });
559
560 // *************************************
561 // Filter
562 // *************************************
563 $(document).on("click", ".ultp-filter-wrap li a", async function (e) {
564 e.preventDefault();
565 const ultpNonce = await getUltpNonce();
566 if ($(this).closest("li").hasClass("filter-item")) {
567 let that = $(this),
568 parents = that.closest(".ultp-filter-wrap"),
569 wrap = that.closest(".ultp-block-wrapper");
570 const postBlock = that.parents(".ultp-post-grid-parent");
571
572 parents.find("a").removeClass("filter-active");
573 that.addClass("filter-active");
574 if (parents.is(".ultp-disable-editor-click")) {
575 return;
576 }
577 let post_ID =
578 parents.parents(".ultp-shortcode").length != 0 &&
579 parents.data("selfpostid") == "no"
580 ? parents.parents(".ultp-shortcode").data("postid")
581 : parents.data("postid");
582
583 if (that.closest(".ultp-builder-content").length > 0) {
584 post_ID = that.closest(".ultp-builder-content").data("postid");
585 }
586 let widgetBlockId = "";
587 let widgetBlock = $(this).parents(".widget_block:first");
588 if (widgetBlock.length > 0) {
589 let widget_items = widgetBlock.attr("id").split("-");
590 widgetBlockId = widget_items[widget_items.length - 1];
591 }
592
593 const ultpUniqueIds = sessionStorage.getItem("ultp_uniqueIds");
594 const ultpCurrentUniquePosts = JSON.stringify(
595 wrap.find(".ultp-current-unique-posts").data("current-unique-posts"),
596 );
597
598 if (parents.data("blockid")) {
599 $.ajax({
600 url: ultp_data_frontend.ajax,
601 type: "POST",
602 data: {
603 action: "ultp_filter",
604 taxtype: parents.data("taxtype"),
605 taxonomy: that.data("taxonomy"),
606 blockId: parents.data("blockid"),
607 postId: post_ID,
608 blockName: parents.data("blockname"),
609 widgetBlockId: widgetBlockId,
610 ultpUniqueIds: ultpUniqueIds || [],
611 ultpCurrentUniquePosts: ultpCurrentUniquePosts || [],
612 wpnonce: ultpNonce,
613 },
614 beforeSend: function () {
615 wrap.addClass("ultp-loading-active");
616 },
617 success: function (response) {
618 wrap
619 .find(".ultp-block-items-wrap")
620 .html(response?.data?.filteredData?.blocks);
621 if (
622 response?.data?.filteredData?.paginationType == "loadMore" &&
623 response?.data?.filteredData?.paginationShow
624 ) {
625 // wrap.find('.ultp-block-items-wrap').append('<span class="ultp-loadmore-insert-before"></span>');
626
627 wrap
628 .find(".ultp-loadmore")
629 .replaceWith(response?.data?.filteredData?.pagination);
630 } else if (
631 response?.data?.filteredData?.paginationType == "navigation"
632 ) {
633 wrap
634 .find(".ultp-next-prev-wrap")
635 .replaceWith(response?.data?.filteredData?.pagination);
636 } else if (
637 response?.data?.filteredData?.paginationType == "pagination"
638 ) {
639 wrap
640 .find(".ultp-pagination-wrap")
641 .replaceWith(response?.data?.filteredData?.pagination);
642 }
643
644 // Adv Pagination Block Integration
645 if (
646 response?.data?.filteredData?.pagination &&
647 postBlock.length > 0
648 ) {
649 postBlock.data("pagi")?.map((pagiClass) => {
650 let pagi = [];
651
652 if (
653 response?.data?.filteredData?.paginationType === "loadMore"
654 ) {
655 pagi = $(".ultp-loadmore." + pagiClass);
656 if (pagi.length > 0) {
657 // wrap.find('.ultp-block-items-wrap').append('<span class="ultp-loadmore-insert-before"></span>');
658 }
659 } else {
660 pagi = $("." + pagiClass + "[data-for]");
661 }
662
663 if (pagi.length > 0) {
664 const newPagi = $(response.data.filteredData.pagination);
665 pagi
666 .attr("class")
667 .split(" ")
668 .forEach((cl) => newPagi.addClass(cl));
669 pagi.replaceWith(newPagi);
670 }
671 });
672 }
673 },
674 complete: function () {
675 wrap.removeClass("ultp-loading-active");
676 setSession(
677 "ultp_uniqueIds",
678 JSON.stringify(
679 wrap.find(".ultp-current-unique-posts").data("ultp-unique-ids"),
680 ),
681 );
682 handleDailyMotion();
683 },
684 error: function (xhr) {
685 console.log(
686 "Error occured.please try again" +
687 xhr.statusText +
688 xhr.responseText,
689 );
690 wrap.removeClass("ultp-loading-active");
691 },
692 });
693 }
694 }
695 });
696
697 // *************************************
698 // Pagination Number
699 // *************************************
700 function showHide(parents, pageNum, pages) {
701 if (pageNum == pages) {
702 parents.find(".ultp-next-page-numbers").hide();
703 } else {
704 parents.find(".ultp-next-page-numbers").show();
705 }
706
707 if (pageNum > 1) {
708 parents.find(".ultp-prev-page-numbers").show();
709 } else {
710 parents.find(".ultp-prev-page-numbers").hide();
711 }
712
713 if (pageNum > 3) {
714 parents.find(".ultp-first-dot").show();
715 } else {
716 parents.find(".ultp-first-dot").hide();
717 }
718
719 if (pageNum > 2) {
720 parents.find(".ultp-first-pages").show();
721 } else {
722 parents.find(".ultp-first-pages").hide();
723 }
724
725 if (pages > pageNum + 2) {
726 parents.find(".ultp-last-dot").show();
727 } else {
728 parents.find(".ultp-last-dot").hide();
729 }
730
731 if (pages > pageNum + 1) {
732 parents.find(".ultp-last-pages").show();
733 } else {
734 parents.find(".ultp-last-pages").hide();
735 }
736 }
737
738 function serial(parents, pageNum, pages) {
739 let datas =
740 pageNum <= 2
741 ? [1, 2, 3]
742 : pages == pageNum
743 ? [pages - 2, pages - 1, pages]
744 : [pageNum - 1, pageNum, pageNum + 1];
745 let i = 0;
746 parents.find(".ultp-center-item").each(function () {
747 if (pageNum == datas[i]) {
748 $(this).addClass("pagination-active");
749 }
750 $(this).find("a").blur();
751 $(this).attr("data-current", datas[i]).find("a").text(datas[i]);
752 i++;
753 });
754 parents.find(".ultp-prev-page-numbers a").blur();
755 parents.find(".ultp-next-page-numbers a").blur();
756 }
757
758 // set session value for unique content on page reload
759 if ($(".ultp-current-unique-posts").length > 0) {
760 $(".ultp-current-unique-posts").each(function () {
761 setSession(
762 "ultp_uniqueIds",
763 JSON.stringify($(this).data("ultp-unique-ids")),
764 );
765 });
766 }
767 // session value set function
768 function setSession(key, value) {
769 if (value != undefined) {
770 sessionStorage.setItem(key, value);
771 }
772 }
773
774 function getCurrPage(blockId) {
775 const params = new URLSearchParams(window.location.search);
776 const page = params.get(blockId + "_page");
777 return page ? +page : 1;
778 }
779
780 function setCurrPage(blockId, currPage, prevPage) {
781 const params = new URLSearchParams(window.location.search);
782 params.set(`${blockId}_page`, currPage);
783 const url = window.location.pathname + "?" + params.toString();
784
785 window.history.replaceState(
786 {
787 page: {
788 [blockId]: prevPage,
789 },
790 },
791 document.title,
792 url,
793 );
794 }
795
796 // *************************************
797 // Common Pagination AJAX Dispatcher
798 // *************************************
799 function paginationAjaxCall({
800 wrap, // .ultp-block-wrapper Selector
801 builder, // Get Builder Data
802 post_ID,
803 exclude,
804 pageNum,
805 blockid,
806 ultpNonce, // Get Nonce
807 blockName,
808 filterType,
809 widgetBlockId,
810 ultpCurrentUniquePosts,
811 filterValue,
812 advFilterData = {},
813 onSuccess,
814 onBeforeSend,
815 }) {
816 if (!pageNum) return;
817
818 const ultpUniqueIds = sessionStorage.getItem("ultp_uniqueIds");
819
820 // console.log({
821 // exclude,
822 // action: "ultp_pagination",
823 // paged: pageNum,
824 // blockId: blockid,
825 // postId: post_ID,
826 // blockName,
827 // builder,
828 // widgetBlockId,
829 // ultpUniqueIds: ultpUniqueIds || [],
830 // ultpCurrentUniquePosts: ultpCurrentUniquePosts || [],
831 // filterType: filterType || "",
832 // wpnonce: ultpNonce,
833 // filterValue,
834 // ...advFilterData,
835 // });
836
837 $.ajax({
838 url: ultp_data_frontend.ajax,
839 type: "POST",
840 data: {
841 exclude,
842 action: "ultp_pagination",
843 paged: pageNum,
844 blockId: blockid,
845 postId: post_ID,
846 blockName,
847 builder,
848 widgetBlockId,
849 ultpUniqueIds: ultpUniqueIds || [],
850 ultpCurrentUniquePosts: ultpCurrentUniquePosts || [],
851 filterType: filterType || "",
852 wpnonce: ultpNonce,
853 filterValue,
854 ...advFilterData,
855 },
856 beforeSend() {
857 if (typeof onBeforeSend === "function") {
858 onBeforeSend();
859 } else {
860 wrap.addClass("ultp-loading-active");
861 }
862 },
863 success(data) {
864 if (typeof onSuccess === "function") onSuccess(data);
865 },
866 complete() {
867 wrap.removeClass("ultp-loading-active");
868 handleDailyMotion();
869 },
870 error(xhr) {
871 console.log(
872 "Error occured. please try again " +
873 xhr.statusText +
874 xhr.responseText,
875 );
876 wrap.removeClass("ultp-loading-active");
877 },
878 });
879 }
880
881 $(document).on(
882 "click",
883 ".ultp-pagination-ajax-action li",
884 async function (e) {
885 e.preventDefault();
886 const ultpNonce = await getUltpNonce();
887
888 let that = $(this),
889 parents = that.closest(".ultp-pagination-ajax-action"),
890 wrap = that.closest(".ultp-block-wrapper");
891
892 if (parents.is(".ultp-disable-editor-click")) {
893 return;
894 }
895
896 let pageNum = 1;
897 let pages = parents.attr("data-pages");
898
899 const exclude = parents.data("expost");
900 const builder = parents.data("builder");
901 const blockName = parents.data("blockname");
902 const blockid = parents.attr("data-blockid");
903 const filterType = parents.data("filter-type") || "";
904 const filterValue = parents.data("filter-value") || "";
905
906 // Pagination block integration
907 if (wrap.length < 1) {
908 const pagiFor = parents.data("for");
909 if (pagiFor) {
910 wrap = $("." + pagiFor + " .ultp-block-wrapper");
911 }
912 }
913
914 if (that.attr("data-current")) {
915 pageNum = Number(that.attr("data-current"));
916 parents
917 .attr("data-paged", pageNum)
918 .find("li")
919 .removeClass("pagination-active");
920 serial(parents, pageNum, pages);
921 showHide(parents, pageNum, pages);
922 } else {
923 if (that.hasClass("ultp-prev-page-numbers")) {
924 pageNum = Number(parents.attr("data-paged")) - 1;
925 parents
926 .attr("data-paged", pageNum)
927 .find("li")
928 .removeClass("pagination-active");
929 //parents.find('li[data-current="'+pageNum+'"]').addClass('pagination-active')
930 serial(parents, pageNum, pages);
931 showHide(parents, pageNum, pages);
932 } else if (that.hasClass("ultp-next-page-numbers")) {
933 pageNum = Number(parents.attr("data-paged")) + 1;
934 parents
935 .attr("data-paged", pageNum)
936 .find("li")
937 .removeClass("pagination-active");
938 //parents.find('li[data-current="'+pageNum+'"]').addClass('pagination-active')
939 serial(parents, pageNum, pages);
940 showHide(parents, pageNum, pages);
941 }
942 }
943
944 let widgetBlockId = "";
945 let widgetBlock = that.parents(".widget_block:first");
946 if (widgetBlock.length > 0) {
947 let widget_items = widgetBlock.attr("id").split("-");
948 widgetBlockId = widget_items[widget_items.length - 1];
949 }
950
951 const ultpCurrentUniquePosts = JSON.stringify(
952 wrap.find(".ultp-current-unique-posts").data("current-unique-posts"),
953 );
954
955 let post_ID =
956 parents.parents(".ultp-shortcode").length != 0 &&
957 parents.data("selfpostid") == "no"
958 ? parents.parents(".ultp-shortcode").data("postid")
959 : parents.data("postid");
960
961 if (that.closest(".ultp-builder-content").length > 0) {
962 post_ID = that.closest(".ultp-builder-content").data("postid");
963 }
964
965 // Build adv filter data from pagination element
966 const advFilterData = {};
967 if (Array.isArray(filterValue) && filterValue.length > 0) {
968 advFilterData.filterShow = true;
969 advFilterData.checkFilter = true;
970 advFilterData.isAdv = true;
971 advFilterData.author = parents.data("filter-author") || "";
972 advFilterData.order = parents.data("filter-order") || "";
973 advFilterData.orderby = parents.data("filter-orderby") || "";
974 advFilterData.adv_sort = parents.data("filter-adv-sort") || "";
975 }
976
977 if (blockid) {
978 setCurrPage(blockid, pageNum, getCurrPage(blockid));
979 }
980
981 // console.log(advFilterData, "advFilterData");
982 paginationAjaxCall({
983 wrap,
984 pageNum,
985 blockid,
986 ultpNonce,
987 blockName,
988 post_ID,
989 filterType,
990 ultpCurrentUniquePosts,
991 widgetBlockId,
992 exclude,
993 builder,
994 filterValue,
995 advFilterData,
996 onSuccess(data) {
997 wrap.find(".ultp-block-items-wrap").html(data);
998 setSession(
999 "ultp_uniqueIds",
1000 JSON.stringify(
1001 wrap.find(".ultp-current-unique-posts").data("ultp-unique-ids"),
1002 ),
1003 );
1004 if ($(window).scrollTop() > wrap.offset().top) {
1005 $([document.documentElement, document.body]).animate(
1006 { scrollTop: wrap.offset().top - 80 },
1007 100,
1008 );
1009 }
1010 },
1011 });
1012 },
1013 );
1014
1015 // *************************************
1016 // SlideShow
1017 // *************************************
1018
1019 // Slideshow Display For Elementor via Shortcode
1020 $(window).on("elementor/frontend/init", () => {
1021 setTimeout(() => {
1022 if ($(".elementor-editor-active").length > 0) {
1023 slideshowDisplay();
1024 }
1025 }, 2000);
1026 });
1027
1028 // Bricks Builder Backend Slider Support
1029 // Bricks Builder Backend Slider Support
1030 if (
1031 $(".bricks-builder-iframe").length > 0 &&
1032 $(window.parent.document).find(".bricks-panel-controls").length > 0
1033 ) {
1034 setTimeout(() => {
1035 slideshowDisplay();
1036 }, 2500);
1037 }
1038
1039 function slideshowDisplay() {
1040 $(
1041 ".wp-block-ultimate-post-post-slider-1, .wp-block-ultimate-post-post-slider-2",
1042 ).each(function () {
1043 const sectionId = "#" + $(this).attr("id");
1044 let selector = $(sectionId).find(".ultp-block-items-wrap");
1045 if ($(this).parent(".ultp-shortcode")) {
1046 selector = $(this).find(".ultp-block-items-wrap");
1047 }
1048 let settings = {
1049 arrows: true,
1050 dots: selector.data("dots") ? true : false,
1051 infinite: true,
1052 speed: 500,
1053 slidesToShow: selector.data("slidelg") || 1,
1054 slidesToScroll: 1,
1055 autoplay: selector.data("autoplay") ? true : false,
1056 autoplaySpeed: selector.data("slidespeed") || 3000,
1057 cssEase: "linear",
1058 prevArrow: selector.parent().find(".ultp-slick-prev").html(),
1059 nextArrow: selector.parent().find(".ultp-slick-next").html(),
1060 };
1061
1062 let layTemp =
1063 selector.data("layout") == "slide2" ||
1064 selector.data("layout") == "slide3" ||
1065 selector.data("layout") == "slide5" ||
1066 selector.data("layout") == "slide6" ||
1067 selector.data("layout") == "slide8";
1068
1069 if (!selector.data("layout")) {
1070 // Slider 1
1071 if (selector.data("slidelg") < 2) {
1072 settings.fade = selector.data("fade") ? true : false;
1073 } else {
1074 settings.responsive = [
1075 {
1076 breakpoint: 1024,
1077 settings: {
1078 slidesToShow: selector.data("slidesm") || 1,
1079 slidesToScroll: 1,
1080 },
1081 },
1082 {
1083 breakpoint: 600,
1084 settings: {
1085 slidesToShow: selector.data("slidexs") || 1,
1086 slidesToScroll: 1,
1087 },
1088 },
1089 ];
1090 }
1091 } else {
1092 // Slider 2
1093 if (selector.data("fade") && layTemp) {
1094 settings.fade = selector.data("fade") ? true : false;
1095 } else if (!selector.data("fade") && layTemp) {
1096 ((settings.slidesToShow = selector.data("slidelg") || 1),
1097 (settings.responsive = [
1098 {
1099 breakpoint: 991,
1100 settings: {
1101 slidesToShow: selector.data("slidesm") || 1,
1102 slidesToScroll: 1,
1103 },
1104 },
1105 {
1106 breakpoint: 767,
1107 settings: {
1108 slidesToShow: selector.data("slidexs") || 1,
1109 slidesToScroll: 1,
1110 },
1111 },
1112 ]));
1113 } else {
1114 ((settings.slidesToShow = selector.data("slidelg") || 1),
1115 (settings.centerMode = true));
1116 settings.centerPadding = `${selector.data("paddlg")}px` || 100;
1117 settings.responsive = [
1118 {
1119 breakpoint: 991,
1120 settings: {
1121 slidesToShow: selector.data("slidesm") || 1,
1122 slidesToScroll: 1,
1123 centerPadding: `${selector.data("paddsm")}px` || 50,
1124 },
1125 },
1126 {
1127 breakpoint: 767,
1128 settings: {
1129 slidesToShow: selector.data("slidexs") || 1,
1130 slidesToScroll: 1,
1131 centerPadding: `${selector.data("paddxs")}px` || 50,
1132 },
1133 },
1134 ];
1135 }
1136 }
1137 selector.not(".slick-initialized").slick(settings);
1138 });
1139 }
1140 slideshowDisplay();
1141
1142 // *************************************
1143 // Accessibility for Loadmore Added
1144 // *************************************
1145 $('span[role="button"].ultp-loadmore-action').on("keydown", function (e) {
1146 const keyD = e.key !== undefined ? e.key : e.keyCode;
1147 if (
1148 keyD === "Enter" ||
1149 keyD === 13 ||
1150 ["Spacebar", " "].indexOf(keyD) >= 0 ||
1151 keyD === 32
1152 ) {
1153 e.preventDefault();
1154 this.click();
1155 }
1156 });
1157 // *************************************
1158 // Video Scroll
1159 // *************************************
1160 let isSticky = true;
1161 $(window).on("scroll", function () {
1162 let windowHeight = $(this).scrollTop();
1163 $(".wp-block-ultimate-post-post-image").each(function () {
1164 let contentSelector = $(this).find(
1165 ".ultp-builder-video video , .ultp-builder-video iframe",
1166 );
1167 if ($(this).find(".ultp-video-block").hasClass("ultp-sticky-video")) {
1168 // block height and position
1169 let blockContent = $(this).find(".ultp-image-wrapper");
1170 let blockPosition = blockContent.offset();
1171 // Video Html height and position
1172 let videoContent = contentSelector.height();
1173 let videoPosition = contentSelector.offset();
1174 // Exclude Adminbar height
1175 let windowTotalHeight = windowHeight + ($("#wpadminbar").height() || 0);
1176 let totalHeight = videoPosition.top + videoContent;
1177 // Scrolling Top to bottom
1178 if (windowTotalHeight > videoPosition.top) {
1179 if (windowTotalHeight > totalHeight && isSticky) {
1180 $(this)
1181 .find(".ultp-image-wrapper")
1182 .css("height", blockContent.height());
1183 $(this).find(".ultp-sticky-video").addClass("ultp-sticky-active");
1184 }
1185 }
1186 // Scrolling bottom to top
1187 if (windowTotalHeight < blockContent.height() + blockPosition.top) {
1188 $(this).find(".ultp-sticky-video").removeClass("ultp-sticky-active");
1189 $(this).find(".ultp-image-wrapper").css("height", "auto");
1190 }
1191 // Close Button
1192 $(".ultp-sticky-close").on("click", function () {
1193 $(this).find(".ultp-image-wrapper").css("height", "auto");
1194 $(".ultp-sticky-video").removeClass("ultp-sticky-active");
1195 isSticky = false;
1196 });
1197 }
1198 });
1199 });
1200
1201 // *************************************
1202 // Advanced Filter
1203 // *************************************
1204 function getTax(name) {
1205 switch (name) {
1206 case "categories":
1207 return "category";
1208 case "tag":
1209 case "tags":
1210 return "post_tag";
1211 case "authors":
1212 return "author";
1213 case "order_by":
1214 return "orderby";
1215 default:
1216 return name;
1217 }
1218 }
1219
1220 function getFormattedSelectedFilter(type, name) {
1221 const fType = type
1222 .replace("_", " ")
1223 .replace(/\b\w/g, (l) => l.toUpperCase());
1224 return `${fType}: ${name}`;
1225 }
1226
1227 function applyFilter(parent, blockId, blockName, postId, grids, builder) {
1228 const selectedFilters = [];
1229 const filterData = {};
1230 const pagis = parent.data("pagi");
1231
1232 parent.find(".ultp-filter-select").each(function () {
1233 const type = $(this).attr("data-type");
1234 const selected = $(this).attr("data-selected");
1235 const cTax = $(this)
1236 .find('.ultp-filter-select__dropdown-inner[data-id="' + selected + '"]')
1237 .data("tax");
1238 if (getTax(type) === "author") {
1239 if (selected !== "_all") {
1240 filterData.author = [{ value: selected }];
1241 }
1242 return;
1243 }
1244 if (getTax(type) === "order") {
1245 filterData.order = selected;
1246 return;
1247 }
1248 if (getTax(type) === "orderby") {
1249 filterData.orderby = selected;
1250 return;
1251 }
1252 if (getTax(type) === "adv_sort") {
1253 filterData.adv_sort = selected;
1254 return;
1255 }
1256 if (getTax(type) === "custom_tax") {
1257 if (cTax) {
1258 selectedFilters.push({
1259 value: cTax + "###" + selected,
1260 });
1261 }
1262 return;
1263 }
1264 selectedFilters.push({
1265 value: getTax(type) + "###" + selected,
1266 });
1267 });
1268
1269 parent.find('.ultp-filter-button[data-is-active="true"]').each(function () {
1270 const type = $(this).attr("data-type");
1271 const selected = $(this).attr("data-selected");
1272 const cTax = $(this).attr("data-tax");
1273
1274 if (getTax(type) === "author") {
1275 if (selected !== "_all") {
1276 filterData.author = [{ value: selected }];
1277 }
1278 return;
1279 }
1280
1281 if (getTax(type) === "order") {
1282 filterData.order = selected;
1283 return;
1284 }
1285
1286 if (getTax(type) === "orderby") {
1287 filterData.orderby = selected;
1288 return;
1289 }
1290
1291 if (getTax(type) === "adv_sort") {
1292 filterData.adv_sort = selected;
1293 return;
1294 }
1295
1296 if (getTax(type) === "custom_tax") {
1297 if (cTax) {
1298 selectedFilters.push({
1299 value: cTax + "###" + selected,
1300 });
1301 }
1302 return;
1303 }
1304 selectedFilters.push({
1305 value: getTax(type) + "###" + selected,
1306 });
1307 });
1308
1309 filterData.taxonomy = selectedFilters;
1310
1311 const searchVal = parent.find(".ultp-filter-search input");
1312
1313 if (searchVal.length > 0) {
1314 filterData.search = searchVal.val();
1315 }
1316
1317 const ultpUniqueIds = sessionStorage.getItem("ultp_uniqueIds");
1318 const ultpCurrentUniquePosts = JSON.stringify(
1319 parent.find(".ultp-current-unique-posts").data("current-unique-posts"),
1320 );
1321
1322 let widgetBlockId = "";
1323 let widgetBlock = parent.parents(".widget_block:first");
1324 if (widgetBlock.length > 0) {
1325 let widget_items = widgetBlock.attr("id").split("-");
1326 widgetBlockId = widget_items[widget_items.length - 1];
1327 }
1328
1329 $(grids).each(function () {
1330 const grid = $(this);
1331
1332 $.ajax({
1333 url: ultp_data_frontend.ajax,
1334 type: "POST",
1335 data: {
1336 action: "ultp_adv_filter",
1337
1338 ...filterData,
1339 builder_id: builder,
1340 blockId: blockId,
1341 blockName: blockName,
1342 postId: postId,
1343 ultpUniqueIds: ultpUniqueIds || [],
1344 ultpCurrentUniquePosts: ultpCurrentUniquePosts || [],
1345 widgetBlockId: widgetBlockId,
1346 wpnonce: ultp_data_frontend.security,
1347 },
1348 beforeSend: function () {
1349 grid.addClass("ultp-loading-active");
1350 },
1351 success: function (response) {
1352 // console.log(
1353 // JSON.parse(response.data.filteredData.data_attrs),
1354 // "response",
1355 // );
1356 console.log("testing", searchVal);
1357 grid
1358 .closest(".wp-block-ultimate-post-post-grid-parent")
1359 ?.find(".ultp-not-found-message")
1360 ?.remove();
1361 if (
1362 response?.data?.filteredData?.blocks === "" &&
1363 response?.data?.filteredData?.notFound
1364 ) {
1365 grid
1366 .closest(".wp-block-ultimate-post-post-grid-parent")
1367 .append(
1368 '<div class="ultp-not-found-message" role="alert">' +
1369 response?.data?.filteredData?.notFound +
1370 "</div>",
1371 );
1372 }
1373 grid
1374 .find(".ultp-block-items-wrap")
1375 .html(response?.data?.filteredData?.blocks);
1376 if (
1377 response?.data?.filteredData?.paginationType == "loadMore" &&
1378 response?.data?.filteredData?.paginationShow
1379 ) {
1380 // grid.find(".ultp-block-items-wrap")
1381 // .append('<span class="ultp-loadmore-insert-before"></span>');
1382 grid
1383 .find(".ultp-loadmore")
1384 .replaceWith(response?.data?.filteredData?.pagination);
1385 } else if (
1386 response?.data?.filteredData?.paginationType == "navigation"
1387 ) {
1388 grid
1389 .find(".ultp-next-prev-wrap")
1390 .replaceWith(response?.data?.filteredData?.pagination);
1391 } else if (
1392 response?.data?.filteredData?.paginationType == "pagination"
1393 ) {
1394 grid
1395 .find(".ultp-pagination-wrap")
1396 .replaceWith(response?.data?.filteredData?.pagination);
1397 }
1398
1399 if (grid.parent().is(".ultp-iscroll-active")) {
1400 const dataAttrs = JSON.parse(response.data.filteredData.data_attrs);
1401
1402 Object.entries(dataAttrs).forEach(([key, value]) => {
1403 if (value !== null && value !== undefined) {
1404 grid.attr("data-" + key, value);
1405 }
1406 });
1407
1408 const iscrollBlock = grid.parent();
1409 iscrollBlock.UltpInfiniteScroll(
1410 iscrollBlock,
1411 setSession,
1412 getUltpNonce,
1413 paginationAjaxCall,
1414 );
1415 }
1416
1417 if (response?.data?.filteredData?.pagination) {
1418 pagis?.map((pagiClass) => {
1419 let pagi = [];
1420
1421 if (response?.data?.filteredData?.paginationType === "loadMore") {
1422 pagi = $(".ultp-loadmore." + pagiClass);
1423 if (pagi.length > 0) {
1424 // grid.find(".ultp-block-items-wrap")
1425 // .append('<span class="ultp-loadmore-insert-before"></span>');
1426 }
1427 } else {
1428 pagi = $("." + pagiClass + "[data-for]");
1429 }
1430
1431 if (pagi.length > 0) {
1432 const newPagi = $(response.data.filteredData.pagination);
1433 pagi
1434 .attr("class")
1435 .split(" ")
1436 .forEach((cl) => newPagi.addClass(cl));
1437 pagi.replaceWith(newPagi);
1438 }
1439 });
1440 }
1441 },
1442 complete: function () {
1443 grid.removeClass("ultp-loading-active");
1444 setSession(
1445 "ultp_uniqueIds",
1446 JSON.stringify(
1447 parent.find(".ultp-current-unique-posts").data("ultp-unique-ids"),
1448 ),
1449 );
1450 },
1451 error: function (xhr) {
1452 console.log(
1453 "Error occured.please try again" +
1454 xhr.statusText +
1455 xhr.responseText,
1456 );
1457 grid.removeClass("ultp-loading-active");
1458 },
1459 });
1460 });
1461 }
1462
1463 $(".ultp-filter-block").each(function () {
1464 const that = $(this);
1465 const parent = $(this).parents(".ultp-post-grid-parent");
1466 const grids = parent.find(".ultp-block-wrapper");
1467 const gridData = JSON.parse(parent.attr("data-grids"));
1468 const selectedFilterTemp = $(this).find(".ultp-filter-clear-template");
1469 const clearBtn = $(this).find(".ultp-filter-clear-button");
1470 const firstElClass = "ultp-block-" + clearBtn.data("blockid") + "-first";
1471 let postId = "";
1472 let builder = "";
1473
1474 function resetFilters() {
1475 // Resetting select fields
1476 that.find(".ultp-filter-select").each(function () {
1477 const defVal = $(this).find(".ultp-filter-select-options li").first();
1478 $(this).attr("data-selected", defVal.attr("data-id"));
1479 $(this).find(".ultp-filter-select-field-selected").text(defVal.text());
1480 });
1481
1482 // Resetting clear button
1483 const selectedFilter = that.find(".ultp-filter-clear-selected-filter");
1484 if (selectedFilter.hasClass(firstElClass)) {
1485 clearBtn.addClass(firstElClass);
1486 }
1487 selectedFilter.remove();
1488
1489 // Resetting search input
1490 that.find(".ultp-filter-search input").val("");
1491
1492 // Resetting filter buttons
1493 that.find('.ultp-filter-button[data-is-active="true"]').each(function () {
1494 $(this).removeClass("ultp-filter-button-active");
1495 $(this).attr("data-is-active", "false");
1496 });
1497 }
1498
1499 function fetchPostsWithFilter() {
1500 gridData.forEach((data) => {
1501 applyFilter(
1502 parent,
1503 data["blockId"],
1504 data["name"],
1505 postId,
1506 grids,
1507 builder,
1508 );
1509 });
1510 }
1511
1512 that.find(".ultp-filter-select").each(function () {
1513 const dropdown = $(this).find(".ultp-filter-select-options");
1514 const selected = $(this).find(".ultp-filter-select-field-selected");
1515 const icon = $(this).find(".ultp-filter-select-field-icon");
1516 const filter = $(this);
1517 const type = $(this).attr("data-type");
1518 const input = $(this).find(".ultp-filter-select-search");
1519 postId = $(this).attr("data-current-postid");
1520 builder = $(this).attr("data-builder");
1521 function showDropdown(show) {
1522 if (show) {
1523 $(".ultp-filter-select .ultp-filter-select-options").css(
1524 "display",
1525 "none",
1526 );
1527 $(".ultp-filter-select .ultp-filter-select-field-icon").removeClass(
1528 "ultp-dropdown-icon-rotate",
1529 );
1530 $(".ultp-filter-select").attr("aria-expanded", false);
1531
1532 dropdown.css("display", "block");
1533 icon.addClass("ultp-dropdown-icon-rotate");
1534 } else {
1535 dropdown.css("display", "none");
1536 icon.removeClass("ultp-dropdown-icon-rotate");
1537 }
1538
1539 filter.attr("aria-expanded", show);
1540 }
1541
1542 const defValue = dropdown.find("li").first();
1543
1544 function resetFilter() {
1545 selected.text(defValue.text());
1546 filter.attr("data-selected", defValue.attr("data-id"));
1547 }
1548
1549 // Toggle on click
1550 $(this).on("click", function (e) {
1551 e.stopPropagation();
1552 showDropdown(dropdown.css("display") === "none");
1553 });
1554
1555 $(dropdown)
1556 .find("li")
1557 .each(function () {
1558 const value = $(this).attr("data-id");
1559 const filterId = $(this).attr("data-blockId");
1560 const text = $(this).text();
1561 $(this).on("click", function () {
1562 selected.text(text);
1563 filter.attr("data-selected", value);
1564
1565 // Selected filters
1566 if (value === "_all") {
1567 that.find(`.ultp-filter-clear[data-type="${type}"]`).remove();
1568 } else if (clearBtn.length > 0) {
1569 let isNew = false;
1570
1571 let copy = that.find(`.ultp-filter-clear[data-type="${type}"]`);
1572
1573 if (copy.length < 1) {
1574 isNew = true;
1575 copy = selectedFilterTemp.clone();
1576 }
1577
1578 copy.removeClass("ultp-filter-clear-template");
1579 copy.addClass("ultp-filter-clear-selected-filter");
1580 copy
1581 .find(".ultp-selected-filter-text")
1582 .text(
1583 getFormattedSelectedFilter(
1584 filter.attr("data-filter-label"),
1585 text,
1586 ),
1587 );
1588 // Alignment
1589 if (clearBtn.hasClass(firstElClass)) {
1590 clearBtn.removeClass(firstElClass);
1591 copy.addClass(firstElClass);
1592 }
1593 copy.find(".ultp-selected-filter-icon").on("click", function () {
1594 resetFilter();
1595 if (copy.hasClass(firstElClass)) {
1596 if (
1597 copy.next().hasClass("ultp-filter-clear-selected-filter")
1598 ) {
1599 copy.next().addClass(firstElClass);
1600 } else {
1601 clearBtn.addClass(firstElClass);
1602 }
1603 }
1604 copy.remove();
1605 fetchPostsWithFilter();
1606 });
1607 copy.attr("data-id", value);
1608 copy.attr("data-type", type);
1609 copy.attr("data-for", filterId);
1610 copy.css({
1611 display: "block",
1612 });
1613 isNew && copy.insertBefore(clearBtn);
1614 }
1615 fetchPostsWithFilter();
1616 showDropdown(true);
1617 });
1618 });
1619
1620 input.on("click", function (e) {
1621 e.preventDefault();
1622 e.stopPropagation();
1623 });
1624
1625 input.on("input", function (e) {
1626 const value = String(e.target.value).toLowerCase();
1627
1628 if (value.length > 0) {
1629 dropdown.find("li").each(function () {
1630 const currValue = $(this).text();
1631 $(this).css(
1632 "display",
1633 currValue.toLowerCase().includes(value) ? "list-item" : "none",
1634 );
1635 });
1636 } else {
1637 dropdown.find("li").each(function () {
1638 $(this).css("display", "list-item");
1639 });
1640 }
1641 });
1642
1643 $(document).on("click", function (e) {
1644 if (!filter.is(e.target) && !filter.has(e.target).length) {
1645 showDropdown(false);
1646 }
1647 });
1648 });
1649
1650 that.find(".ultp-filter-button").each(function () {
1651 const currFBtn = this;
1652 const fBtnType = $(this).data("type");
1653 postId = $(this).attr("data-current-postid");
1654 $(this).on("click", function () {
1655 const isActive = $(currFBtn).attr("data-is-active") === "true";
1656 const value = $(this).data("selected");
1657
1658 // Clicking all button will disable other
1659 if (value === "_all") {
1660 const otherBtns = that.find(
1661 '.ultp-filter-button[data-selected]:not([data-selected="_all"])',
1662 );
1663 if (otherBtns.length > 0) {
1664 otherBtns.attr("data-is-active", "false");
1665 otherBtns.removeClass("ultp-filter-button-active");
1666 }
1667 }
1668
1669 // This buttons are exclusive
1670 else if (
1671 ["adv_sort", "order", "order_by"].includes(fBtnType) &&
1672 !isActive
1673 ) {
1674 const otherBtns = that.find(
1675 `.ultp-filter-button[data-type="${fBtnType}"]`,
1676 );
1677 if (otherBtns.length > 0) {
1678 otherBtns.attr("data-is-active", "false");
1679 otherBtns.removeClass("ultp-filter-button-active");
1680 }
1681 }
1682
1683 // Click a button should disable all button
1684 else {
1685 const allBtn = that.find('.ultp-filter-button[data-selected="_all"]');
1686 if (allBtn.length > 0) {
1687 allBtn.attr("data-is-active", "false");
1688 allBtn.removeClass("ultp-filter-button-active");
1689 }
1690 }
1691
1692 if (isActive) {
1693 $(currFBtn).attr("data-is-active", "false");
1694 $(currFBtn).removeClass("ultp-filter-button-active");
1695 } else {
1696 $(currFBtn).attr("data-is-active", "true");
1697 $(currFBtn).addClass("ultp-filter-button-active");
1698 if (
1699 ["author"].includes(fBtnType) ||
1700 !($(this).parent().attr("data-multiselect") == "true")
1701 ) {
1702 $(currFBtn)
1703 .siblings()
1704 .attr("data-is-active", "false")
1705 .removeClass("ultp-filter-button-active");
1706 }
1707 }
1708
1709 fetchPostsWithFilter();
1710 });
1711 });
1712
1713 clearBtn.on("click", function () {
1714 resetFilters();
1715 fetchPostsWithFilter();
1716 });
1717
1718 let searchTimeout;
1719
1720 function performSearch(isDebounce) {
1721 clearTimeout(searchTimeout);
1722 searchTimeout = isDebounce
1723 ? setTimeout(fetchPostsWithFilter, 500)
1724 : fetchPostsWithFilter();
1725 }
1726
1727 parent
1728 .find(".ultp-filter-search input")
1729 .off("input")
1730 .on("input", function () {
1731 performSearch(true);
1732 });
1733
1734 parent.find(".ultp-filter-search input").on("keydown", function (e) {
1735 if (e.key === "Enter") {
1736 performSearch(false);
1737 }
1738 });
1739
1740 parent.find(".ultp-filter-search-icon").on("click", function () {
1741 performSearch(false);
1742 });
1743 });
1744
1745 /**************************************
1746 Dark Light Block
1747 **************************************/
1748
1749 // dark light logo vars
1750 const customSrc = ultp_data_frontend?.dark_logo;
1751 const site_logo = $(".ultp-dark-logo.wp-block-site-logo")
1752 .find("img")
1753 .attr("src");
1754 const site_srcset =
1755 $(".ultp-dark-logo.wp-block-site-logo").find("img").attr("srcset") || "";
1756
1757 /************** handle dark light color swap on click **************/
1758 $(document).on(
1759 "click",
1760 ".ultp-dark-light-block-wrapper-content.ultp-frontend .ultp-dl-con",
1761 function (e) {
1762 e.preventDefault();
1763 const parents = $(this).closest(".ultp-dark-light-block-wrapper-content");
1764 const lightMode = $(this).hasClass("ultp-light-con");
1765
1766 const currentParents = $(this).closest(".ultp-dl-after-before-con");
1767 const opponent = parents.find(
1768 `.ultp-${lightMode ? "dark" : "light"}-con`,
1769 );
1770 const opponentParents = opponent.closest(".ultp-dl-after-before-con");
1771
1772 const iconlay = currentParents.data("iconlay");
1773 const iconsize = currentParents.data("iconsize");
1774 const iconrev = currentParents.data("iconrev");
1775
1776 let delay = 0;
1777 if (["layout5", "layout6", "layout7"].includes(iconlay)) {
1778 delay = iconlay == "layout7" ? 500 : 400;
1779 const extraSize =
1780 iconlay == "layout7"
1781 ? $(this).find(".ultp-dl-text").width()
1782 : iconsize / 2;
1783 if (lightMode) {
1784 $(this)
1785 .find(".ultp-dl-svg-con")
1786 .css({
1787 transform: `translateX(calc(${100 * (iconrev ? -1 : 1)}% ${
1788 iconrev ? "-" : "+"
1789 } ${extraSize}px))`,
1790 transition: `transform ${delay / 1000}s ease`,
1791 });
1792 if (iconlay == "layout6") {
1793 $(this)
1794 .find(".ultp-dl-text")
1795 .css({
1796 transform: `translateX(calc(${100 * (iconrev ? 1 : -1)}% ${
1797 iconrev ? "+" : "-"
1798 } ${extraSize}px))`,
1799 transition: `transform ${delay / 1000}s ease`,
1800 });
1801 } else if (iconlay == "layout7") {
1802 $(this)
1803 .find(".ultp-dl-text")
1804 .css({
1805 transform: `translateX(calc(${
1806 (iconrev ? 1 : -1) * iconsize
1807 }px))`,
1808 transition: `transform ${delay / 1000}s ease`,
1809 });
1810 }
1811 } else {
1812 $(this)
1813 .find(".ultp-dl-svg-con")
1814 .css({
1815 transform: `translateX(calc(${100 * (iconrev ? 1 : -1)}% ${
1816 iconrev ? "+" : "-"
1817 } ${extraSize}px))`,
1818 transition: `transform ${delay / 1000}s ease`,
1819 });
1820 if (iconlay == "layout6") {
1821 $(this)
1822 .find(".ultp-dl-text")
1823 .css({
1824 transform: `translateX(calc(${100 * (iconrev ? -1 : 1)}% ${
1825 iconrev ? "-" : "+"
1826 } ${extraSize}px))`,
1827 transition: `transform ${delay / 1000}s ease`,
1828 });
1829 } else if (iconlay == "layout7") {
1830 $(this)
1831 .find(".ultp-dl-text")
1832 .css({
1833 transform: `translateX(calc(${
1834 (iconrev ? -1 : 1) * iconsize
1835 }px))`,
1836 transition: `transform ${delay / 1000}s ease`,
1837 });
1838 }
1839 }
1840 }
1841 setCookie("ultplocalDLMode", lightMode ? "ultpdark" : "ultplight", 60);
1842 setTimeout(() => {
1843 currentParents.addClass("inactive");
1844 opponentParents.removeClass("inactive");
1845
1846 // handle dark light image block
1847 if (lightMode) {
1848 $(".wp-block-ultimate-post-image .ultp-light-image-block").addClass(
1849 "inactive",
1850 );
1851 $(".wp-block-ultimate-post-image .ultp-dark-image-block").removeClass(
1852 "inactive",
1853 );
1854 } else if (!lightMode) {
1855 $(".wp-block-ultimate-post-image .ultp-dark-image-block").addClass(
1856 "inactive",
1857 );
1858 $(
1859 ".wp-block-ultimate-post-image .ultp-light-image-block",
1860 ).removeClass("inactive");
1861 }
1862
1863 // handle dark light logo
1864 $(".ultp-dark-logo.wp-block-site-logo")
1865 .find("img")
1866 .attr("src", lightMode ? customSrc : site_logo)
1867 .attr("srcset", lightMode ? customSrc : site_srcset);
1868 $(".ultp-dark-logo.wp-block-site-logo img").css({ content: "initial" });
1869
1870 // handle more than one block
1871 $(
1872 `.ultp-dark-light-block-wrapper-content .ultp-${
1873 lightMode ? "dark" : "light"
1874 }-con`,
1875 ).each(function () {
1876 $(this).closest(".ultp-dl-after-before-con").removeClass("inactive");
1877 });
1878 $(
1879 `.ultp-dark-light-block-wrapper-content .ultp-${
1880 lightMode ? "light" : "dark"
1881 }-con`,
1882 ).each(function () {
1883 $(this).closest(".ultp-dl-after-before-con").addClass("inactive");
1884 });
1885
1886 // remove transition
1887 $(this).find(".ultp-dl-svg-con").removeAttr("style");
1888 $(this).find(".ultp-dl-text").removeAttr("style");
1889
1890 handleDarkLight();
1891 }, delay);
1892 },
1893 );
1894
1895 /************** set cookie **************/
1896 function setCookie(cookieName, cookieValue, expires) {
1897 const date = new Date();
1898 date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);
1899 let expiresAt = "expires=" + date.toUTCString();
1900 document.cookie = cookieName + "=" + cookieValue + ";" + expiresAt + ";";
1901 }
1902
1903 /************** get registered cookie **************/
1904 function getCookie(cookieName) {
1905 let c_name = cookieName + "=";
1906 let c_array = document.cookie.split(";");
1907 for (let i = 0; i < c_array.length; i++) {
1908 let item = c_array[i];
1909 while (item.charAt(0) == " ") {
1910 item = item.substring(1);
1911 }
1912 if (item.indexOf(c_name) == 0) {
1913 return item.substring(c_name.length, item.length);
1914 }
1915 }
1916 return "";
1917 }
1918
1919 /************** handle dark light color swap **************/
1920 function handleDarkLight() {
1921 if (
1922 $("#ultp-preset-colors-style-inline-css") &&
1923 $("#ultp-preset-colors-style-inline-css")[0]
1924 ) {
1925 const root = $("#ultp-preset-colors-style-inline-css")[0].sheet;
1926 const base1 = root.cssRules[0].style.getPropertyValue(
1927 "--postx_preset_Base_1_color",
1928 );
1929 const base2 = root.cssRules[0].style.getPropertyValue(
1930 "--postx_preset_Base_2_color",
1931 );
1932 const base3 = root.cssRules[0].style.getPropertyValue(
1933 "--postx_preset_Base_3_color",
1934 );
1935
1936 const contrast1 = root.cssRules[0].style.getPropertyValue(
1937 "--postx_preset_Contrast_1_color",
1938 );
1939 const contrast2 = root.cssRules[0].style.getPropertyValue(
1940 "--postx_preset_Contrast_2_color",
1941 );
1942 const contrast3 = root.cssRules[0].style.getPropertyValue(
1943 "--postx_preset_Contrast_3_color",
1944 );
1945
1946 root.cssRules[0].style.setProperty(
1947 "--postx_preset_Base_1_color",
1948 contrast1,
1949 );
1950 root.cssRules[0].style.setProperty(
1951 "--postx_preset_Base_2_color",
1952 contrast2,
1953 );
1954 root.cssRules[0].style.setProperty(
1955 "--postx_preset_Base_3_color",
1956 contrast3,
1957 );
1958
1959 root.cssRules[0].style.setProperty(
1960 "--postx_preset_Contrast_1_color",
1961 base1,
1962 );
1963 root.cssRules[0].style.setProperty(
1964 "--postx_preset_Contrast_2_color",
1965 base2,
1966 );
1967 root.cssRules[0].style.setProperty(
1968 "--postx_preset_Contrast_3_color",
1969 base3,
1970 );
1971 }
1972 }
1973
1974 function handleDailyMotion() {
1975 $(
1976 ".ultp-video-modal .ultp-video-modal__content .ultp-video-wrapper > iframe",
1977 ).each(function () {
1978 const that = $(this);
1979 const videoSrc = that.attr("src");
1980 if (
1981 videoSrc &&
1982 videoSrc.includes("dailymotion.com/player") &&
1983 videoSrc[videoSrc.length - 1] == "&"
1984 ) {
1985 that.attr(
1986 "src",
1987 videoSrc.slice(0, videoSrc.length - 1) + "?autoplay=0",
1988 );
1989 }
1990 });
1991 }
1992 if (isFront) {
1993 handleDailyMotion();
1994 }
1995
1996 // /*************************************
1997 // Tab Block
1998 // *************************************/
1999 // $('.ultp-tabs-content[data-show="click"] .ultp-tab-item-label').on(
2000 // "click",
2001 // function (e) {
2002 // handleTabItem($(this));
2003 // }
2004 // );
2005 // $('.ultp-tabs-content[data-show="hover"] .ultp-tab-item-label').hover(
2006 // function (e) {
2007 // handleTabItem($(this));
2008 // }
2009 // );
2010 // function handleTabItem(that) {
2011 // if (that.closest("body.block-editor-page").length) {
2012 // return;
2013 // }
2014 // const parent = that.closest(".ultp-tabs-content");
2015 // parent.find(".ultp-tab-item-label").removeClass("pt-active");
2016 // that.addClass("pt-active");
2017
2018 // const tabId = that.data("tabid");
2019 // parent
2020 // .find("> .ultp-tabs-content-warp > .wp-block-ultimate-post-tab-item")
2021 // .removeClass("pt-active");
2022 // parent
2023 // .find(
2024 // `> .ultp-tabs-content-warp > .wp-block-ultimate-post-tab-item.${tabId}`
2025 // )
2026 // .addClass("pt-active");
2027 // }
2028 if ($(".ultp-iscroll-active").length > 0) {
2029 $(".ultp-iscroll-active").each(function () {
2030 $(this).UltpInfiniteScroll(
2031 $(this),
2032 setSession, // set Unique Post Id
2033 getUltpNonce, // Get Nonce
2034 paginationAjaxCall, // Pagination API Call Function
2035 );
2036 });
2037 }
2038 })(jQuery);
2039