PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.23
Post Grid Gutenberg Blocks – PostX v5.0.23
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.23, at assets/js/ultp.js

1,943 lines 53.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 $(document).on(
797 "click",
798 ".ultp-pagination-ajax-action li",
799 async function (e) {
800 e.preventDefault();
801 const ultpNonce = await getUltpNonce();
802
803 let that = $(this),
804 parents = that.closest(".ultp-pagination-ajax-action"),
805 wrap = that.closest(".ultp-block-wrapper");
806
807 const blockid = parents.attr("data-blockid");
808
809 // Pagination block integration
810 if (wrap.length < 1) {
811 const pagiFor = parents.data("for");
812 if (pagiFor) {
813 wrap = $("." + pagiFor + " .ultp-block-wrapper");
814 }
815 }
816
817 if (parents.is(".ultp-disable-editor-click")) {
818 return;
819 }
820 let pageNum = 1;
821 let pages = parents.attr("data-pages");
822
823 if (that.attr("data-current")) {
824 pageNum = Number(that.attr("data-current"));
825 parents
826 .attr("data-paged", pageNum)
827 .find("li")
828 .removeClass("pagination-active");
829 serial(parents, pageNum, pages);
830 showHide(parents, pageNum, pages);
831 } else {
832 if (that.hasClass("ultp-prev-page-numbers")) {
833 pageNum = Number(parents.attr("data-paged")) - 1;
834 parents
835 .attr("data-paged", pageNum)
836 .find("li")
837 .removeClass("pagination-active");
838 //parents.find('li[data-current="'+pageNum+'"]').addClass('pagination-active')
839 serial(parents, pageNum, pages);
840 showHide(parents, pageNum, pages);
841 } else if (that.hasClass("ultp-next-page-numbers")) {
842 pageNum = Number(parents.attr("data-paged")) + 1;
843 parents
844 .attr("data-paged", pageNum)
845 .find("li")
846 .removeClass("pagination-active");
847 //parents.find('li[data-current="'+pageNum+'"]').addClass('pagination-active')
848 serial(parents, pageNum, pages);
849 showHide(parents, pageNum, pages);
850 }
851 }
852
853 let post_ID =
854 parents.parents(".ultp-shortcode").length != 0 &&
855 parents.data("selfpostid") == "no"
856 ? parents.parents(".ultp-shortcode").data("postid")
857 : parents.data("postid");
858
859 if (that.closest(".ultp-builder-content").length > 0) {
860 post_ID = that.closest(".ultp-builder-content").data("postid");
861 }
862 let widgetBlockId = "";
863 let widgetBlock = $(this).parents(".widget_block:first");
864 if (widgetBlock.length > 0) {
865 let widget_items = widgetBlock.attr("id").split("-");
866 widgetBlockId = widget_items[widget_items.length - 1];
867 }
868
869 const ultpUniqueIds = sessionStorage.getItem("ultp_uniqueIds");
870 const ultpCurrentUniquePosts = JSON.stringify(
871 wrap.find(".ultp-current-unique-posts").data("current-unique-posts"),
872 );
873
874 // Adv Filter Integration
875 const filterValue = parents.data("filter-value") || "";
876 const advFilterData = {};
877
878 if (Array.isArray(filterValue) && filterValue.length > 0) {
879 advFilterData.filterShow = true;
880 advFilterData.checkFilter = true;
881 advFilterData.isAdv = true;
882 advFilterData.author = parents.data("filter-author") || "";
883 advFilterData.order = parents.data("filter-order") || "";
884 advFilterData.orderby = parents.data("filter-orderby") || "";
885 advFilterData.adv_sort = parents.data("filter-adv-sort") || "";
886 }
887
888 if (pageNum) {
889 if (blockid) {
890 setCurrPage(blockid, pageNum, getCurrPage(blockid));
891 }
892
893 $.ajax({
894 url: ultp_data_frontend.ajax,
895 type: "POST",
896 data: {
897 exclude: parents.data("expost"),
898 action: "ultp_pagination",
899 paged: pageNum,
900 blockId: parents.data("blockid"),
901 postId: post_ID,
902 blockName: parents.data("blockname"),
903 builder: parents.data("builder"),
904 widgetBlockId: widgetBlockId,
905 ultpUniqueIds: ultpUniqueIds || [],
906 ultpCurrentUniquePosts: ultpCurrentUniquePosts || [],
907
908 filterType: parents.data("filter-type") || "",
909 filterValue: filterValue,
910
911 ...advFilterData,
912
913 wpnonce: ultpNonce,
914 },
915 beforeSend: function () {
916 wrap.addClass("ultp-loading-active");
917 },
918 success: function (data) {
919 wrap.find(".ultp-block-items-wrap").html(data);
920 setSession(
921 "ultp_uniqueIds",
922 JSON.stringify(
923 wrap.find(".ultp-current-unique-posts").data("ultp-unique-ids"),
924 ),
925 );
926 if ($(window).scrollTop() > wrap.offset().top) {
927 $([document.documentElement, document.body]).animate(
928 {
929 scrollTop: wrap.offset().top - 80,
930 },
931 100,
932 );
933 }
934 },
935 complete: function () {
936 wrap.removeClass("ultp-loading-active");
937 handleDailyMotion();
938 },
939 error: function (xhr) {
940 console.log(
941 "Error occured.please try again" +
942 xhr.statusText +
943 xhr.responseText,
944 );
945 wrap.removeClass("ultp-loading-active");
946 },
947 });
948 }
949 },
950 );
951
952 // *************************************
953 // SlideShow
954 // *************************************
955
956 // Slideshow Display For Elementor via Shortcode
957 $(window).on("elementor/frontend/init", () => {
958 setTimeout(() => {
959 if ($(".elementor-editor-active").length > 0) {
960 slideshowDisplay();
961 }
962 }, 2000);
963 });
964
965 // Bricks Builder Backend Slider Support
966 // Bricks Builder Backend Slider Support
967 if (
968 $(".bricks-builder-iframe").length > 0 &&
969 $(window.parent.document).find(".bricks-panel-controls").length > 0
970 ) {
971 setTimeout(() => {
972 slideshowDisplay();
973 }, 2500);
974 }
975
976 function slideshowDisplay() {
977 $(
978 ".wp-block-ultimate-post-post-slider-1, .wp-block-ultimate-post-post-slider-2",
979 ).each(function () {
980 const sectionId = "#" + $(this).attr("id");
981 let selector = $(sectionId).find(".ultp-block-items-wrap");
982 if ($(this).parent(".ultp-shortcode")) {
983 selector = $(this).find(".ultp-block-items-wrap");
984 }
985 let settings = {
986 arrows: true,
987 dots: selector.data("dots") ? true : false,
988 infinite: true,
989 speed: 500,
990 slidesToShow: selector.data("slidelg") || 1,
991 slidesToScroll: 1,
992 autoplay: selector.data("autoplay") ? true : false,
993 autoplaySpeed: selector.data("slidespeed") || 3000,
994 cssEase: "linear",
995 prevArrow: selector.parent().find(".ultp-slick-prev").html(),
996 nextArrow: selector.parent().find(".ultp-slick-next").html(),
997 };
998
999 let layTemp =
1000 selector.data("layout") == "slide2" ||
1001 selector.data("layout") == "slide3" ||
1002 selector.data("layout") == "slide5" ||
1003 selector.data("layout") == "slide6" ||
1004 selector.data("layout") == "slide8";
1005
1006 if (!selector.data("layout")) {
1007 // Slider 1
1008 if (selector.data("slidelg") < 2) {
1009 settings.fade = selector.data("fade") ? true : false;
1010 } else {
1011 settings.responsive = [
1012 {
1013 breakpoint: 1024,
1014 settings: {
1015 slidesToShow: selector.data("slidesm") || 1,
1016 slidesToScroll: 1,
1017 },
1018 },
1019 {
1020 breakpoint: 600,
1021 settings: {
1022 slidesToShow: selector.data("slidexs") || 1,
1023 slidesToScroll: 1,
1024 },
1025 },
1026 ];
1027 }
1028 } else {
1029 // Slider 2
1030 if (selector.data("fade") && layTemp) {
1031 settings.fade = selector.data("fade") ? true : false;
1032 } else if (!selector.data("fade") && layTemp) {
1033 ((settings.slidesToShow = selector.data("slidelg") || 1),
1034 (settings.responsive = [
1035 {
1036 breakpoint: 991,
1037 settings: {
1038 slidesToShow: selector.data("slidesm") || 1,
1039 slidesToScroll: 1,
1040 },
1041 },
1042 {
1043 breakpoint: 767,
1044 settings: {
1045 slidesToShow: selector.data("slidexs") || 1,
1046 slidesToScroll: 1,
1047 },
1048 },
1049 ]));
1050 } else {
1051 ((settings.slidesToShow = selector.data("slidelg") || 1),
1052 (settings.centerMode = true));
1053 settings.centerPadding = `${selector.data("paddlg")}px` || 100;
1054 settings.responsive = [
1055 {
1056 breakpoint: 991,
1057 settings: {
1058 slidesToShow: selector.data("slidesm") || 1,
1059 slidesToScroll: 1,
1060 centerPadding: `${selector.data("paddsm")}px` || 50,
1061 },
1062 },
1063 {
1064 breakpoint: 767,
1065 settings: {
1066 slidesToShow: selector.data("slidexs") || 1,
1067 slidesToScroll: 1,
1068 centerPadding: `${selector.data("paddxs")}px` || 50,
1069 },
1070 },
1071 ];
1072 }
1073 }
1074 selector.not(".slick-initialized").slick(settings);
1075 });
1076 }
1077 slideshowDisplay();
1078
1079 // *************************************
1080 // Accessibility for Loadmore Added
1081 // *************************************
1082 $('span[role="button"].ultp-loadmore-action').on("keydown", function (e) {
1083 const keyD = e.key !== undefined ? e.key : e.keyCode;
1084 if (
1085 keyD === "Enter" ||
1086 keyD === 13 ||
1087 ["Spacebar", " "].indexOf(keyD) >= 0 ||
1088 keyD === 32
1089 ) {
1090 e.preventDefault();
1091 this.click();
1092 }
1093 });
1094 // *************************************
1095 // Video Scroll
1096 // *************************************
1097 let isSticky = true;
1098 $(window).on("scroll", function () {
1099 let windowHeight = $(this).scrollTop();
1100 $(".wp-block-ultimate-post-post-image").each(function () {
1101 let contentSelector = $(this).find(
1102 ".ultp-builder-video video , .ultp-builder-video iframe",
1103 );
1104 if ($(this).find(".ultp-video-block").hasClass("ultp-sticky-video")) {
1105 // block height and position
1106 let blockContent = $(this).find(".ultp-image-wrapper");
1107 let blockPosition = blockContent.offset();
1108 // Video Html height and position
1109 let videoContent = contentSelector.height();
1110 let videoPosition = contentSelector.offset();
1111 // Exclude Adminbar height
1112 let windowTotalHeight = windowHeight + ($("#wpadminbar").height() || 0);
1113 let totalHeight = videoPosition.top + videoContent;
1114 // Scrolling Top to bottom
1115 if (windowTotalHeight > videoPosition.top) {
1116 if (windowTotalHeight > totalHeight && isSticky) {
1117 $(this)
1118 .find(".ultp-image-wrapper")
1119 .css("height", blockContent.height());
1120 $(this).find(".ultp-sticky-video").addClass("ultp-sticky-active");
1121 }
1122 }
1123 // Scrolling bottom to top
1124 if (windowTotalHeight < blockContent.height() + blockPosition.top) {
1125 $(this).find(".ultp-sticky-video").removeClass("ultp-sticky-active");
1126 $(this).find(".ultp-image-wrapper").css("height", "auto");
1127 }
1128 // Close Button
1129 $(".ultp-sticky-close").on("click", function () {
1130 $(this).find(".ultp-image-wrapper").css("height", "auto");
1131 $(".ultp-sticky-video").removeClass("ultp-sticky-active");
1132 isSticky = false;
1133 });
1134 }
1135 });
1136 });
1137
1138 // *************************************
1139 // Advanced Filter
1140 // *************************************
1141 function getTax(name) {
1142 switch (name) {
1143 case "categories":
1144 return "category";
1145 case "tag":
1146 case "tags":
1147 return "post_tag";
1148 case "authors":
1149 return "author";
1150 case "order_by":
1151 return "orderby";
1152 default:
1153 return name;
1154 }
1155 }
1156
1157 function getFormattedSelectedFilter(type, name) {
1158 const fType = type
1159 .replace("_", " ")
1160 .replace(/\b\w/g, (l) => l.toUpperCase());
1161 return `${fType}: ${name}`;
1162 }
1163
1164 function applyFilter(parent, blockId, blockName, postId, grids, builder) {
1165 const selectedFilters = [];
1166 const filterData = {};
1167 const pagis = parent.data("pagi");
1168
1169 parent.find(".ultp-filter-select").each(function () {
1170 const type = $(this).attr("data-type");
1171 const selected = $(this).attr("data-selected");
1172 const cTax = $(this)
1173 .find('.ultp-filter-select__dropdown-inner[data-id="' + selected + '"]')
1174 .data("tax");
1175 if (getTax(type) === "author") {
1176 if (selected !== "_all") {
1177 filterData.author = [{ value: selected }];
1178 }
1179 return;
1180 }
1181 if (getTax(type) === "order") {
1182 filterData.order = selected;
1183 return;
1184 }
1185 if (getTax(type) === "orderby") {
1186 filterData.orderby = selected;
1187 return;
1188 }
1189 if (getTax(type) === "adv_sort") {
1190 filterData.adv_sort = selected;
1191 return;
1192 }
1193 if (getTax(type) === "custom_tax") {
1194 if (cTax) {
1195 selectedFilters.push({
1196 value: cTax + "###" + selected,
1197 });
1198 }
1199 return;
1200 }
1201 selectedFilters.push({
1202 value: getTax(type) + "###" + selected,
1203 });
1204 });
1205
1206 parent.find('.ultp-filter-button[data-is-active="true"]').each(function () {
1207 const type = $(this).attr("data-type");
1208 const selected = $(this).attr("data-selected");
1209 const cTax = $(this).attr("data-tax");
1210
1211 if (getTax(type) === "author") {
1212 if (selected !== "_all") {
1213 filterData.author = [{ value: selected }];
1214 }
1215 return;
1216 }
1217
1218 if (getTax(type) === "order") {
1219 filterData.order = selected;
1220 return;
1221 }
1222
1223 if (getTax(type) === "orderby") {
1224 filterData.orderby = selected;
1225 return;
1226 }
1227
1228 if (getTax(type) === "adv_sort") {
1229 filterData.adv_sort = selected;
1230 return;
1231 }
1232
1233 if (getTax(type) === "custom_tax") {
1234 if (cTax) {
1235 selectedFilters.push({
1236 value: cTax + "###" + selected,
1237 });
1238 }
1239 return;
1240 }
1241 selectedFilters.push({
1242 value: getTax(type) + "###" + selected,
1243 });
1244 });
1245
1246 filterData.taxonomy = selectedFilters;
1247
1248 const searchVal = parent.find(".ultp-filter-search input");
1249 if (searchVal.length > 0) {
1250 filterData.search = searchVal.val();
1251 }
1252
1253 const ultpUniqueIds = sessionStorage.getItem("ultp_uniqueIds");
1254 const ultpCurrentUniquePosts = JSON.stringify(
1255 parent.find(".ultp-current-unique-posts").data("current-unique-posts"),
1256 );
1257
1258 let widgetBlockId = "";
1259 let widgetBlock = parent.parents(".widget_block:first");
1260 if (widgetBlock.length > 0) {
1261 let widget_items = widgetBlock.attr("id").split("-");
1262 widgetBlockId = widget_items[widget_items.length - 1];
1263 }
1264
1265 $(grids).each(function () {
1266 const grid = $(this);
1267
1268 $.ajax({
1269 url: ultp_data_frontend.ajax,
1270 type: "POST",
1271 data: {
1272 action: "ultp_adv_filter",
1273
1274 ...filterData,
1275 builder_id: builder,
1276 blockId: blockId,
1277 blockName: blockName,
1278 postId: postId,
1279 ultpUniqueIds: ultpUniqueIds || [],
1280 ultpCurrentUniquePosts: ultpCurrentUniquePosts || [],
1281 widgetBlockId: widgetBlockId,
1282 wpnonce: ultp_data_frontend.security,
1283 },
1284 beforeSend: function () {
1285 grid.addClass("ultp-loading-active");
1286 },
1287 success: function (response) {
1288 grid
1289 .closest(".wp-block-ultimate-post-post-grid-parent")
1290 ?.find(".ultp-not-found-message")
1291 ?.remove();
1292 if (
1293 response?.data?.filteredData?.blocks === "" &&
1294 response?.data?.filteredData?.notFound
1295 ) {
1296 grid
1297 .closest(".wp-block-ultimate-post-post-grid-parent")
1298 .append(
1299 '<div class="ultp-not-found-message" role="alert">' +
1300 response?.data?.filteredData?.notFound +
1301 "</div>",
1302 );
1303 }
1304 grid
1305 .find(".ultp-block-items-wrap")
1306 .html(response?.data?.filteredData?.blocks);
1307 if (
1308 response?.data?.filteredData?.paginationType == "loadMore" &&
1309 response?.data?.filteredData?.paginationShow
1310 ) {
1311 // grid.find(".ultp-block-items-wrap")
1312 // .append('<span class="ultp-loadmore-insert-before"></span>');
1313 grid
1314 .find(".ultp-loadmore")
1315 .replaceWith(response?.data?.filteredData?.pagination);
1316 } else if (
1317 response?.data?.filteredData?.paginationType == "navigation"
1318 ) {
1319 grid
1320 .find(".ultp-next-prev-wrap")
1321 .replaceWith(response?.data?.filteredData?.pagination);
1322 } else if (
1323 response?.data?.filteredData?.paginationType == "pagination"
1324 ) {
1325 grid
1326 .find(".ultp-pagination-wrap")
1327 .replaceWith(response?.data?.filteredData?.pagination);
1328 }
1329
1330 // Pagination Block Integration
1331 if (response?.data?.filteredData?.pagination) {
1332 pagis?.map((pagiClass) => {
1333 let pagi = [];
1334
1335 if (response?.data?.filteredData?.paginationType === "loadMore") {
1336 pagi = $(".ultp-loadmore." + pagiClass);
1337 if (pagi.length > 0) {
1338 // grid.find(".ultp-block-items-wrap")
1339 // .append('<span class="ultp-loadmore-insert-before"></span>');
1340 }
1341 } else {
1342 pagi = $("." + pagiClass + "[data-for]");
1343 }
1344
1345 if (pagi.length > 0) {
1346 const newPagi = $(response.data.filteredData.pagination);
1347 pagi
1348 .attr("class")
1349 .split(" ")
1350 .forEach((cl) => newPagi.addClass(cl));
1351 pagi.replaceWith(newPagi);
1352 }
1353 });
1354 }
1355 },
1356 complete: function () {
1357 grid.removeClass("ultp-loading-active");
1358 setSession(
1359 "ultp_uniqueIds",
1360 JSON.stringify(
1361 parent.find(".ultp-current-unique-posts").data("ultp-unique-ids"),
1362 ),
1363 );
1364 },
1365 error: function (xhr) {
1366 console.log(
1367 "Error occured.please try again" +
1368 xhr.statusText +
1369 xhr.responseText,
1370 );
1371 grid.removeClass("ultp-loading-active");
1372 },
1373 });
1374 });
1375 }
1376
1377 $(".ultp-filter-block").each(function () {
1378 const that = $(this);
1379 const parent = $(this).parents(".ultp-post-grid-parent");
1380 const grids = parent.find(".ultp-block-wrapper");
1381 const gridData = JSON.parse(parent.attr("data-grids"));
1382 const selectedFilterTemp = $(this).find(".ultp-filter-clear-template");
1383 const clearBtn = $(this).find(".ultp-filter-clear-button");
1384 const firstElClass = "ultp-block-" + clearBtn.data("blockid") + "-first";
1385 let postId = "";
1386 let builder = "";
1387
1388 function resetFilters() {
1389 // Resetting select fields
1390 that.find(".ultp-filter-select").each(function () {
1391 const defVal = $(this).find(".ultp-filter-select-options li").first();
1392 $(this).attr("data-selected", defVal.attr("data-id"));
1393 $(this).find(".ultp-filter-select-field-selected").text(defVal.text());
1394 });
1395
1396 // Resetting clear button
1397 const selectedFilter = that.find(".ultp-filter-clear-selected-filter");
1398 if (selectedFilter.hasClass(firstElClass)) {
1399 clearBtn.addClass(firstElClass);
1400 }
1401 selectedFilter.remove();
1402
1403 // Resetting search input
1404 that.find(".ultp-filter-search input").val("");
1405
1406 // Resetting filter buttons
1407 that.find('.ultp-filter-button[data-is-active="true"]').each(function () {
1408 $(this).removeClass("ultp-filter-button-active");
1409 $(this).attr("data-is-active", "false");
1410 });
1411 }
1412
1413 function fetchPostsWithFilter() {
1414 gridData.forEach((data) => {
1415 applyFilter(
1416 parent,
1417 data["blockId"],
1418 data["name"],
1419 postId,
1420 grids,
1421 builder,
1422 );
1423 });
1424 }
1425
1426 that.find(".ultp-filter-select").each(function () {
1427 const dropdown = $(this).find(".ultp-filter-select-options");
1428 const selected = $(this).find(".ultp-filter-select-field-selected");
1429 const icon = $(this).find(".ultp-filter-select-field-icon");
1430 const filter = $(this);
1431 const type = $(this).attr("data-type");
1432 const input = $(this).find(".ultp-filter-select-search");
1433 postId = $(this).attr("data-current-postid");
1434 builder = $(this).attr("data-builder");
1435 function showDropdown(show) {
1436 if (show) {
1437 $(".ultp-filter-select .ultp-filter-select-options").css(
1438 "display",
1439 "none",
1440 );
1441 $(".ultp-filter-select .ultp-filter-select-field-icon").removeClass(
1442 "ultp-dropdown-icon-rotate",
1443 );
1444 $(".ultp-filter-select").attr("aria-expanded", false);
1445
1446 dropdown.css("display", "block");
1447 icon.addClass("ultp-dropdown-icon-rotate");
1448 } else {
1449 dropdown.css("display", "none");
1450 icon.removeClass("ultp-dropdown-icon-rotate");
1451 }
1452
1453 filter.attr("aria-expanded", show);
1454 }
1455
1456 const defValue = dropdown.find("li").first();
1457
1458 function resetFilter() {
1459 selected.text(defValue.text());
1460 filter.attr("data-selected", defValue.attr("data-id"));
1461 }
1462
1463 // Toggle on click
1464 $(this).on("click", function (e) {
1465 e.stopPropagation();
1466 showDropdown(dropdown.css("display") === "none");
1467 });
1468
1469 $(dropdown)
1470 .find("li")
1471 .each(function () {
1472 const value = $(this).attr("data-id");
1473 const filterId = $(this).attr("data-blockId");
1474 const text = $(this).text();
1475 $(this).on("click", function () {
1476 selected.text(text);
1477 filter.attr("data-selected", value);
1478
1479 // Selected filters
1480 if (value === "_all") {
1481 that.find(`.ultp-filter-clear[data-type="${type}"]`).remove();
1482 } else if (clearBtn.length > 0) {
1483 let isNew = false;
1484
1485 let copy = that.find(`.ultp-filter-clear[data-type="${type}"]`);
1486
1487 if (copy.length < 1) {
1488 isNew = true;
1489 copy = selectedFilterTemp.clone();
1490 }
1491
1492 copy.removeClass("ultp-filter-clear-template");
1493 copy.addClass("ultp-filter-clear-selected-filter");
1494 copy
1495 .find(".ultp-selected-filter-text")
1496 .text(
1497 getFormattedSelectedFilter(
1498 filter.attr("data-filter-label"),
1499 text,
1500 ),
1501 );
1502 // Alignment
1503 if (clearBtn.hasClass(firstElClass)) {
1504 clearBtn.removeClass(firstElClass);
1505 copy.addClass(firstElClass);
1506 }
1507 copy.find(".ultp-selected-filter-icon").on("click", function () {
1508 resetFilter();
1509 if (copy.hasClass(firstElClass)) {
1510 if (
1511 copy.next().hasClass("ultp-filter-clear-selected-filter")
1512 ) {
1513 copy.next().addClass(firstElClass);
1514 } else {
1515 clearBtn.addClass(firstElClass);
1516 }
1517 }
1518 copy.remove();
1519 fetchPostsWithFilter();
1520 });
1521 copy.attr("data-id", value);
1522 copy.attr("data-type", type);
1523 copy.attr("data-for", filterId);
1524 copy.css({
1525 display: "block",
1526 });
1527 isNew && copy.insertBefore(clearBtn);
1528 }
1529 fetchPostsWithFilter();
1530 showDropdown(true);
1531 });
1532 });
1533
1534 input.on("click", function (e) {
1535 e.preventDefault();
1536 e.stopPropagation();
1537 });
1538
1539 input.on("input", function (e) {
1540 const value = String(e.target.value).toLowerCase();
1541
1542 if (value.length > 0) {
1543 dropdown.find("li").each(function () {
1544 const currValue = $(this).text();
1545 $(this).css(
1546 "display",
1547 currValue.toLowerCase().includes(value) ? "list-item" : "none",
1548 );
1549 });
1550 } else {
1551 dropdown.find("li").each(function () {
1552 $(this).css("display", "list-item");
1553 });
1554 }
1555 });
1556
1557 $(document).on("click", function (e) {
1558 if (!filter.is(e.target) && !filter.has(e.target).length) {
1559 showDropdown(false);
1560 }
1561 });
1562 });
1563
1564 that.find(".ultp-filter-button").each(function () {
1565 const currFBtn = this;
1566 const fBtnType = $(this).data("type");
1567 postId = $(this).attr("data-current-postid");
1568 $(this).on("click", function () {
1569 const isActive = $(currFBtn).attr("data-is-active") === "true";
1570 const value = $(this).data("selected");
1571
1572 // Clicking all button will disable other
1573 if (value === "_all") {
1574 const otherBtns = that.find(
1575 '.ultp-filter-button[data-selected]:not([data-selected="_all"])',
1576 );
1577 if (otherBtns.length > 0) {
1578 otherBtns.attr("data-is-active", "false");
1579 otherBtns.removeClass("ultp-filter-button-active");
1580 }
1581 }
1582
1583 // This buttons are exclusive
1584 else if (
1585 ["adv_sort", "order", "order_by"].includes(fBtnType) &&
1586 !isActive
1587 ) {
1588 const otherBtns = that.find(
1589 `.ultp-filter-button[data-type="${fBtnType}"]`,
1590 );
1591 if (otherBtns.length > 0) {
1592 otherBtns.attr("data-is-active", "false");
1593 otherBtns.removeClass("ultp-filter-button-active");
1594 }
1595 }
1596
1597 // Click a button should disable all button
1598 else {
1599 const allBtn = that.find('.ultp-filter-button[data-selected="_all"]');
1600 if (allBtn.length > 0) {
1601 allBtn.attr("data-is-active", "false");
1602 allBtn.removeClass("ultp-filter-button-active");
1603 }
1604 }
1605
1606 if (isActive) {
1607 $(currFBtn).attr("data-is-active", "false");
1608 $(currFBtn).removeClass("ultp-filter-button-active");
1609 } else {
1610 $(currFBtn).attr("data-is-active", "true");
1611 $(currFBtn).addClass("ultp-filter-button-active");
1612 if (
1613 ["author"].includes(fBtnType) ||
1614 !($(this).parent().attr("data-multiselect") == "true")
1615 ) {
1616 $(currFBtn)
1617 .siblings()
1618 .attr("data-is-active", "false")
1619 .removeClass("ultp-filter-button-active");
1620 }
1621 }
1622
1623 fetchPostsWithFilter();
1624 });
1625 });
1626
1627 clearBtn.on("click", function () {
1628 resetFilters();
1629 fetchPostsWithFilter();
1630 });
1631
1632 let searchTimeout;
1633
1634 function performSearch(isDebounce) {
1635 clearTimeout(searchTimeout);
1636 searchTimeout = isDebounce
1637 ? setTimeout(fetchPostsWithFilter, 500)
1638 : fetchPostsWithFilter();
1639 }
1640
1641 parent
1642 .find(".ultp-filter-search input")
1643 .off("input")
1644 .on("input", function () {
1645 performSearch(true);
1646 });
1647
1648 parent.find(".ultp-filter-search input").on("keydown", function (e) {
1649 if (e.key === "Enter") {
1650 performSearch(false);
1651 }
1652 });
1653
1654 parent.find(".ultp-filter-search-icon").on("click", function () {
1655 performSearch(false);
1656 });
1657 });
1658
1659 /**************************************
1660 Dark Light Block
1661 **************************************/
1662
1663 // dark light logo vars
1664 const customSrc = ultp_data_frontend?.dark_logo;
1665 const site_logo = $(".ultp-dark-logo.wp-block-site-logo")
1666 .find("img")
1667 .attr("src");
1668 const site_srcset =
1669 $(".ultp-dark-logo.wp-block-site-logo").find("img").attr("srcset") || "";
1670
1671 /************** handle dark light color swap on click **************/
1672 $(document).on(
1673 "click",
1674 ".ultp-dark-light-block-wrapper-content.ultp-frontend .ultp-dl-con",
1675 function (e) {
1676 e.preventDefault();
1677 const parents = $(this).closest(".ultp-dark-light-block-wrapper-content");
1678 const lightMode = $(this).hasClass("ultp-light-con");
1679
1680 const currentParents = $(this).closest(".ultp-dl-after-before-con");
1681 const opponent = parents.find(
1682 `.ultp-${lightMode ? "dark" : "light"}-con`,
1683 );
1684 const opponentParents = opponent.closest(".ultp-dl-after-before-con");
1685
1686 const iconlay = currentParents.data("iconlay");
1687 const iconsize = currentParents.data("iconsize");
1688 const iconrev = currentParents.data("iconrev");
1689
1690 let delay = 0;
1691 if (["layout5", "layout6", "layout7"].includes(iconlay)) {
1692 delay = iconlay == "layout7" ? 500 : 400;
1693 const extraSize =
1694 iconlay == "layout7"
1695 ? $(this).find(".ultp-dl-text").width()
1696 : iconsize / 2;
1697 if (lightMode) {
1698 $(this)
1699 .find(".ultp-dl-svg-con")
1700 .css({
1701 transform: `translateX(calc(${100 * (iconrev ? -1 : 1)}% ${
1702 iconrev ? "-" : "+"
1703 } ${extraSize}px))`,
1704 transition: `transform ${delay / 1000}s ease`,
1705 });
1706 if (iconlay == "layout6") {
1707 $(this)
1708 .find(".ultp-dl-text")
1709 .css({
1710 transform: `translateX(calc(${100 * (iconrev ? 1 : -1)}% ${
1711 iconrev ? "+" : "-"
1712 } ${extraSize}px))`,
1713 transition: `transform ${delay / 1000}s ease`,
1714 });
1715 } else if (iconlay == "layout7") {
1716 $(this)
1717 .find(".ultp-dl-text")
1718 .css({
1719 transform: `translateX(calc(${
1720 (iconrev ? 1 : -1) * iconsize
1721 }px))`,
1722 transition: `transform ${delay / 1000}s ease`,
1723 });
1724 }
1725 } else {
1726 $(this)
1727 .find(".ultp-dl-svg-con")
1728 .css({
1729 transform: `translateX(calc(${100 * (iconrev ? 1 : -1)}% ${
1730 iconrev ? "+" : "-"
1731 } ${extraSize}px))`,
1732 transition: `transform ${delay / 1000}s ease`,
1733 });
1734 if (iconlay == "layout6") {
1735 $(this)
1736 .find(".ultp-dl-text")
1737 .css({
1738 transform: `translateX(calc(${100 * (iconrev ? -1 : 1)}% ${
1739 iconrev ? "-" : "+"
1740 } ${extraSize}px))`,
1741 transition: `transform ${delay / 1000}s ease`,
1742 });
1743 } else if (iconlay == "layout7") {
1744 $(this)
1745 .find(".ultp-dl-text")
1746 .css({
1747 transform: `translateX(calc(${
1748 (iconrev ? -1 : 1) * iconsize
1749 }px))`,
1750 transition: `transform ${delay / 1000}s ease`,
1751 });
1752 }
1753 }
1754 }
1755 setCookie("ultplocalDLMode", lightMode ? "ultpdark" : "ultplight", 60);
1756 setTimeout(() => {
1757 currentParents.addClass("inactive");
1758 opponentParents.removeClass("inactive");
1759
1760 // handle dark light image block
1761 if (lightMode) {
1762 $(".wp-block-ultimate-post-image .ultp-light-image-block").addClass(
1763 "inactive",
1764 );
1765 $(".wp-block-ultimate-post-image .ultp-dark-image-block").removeClass(
1766 "inactive",
1767 );
1768 } else if (!lightMode) {
1769 $(".wp-block-ultimate-post-image .ultp-dark-image-block").addClass(
1770 "inactive",
1771 );
1772 $(
1773 ".wp-block-ultimate-post-image .ultp-light-image-block",
1774 ).removeClass("inactive");
1775 }
1776
1777 // handle dark light logo
1778 $(".ultp-dark-logo.wp-block-site-logo")
1779 .find("img")
1780 .attr("src", lightMode ? customSrc : site_logo)
1781 .attr("srcset", lightMode ? customSrc : site_srcset);
1782 $(".ultp-dark-logo.wp-block-site-logo img").css({ content: "initial" });
1783
1784 // handle more than one block
1785 $(
1786 `.ultp-dark-light-block-wrapper-content .ultp-${
1787 lightMode ? "dark" : "light"
1788 }-con`,
1789 ).each(function () {
1790 $(this).closest(".ultp-dl-after-before-con").removeClass("inactive");
1791 });
1792 $(
1793 `.ultp-dark-light-block-wrapper-content .ultp-${
1794 lightMode ? "light" : "dark"
1795 }-con`,
1796 ).each(function () {
1797 $(this).closest(".ultp-dl-after-before-con").addClass("inactive");
1798 });
1799
1800 // remove transition
1801 $(this).find(".ultp-dl-svg-con").removeAttr("style");
1802 $(this).find(".ultp-dl-text").removeAttr("style");
1803
1804 handleDarkLight();
1805 }, delay);
1806 },
1807 );
1808
1809 /************** set cookie **************/
1810 function setCookie(cookieName, cookieValue, expires) {
1811 const date = new Date();
1812 date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);
1813 let expiresAt = "expires=" + date.toUTCString();
1814 document.cookie = cookieName + "=" + cookieValue + ";" + expiresAt + ";";
1815 }
1816
1817 /************** get registered cookie **************/
1818 function getCookie(cookieName) {
1819 let c_name = cookieName + "=";
1820 let c_array = document.cookie.split(";");
1821 for (let i = 0; i < c_array.length; i++) {
1822 let item = c_array[i];
1823 while (item.charAt(0) == " ") {
1824 item = item.substring(1);
1825 }
1826 if (item.indexOf(c_name) == 0) {
1827 return item.substring(c_name.length, item.length);
1828 }
1829 }
1830 return "";
1831 }
1832
1833 /************** handle dark light color swap **************/
1834 function handleDarkLight() {
1835 if (
1836 $("#ultp-preset-colors-style-inline-css") &&
1837 $("#ultp-preset-colors-style-inline-css")[0]
1838 ) {
1839 const root = $("#ultp-preset-colors-style-inline-css")[0].sheet;
1840 const base1 = root.cssRules[0].style.getPropertyValue(
1841 "--postx_preset_Base_1_color",
1842 );
1843 const base2 = root.cssRules[0].style.getPropertyValue(
1844 "--postx_preset_Base_2_color",
1845 );
1846 const base3 = root.cssRules[0].style.getPropertyValue(
1847 "--postx_preset_Base_3_color",
1848 );
1849
1850 const contrast1 = root.cssRules[0].style.getPropertyValue(
1851 "--postx_preset_Contrast_1_color",
1852 );
1853 const contrast2 = root.cssRules[0].style.getPropertyValue(
1854 "--postx_preset_Contrast_2_color",
1855 );
1856 const contrast3 = root.cssRules[0].style.getPropertyValue(
1857 "--postx_preset_Contrast_3_color",
1858 );
1859
1860 root.cssRules[0].style.setProperty(
1861 "--postx_preset_Base_1_color",
1862 contrast1,
1863 );
1864 root.cssRules[0].style.setProperty(
1865 "--postx_preset_Base_2_color",
1866 contrast2,
1867 );
1868 root.cssRules[0].style.setProperty(
1869 "--postx_preset_Base_3_color",
1870 contrast3,
1871 );
1872
1873 root.cssRules[0].style.setProperty(
1874 "--postx_preset_Contrast_1_color",
1875 base1,
1876 );
1877 root.cssRules[0].style.setProperty(
1878 "--postx_preset_Contrast_2_color",
1879 base2,
1880 );
1881 root.cssRules[0].style.setProperty(
1882 "--postx_preset_Contrast_3_color",
1883 base3,
1884 );
1885 }
1886 }
1887
1888 function handleDailyMotion() {
1889 $(
1890 ".ultp-video-modal .ultp-video-modal__content .ultp-video-wrapper > iframe",
1891 ).each(function () {
1892 const that = $(this);
1893 const videoSrc = that.attr("src");
1894 if (
1895 videoSrc &&
1896 videoSrc.includes("dailymotion.com/player") &&
1897 videoSrc[videoSrc.length - 1] == "&"
1898 ) {
1899 that.attr(
1900 "src",
1901 videoSrc.slice(0, videoSrc.length - 1) + "?autoplay=0",
1902 );
1903 }
1904 });
1905 }
1906 if (isFront) {
1907 handleDailyMotion();
1908 }
1909
1910 // /*************************************
1911 // Tab Block
1912 // *************************************/
1913 // $('.ultp-tabs-content[data-show="click"] .ultp-tab-item-label').on(
1914 // "click",
1915 // function (e) {
1916 // handleTabItem($(this));
1917 // }
1918 // );
1919 // $('.ultp-tabs-content[data-show="hover"] .ultp-tab-item-label').hover(
1920 // function (e) {
1921 // handleTabItem($(this));
1922 // }
1923 // );
1924 // function handleTabItem(that) {
1925 // if (that.closest("body.block-editor-page").length) {
1926 // return;
1927 // }
1928 // const parent = that.closest(".ultp-tabs-content");
1929 // parent.find(".ultp-tab-item-label").removeClass("pt-active");
1930 // that.addClass("pt-active");
1931
1932 // const tabId = that.data("tabid");
1933 // parent
1934 // .find("> .ultp-tabs-content-warp > .wp-block-ultimate-post-tab-item")
1935 // .removeClass("pt-active");
1936 // parent
1937 // .find(
1938 // `> .ultp-tabs-content-warp > .wp-block-ultimate-post-tab-item.${tabId}`
1939 // )
1940 // .addClass("pt-active");
1941 // }
1942 })(jQuery);
1943