| @@ -4,13 +4,44 @@ | ||
| 4 | 4 | const isFront = $("body.postx-admin-page").length == 0; |
| 5 | 5 | // ************************************* |
| 6 | 6 | // Nonce Generation for AJAX |
| 7 | 7 | // ************************************* |
| 8 | - async function getUltpNonce() { | |
| 9 | - const nonce = sessionStorage.getItem("ultp_nonce"); | |
| 10 | - if (nonce) return nonce; | |
| 8 | + const ULTP_NONCE_KEY = "ultp_public_nonce"; | |
| 11 | 9 | |
| 10 | + // sessionStorage throws outright when the browser blocks site data (private | |
| 11 | + // windows, cookie-blocking extensions). Guard every access so that degrades to | |
| 12 | + // "fetch a nonce per request" instead of breaking the block entirely. | |
| 13 | + function readStoredNonce() { | |
| 12 | 14 | try { |
| 15 | + return sessionStorage.getItem(ULTP_NONCE_KEY); | |
| 16 | + } catch (e) { | |
| 17 | + return null; | |
| 18 | + } | |
| 19 | + } | |
| 20 | + | |
| 21 | + function storeNonce(value) { | |
| 22 | + try { | |
| 23 | + sessionStorage.setItem(ULTP_NONCE_KEY, value); | |
| 24 | + } catch (e) { | |
| 25 | + // Not cacheable in this browser; every call refetches instead. | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + function clearStoredNonce() { | |
| 30 | + try { | |
| 31 | + sessionStorage.removeItem(ULTP_NONCE_KEY); | |
| 32 | + } catch (e) { | |
| 33 | + // Nothing was stored, so nothing to clear. | |
| 34 | + } | |
| 35 | + } | |
| 36 | + | |
| 37 | + async function getUltpNonce(forceRefresh = false) { | |
| 38 | + if (!forceRefresh) { | |
| 39 | + const nonce = readStoredNonce(); | |
| 40 | + if (nonce) return nonce; | |
| 41 | + } | |
| 42 | + | |
| 43 | + try { | |
| 13 | 44 | const response = await $.ajax({ |
| 14 | 45 | url: ultp_data_frontend.ajax, |
| 15 | 46 | type: "POST", |
| 16 | 47 | data: { action: "ultp_get_nonce" }, |
| @@ -16,9 +47,9 @@ | ||
| 16 | 47 | data: { action: "ultp_get_nonce" }, |
| 17 | 48 | }); |
| 18 | 49 | |
| 19 | 50 | if (response?.success && response?.data?.nonce) { |
| 20 | - sessionStorage.setItem("ultp_nonce", response.data.nonce); | |
| 51 | + storeNonce(response.data.nonce); | |
| 21 | 52 | return response.data.nonce; |
| 22 | 53 | } |
| 23 | 54 | |
| 24 | 55 | console.log("Failed to fetching nonce"); |
| @@ -31,8 +62,99 @@ | ||
| 31 | 62 | return null; |
| 32 | 63 | } |
| 33 | 64 | } |
| 34 | 65 | |
| 66 | + // A front-end nonce goes stale in normal use: WordPress nonces last 12-24h and | |
| 67 | + // a tab can stay open longer, a full-page cache can serve HTML carrying a nonce | |
| 68 | + // minted for an earlier visitor, and a plugin update can change the action name | |
| 69 | + // under a tab that is already open. All three look identical from here, and | |
| 70 | + // before this existed all three broke the block with no way back short of a | |
| 71 | + // reload. PHP marks exactly this case with ultp_invalid_nonce. | |
| 72 | + function isExpiredNonce(xhr) { | |
| 73 | + return ( | |
| 74 | + xhr?.status === 403 && | |
| 75 | + xhr?.responseJSON?.data?.code === "ultp_invalid_nonce" | |
| 76 | + ); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * $.ajax for the nonce-guarded front-end endpoints. | |
| 81 | + * | |
| 82 | + * Takes the same options as $.ajax plus `nonce`, the value to try first, and | |
| 83 | + * injects it as `wpnonce`. On an expired-nonce 403 it discards the cached | |
| 84 | + * nonce, fetches a fresh one and replays the request once. The retry is | |
| 85 | + * invisible to the caller: `success` runs only for the attempt that worked, | |
| 86 | + * and `complete`/`error` are suppressed on an attempt that is being retried, | |
| 87 | + * so loading states are not torn down half way. | |
| 88 | + */ | |
| 89 | + function ultpAjax(options) { | |
| 90 | + const { | |
| 91 | + nonce: initialNonce, | |
| 92 | + data = {}, | |
| 93 | + success, | |
| 94 | + error, | |
| 95 | + complete, | |
| 96 | + ...rest | |
| 97 | + } = options; | |
| 98 | + | |
| 99 | + let retried = false; | |
| 100 | + | |
| 101 | + function fail(xhr, ...args) { | |
| 102 | + if (typeof error === "function") error.call(this, xhr, ...args); | |
| 103 | + if (typeof complete === "function") complete.call(this, xhr, ...args); | |
| 104 | + } | |
| 105 | + | |
| 106 | + function send(nonce) { | |
| 107 | + // Set per attempt, not per call: it must not leak into the retry. | |
| 108 | + let retrying = false; | |
| 109 | + | |
| 110 | + $.ajax({ | |
| 111 | + ...rest, | |
| 112 | + data: { ...data, wpnonce: nonce }, | |
| 113 | + success, | |
| 114 | + error(xhr, ...args) { | |
| 115 | + if (!retried && isExpiredNonce(xhr)) { | |
| 116 | + retried = true; | |
| 117 | + retrying = true; | |
| 118 | + clearStoredNonce(); | |
| 119 | + getUltpNonce(true).then((fresh) => { | |
| 120 | + if (fresh) { | |
| 121 | + send(fresh); | |
| 122 | + } else { | |
| 123 | + fail.call(this, xhr, ...args); | |
| 124 | + } | |
| 125 | + }); | |
| 126 | + return; | |
| 127 | + } | |
| 128 | + if (typeof error === "function") error.call(this, xhr, ...args); | |
| 129 | + }, | |
| 130 | + complete(xhr, ...args) { | |
| 131 | + if (retrying) return; | |
| 132 | + if (typeof complete === "function") complete.call(this, xhr, ...args); | |
| 133 | + }, | |
| 134 | + }); | |
| 135 | + } | |
| 136 | + | |
| 137 | + // Prefer a nonce fetched live over whatever the caller passed. A caller's | |
| 138 | + // nonce comes either from page HTML, which a full-page cache can serve | |
| 139 | + // stale, or from a value captured once at init and reused for the life of | |
| 140 | + // the page (the infinite scroll script does this). Reading storage first costs | |
| 141 | + // nothing and stops those callers replaying a known-dead nonce forever. | |
| 142 | + const storedNonce = readStoredNonce(); | |
| 143 | + if (storedNonce || initialNonce) { | |
| 144 | + send(storedNonce || initialNonce); | |
| 145 | + return; | |
| 146 | + } | |
| 147 | + | |
| 148 | + getUltpNonce().then((nonce) => { | |
| 149 | + if (nonce) { | |
| 150 | + send(nonce); | |
| 151 | + } else { | |
| 152 | + fail({ status: 0, statusText: "no nonce", responseText: "" }); | |
| 153 | + } | |
| 154 | + }); | |
| 155 | + } | |
| 156 | + | |
| 35 | 157 | // ************************************* |
| 36 | 158 | // Social Share window |
| 37 | 159 | // ************************************* |
| 38 | 160 | $(".ultp-post-share-item a").each(function () { |
| @@ -66,16 +188,16 @@ | ||
| 66 | 188 | .attr("postId"); |
| 67 | 189 | let count = $(this) |
| 68 | 190 | .parents(".ultp-post-share-item-inner-block") |
| 69 | 191 | .attr("count"); |
| 70 | - $.ajax({ | |
| 192 | + ultpAjax({ | |
| 71 | 193 | url: ultp_data_frontend.ajax, |
| 72 | 194 | type: "POST", |
| 195 | + nonce: ultp_data_frontend.security, | |
| 73 | 196 | data: { |
| 74 | 197 | action: "ultp_share_count", |
| 75 | 198 | shareCount: count, |
| 76 | 199 | postId: id, |
| 77 | - wpnonce: ultp_data_frontend.security, | |
| 78 | 200 | }, |
| 79 | 201 | error: function (xhr) { |
| 80 | 202 | console.log( |
| 81 | 203 | "Error occured.please try again" + |
| @@ -141,14 +263,10 @@ | ||
| 141 | 263 | |
| 142 | 264 | function scrollTopButton() { |
| 143 | 265 | if ($(document).scrollTop() > 1000) { |
| 144 | 266 | $(".ultp-toc-backtotop").addClass("tocshow"); |
| 145 | - $(".wp-block-ultimate-post-table-of-content").addClass("ultp-toc-scroll"); | |
| 146 | 267 | } else { |
| 147 | 268 | $(".ultp-toc-backtotop").removeClass("tocshow"); |
| 148 | - $(".wp-block-ultimate-post-table-of-content").removeClass( | |
| 149 | - "ultp-toc-scroll", | |
| 150 | - ); | |
| 151 | 269 | } |
| 152 | 270 | } |
| 153 | 271 | scrollTopButton(); |
| 154 | 272 | |
| @@ -304,12 +422,8 @@ | ||
| 304 | 422 | if (widgetBlock.length > 0) { |
| 305 | 423 | let widget_items = widgetBlock.attr("id").split("-"); |
| 306 | 424 | widgetBlockId = widget_items[widget_items.length - 1]; |
| 307 | 425 | } |
| 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 | 426 | |
| 313 | 427 | // Adv Filter Integration |
| 314 | 428 | const filterValue = parents.data("filter-value") || ""; |
| 315 | 429 | const advFilterData = {}; |
| @@ -323,29 +437,29 @@ | ||
| 323 | 437 | advFilterData.orderby = parents.data("filter-orderby") || ""; |
| 324 | 438 | advFilterData.adv_sort = parents.data("filter-adv-sort") || ""; |
| 325 | 439 | } |
| 326 | 440 | |
| 327 | - $.ajax({ | |
| 441 | + ultpAjax({ | |
| 328 | 442 | url: ultp_data_frontend.ajax, |
| 329 | 443 | 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 || [], | |
| 444 | + nonce: ultp_data_frontend.security, | |
| 445 | + data: postsRequestData( | |
| 446 | + { | |
| 447 | + action: "ultp_next_prev", | |
| 448 | + paged: paged, | |
| 449 | + blockId: parents.data("blockid"), | |
| 450 | + postId: post_ID, | |
| 451 | + exclude: parents.data("expost"), | |
| 452 | + blockName: parents.data("blockname"), | |
| 453 | + builder: parents.data("builder"), | |
| 454 | + filterValue: filterValue, | |
| 455 | + filterType: parents.data("filter-type") || "", | |
| 456 | + widgetBlockId: widgetBlockId, | |
| 343 | 457 | |
| 344 | - ...advFilterData, | |
| 345 | - | |
| 346 | - wpnonce: ultp_data_frontend.security, | |
| 347 | - }, | |
| 458 | + ...advFilterData, | |
| 459 | + }, | |
| 460 | + wrap, | |
| 461 | + ), | |
| 348 | 462 | beforeSend: function () { |
| 349 | 463 | if (blockWrapper.length < 1 && postBlock.length > 0) { |
| 350 | 464 | postBlock.find(".ultp-block-wrapper").addClass("ultp-loading-active"); |
| 351 | 465 | } else { |
| @@ -354,14 +468,9 @@ | ||
| 354 | 468 | }, |
| 355 | 469 | success: function (data) { |
| 356 | 470 | if (data) { |
| 357 | 471 | wrap.html(data); |
| 358 | - setSession( | |
| 359 | - "ultp_uniqueIds", | |
| 360 | - JSON.stringify( | |
| 361 | - wrap.find(".ultp-current-unique-posts").data("ultp-unique-ids"), | |
| 362 | - ), | |
| 363 | - ); | |
| 472 | + postsLoaded(wrap, "replace"); | |
| 364 | 473 | if ($(window).scrollTop() > wrap.offset().top) { |
| 365 | 474 | $([document.documentElement, document.body]).animate( |
| 366 | 475 | { |
| 367 | 476 | scrollTop: wrap.offset().top - 80, |
| @@ -378,9 +487,9 @@ | ||
| 378 | 487 | .removeClass("ultp-loading-active"); |
| 379 | 488 | } else { |
| 380 | 489 | blockWrapper.removeClass("ultp-loading-active"); |
| 381 | 490 | } |
| 382 | - handleDailyMotion(); | |
| 491 | + contentUpdated(); | |
| 383 | 492 | }, |
| 384 | 493 | error: function (xhr) { |
| 385 | 494 | console.log( |
| 386 | 495 | "Error occured.please try again" + xhr.statusText + xhr.responseText, |
| @@ -444,13 +553,8 @@ | ||
| 444 | 553 | let widget_items = widgetBlock.attr("id").split("-"); |
| 445 | 554 | widgetBlockId = widget_items[widget_items.length - 1]; |
| 446 | 555 | } |
| 447 | 556 | |
| 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 | 557 | // Adv Filter Integration |
| 454 | 558 | const filterValue = that.data("filter-value") || ""; |
| 455 | 559 | const advFilterData = {}; |
| 456 | 560 | |
| @@ -463,29 +567,29 @@ | ||
| 463 | 567 | advFilterData.orderby = that.data("filter-orderby") || ""; |
| 464 | 568 | advFilterData.adv_sort = that.data("filter-adv-sort") || ""; |
| 465 | 569 | } |
| 466 | 570 | |
| 467 | - $.ajax({ | |
| 571 | + ultpAjax({ | |
| 468 | 572 | url: ultp_data_frontend.ajax, |
| 469 | 573 | 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 || [], | |
| 574 | + nonce: ultp_data_frontend.security, | |
| 575 | + data: postsRequestData( | |
| 576 | + { | |
| 577 | + action: "ultp_next_prev", | |
| 578 | + paged: paged, | |
| 579 | + blockId: that.data("blockid"), | |
| 580 | + postId: post_ID, | |
| 581 | + blockName: that.data("blockname"), | |
| 582 | + builder: that.data("builder"), | |
| 583 | + exclude: that.data("expost"), | |
| 584 | + filterValue: filterValue, | |
| 585 | + filterType: that.data("filter-type") || "", | |
| 586 | + widgetBlockId: widgetBlockId, | |
| 483 | 587 | |
| 484 | - ...advFilterData, | |
| 485 | - | |
| 486 | - wpnonce: ultp_data_frontend.security, | |
| 487 | - }, | |
| 588 | + ...advFilterData, | |
| 589 | + }, | |
| 590 | + parents, | |
| 591 | + ), | |
| 488 | 592 | beforeSend: function () { |
| 489 | 593 | parents.addClass("ultp-loading-active"); |
| 490 | 594 | |
| 491 | 595 | if (isPagiBlock) { |
| @@ -497,10 +601,8 @@ | ||
| 497 | 601 | if (data) { |
| 498 | 602 | // Fix for grids that have fixed max-height (Adv Pagination Block integration) |
| 499 | 603 | parents.find(".ultp-block-row").css("max-height", "unset"); |
| 500 | 604 | |
| 501 | - parents.find(".ultp-current-unique-posts").remove(); | |
| 502 | - | |
| 503 | 605 | const insertPoint = parents.find(".ultp-loadmore-insert-before"); |
| 504 | 606 | |
| 505 | 607 | if (insertPoint.length) { |
| 506 | 608 | // Adv Pagination block loadmore fix for post modules |
| @@ -524,16 +626,9 @@ | ||
| 524 | 626 | |
| 525 | 627 | cardDiv.append(data); |
| 526 | 628 | } |
| 527 | 629 | |
| 528 | - setSession( | |
| 529 | - "ultp_uniqueIds", | |
| 530 | - JSON.stringify( | |
| 531 | - parents | |
| 532 | - .find(".ultp-current-unique-posts") | |
| 533 | - .data("ultp-unique-ids"), | |
| 534 | - ), | |
| 535 | - ); | |
| 630 | + postsLoaded(parents, "append"); | |
| 536 | 631 | } |
| 537 | 632 | }, |
| 538 | 633 | |
| 539 | 634 | complete: function () { |
| @@ -589,29 +684,25 @@ | ||
| 589 | 684 | let widget_items = widgetBlock.attr("id").split("-"); |
| 590 | 685 | widgetBlockId = widget_items[widget_items.length - 1]; |
| 591 | 686 | } |
| 592 | 687 | |
| 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 | 688 | if (parents.data("blockid")) { |
| 599 | - $.ajax({ | |
| 689 | + ultpAjax({ | |
| 600 | 690 | url: ultp_data_frontend.ajax, |
| 601 | 691 | 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 | - }, | |
| 692 | + nonce: ultpNonce, | |
| 693 | + data: postsRequestData( | |
| 694 | + { | |
| 695 | + action: "ultp_filter", | |
| 696 | + taxtype: parents.data("taxtype"), | |
| 697 | + taxonomy: that.data("taxonomy"), | |
| 698 | + blockId: parents.data("blockid"), | |
| 699 | + postId: post_ID, | |
| 700 | + blockName: parents.data("blockname"), | |
| 701 | + widgetBlockId: widgetBlockId, | |
| 702 | + }, | |
| 703 | + wrap, | |
| 704 | + ), | |
| 614 | 705 | beforeSend: function () { |
| 615 | 706 | wrap.addClass("ultp-loading-active"); |
| 616 | 707 | }, |
| 617 | 708 | success: function (response) { |
| @@ -672,15 +763,10 @@ | ||
| 672 | 763 | } |
| 673 | 764 | }, |
| 674 | 765 | complete: function () { |
| 675 | 766 | 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(); | |
| 767 | + postsLoaded(wrap, "replace"); | |
| 768 | + contentUpdated(); | |
| 683 | 769 | }, |
| 684 | 770 | error: function (xhr) { |
| 685 | 771 | console.log( |
| 686 | 772 | "Error occured.please try again" + |
| @@ -754,17 +840,8 @@ | ||
| 754 | 840 | parents.find(".ultp-prev-page-numbers a").blur(); |
| 755 | 841 | parents.find(".ultp-next-page-numbers a").blur(); |
| 756 | 842 | } |
| 757 | 843 | |
| 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 | 844 | // session value set function |
| 768 | 845 | function setSession(key, value) { |
| 769 | 846 | if (value != undefined) { |
| 770 | 847 | sessionStorage.setItem(key, value); |
| @@ -792,8 +869,89 @@ | ||
| 792 | 869 | url, |
| 793 | 870 | ); |
| 794 | 871 | } |
| 795 | 872 | |
| 873 | + // ************************************* | |
| 874 | + // Common Pagination AJAX Dispatcher | |
| 875 | + // ************************************* | |
| 876 | + function paginationAjaxCall({ | |
| 877 | + wrap, // .ultp-block-wrapper Selector | |
| 878 | + builder, // Get Builder Data | |
| 879 | + post_ID, | |
| 880 | + exclude, | |
| 881 | + pageNum, | |
| 882 | + blockid, | |
| 883 | + ultpNonce, // Get Nonce | |
| 884 | + blockName, | |
| 885 | + filterType, | |
| 886 | + widgetBlockId, | |
| 887 | + filterValue, | |
| 888 | + advFilterData = {}, | |
| 889 | + onSuccess, | |
| 890 | + onBeforeSend, | |
| 891 | + }) { | |
| 892 | + if (!pageNum) return; | |
| 893 | + | |
| 894 | + // console.log({ | |
| 895 | + // exclude, | |
| 896 | + // action: "ultp_pagination", | |
| 897 | + // paged: pageNum, | |
| 898 | + // blockId: blockid, | |
| 899 | + // postId: post_ID, | |
| 900 | + // blockName, | |
| 901 | + // builder, | |
| 902 | + // widgetBlockId, | |
| 903 | + // filterType: filterType || "", | |
| 904 | + // wpnonce: ultpNonce, | |
| 905 | + // filterValue, | |
| 906 | + // ...advFilterData, | |
| 907 | + // }); | |
| 908 | + | |
| 909 | + ultpAjax({ | |
| 910 | + url: ultp_data_frontend.ajax, | |
| 911 | + type: "POST", | |
| 912 | + nonce: ultpNonce, | |
| 913 | + data: postsRequestData( | |
| 914 | + { | |
| 915 | + exclude, | |
| 916 | + action: "ultp_pagination", | |
| 917 | + paged: pageNum, | |
| 918 | + blockId: blockid, | |
| 919 | + postId: post_ID, | |
| 920 | + blockName, | |
| 921 | + builder, | |
| 922 | + widgetBlockId, | |
| 923 | + filterType: filterType || "", | |
| 924 | + filterValue, | |
| 925 | + ...advFilterData, | |
| 926 | + }, | |
| 927 | + wrap, | |
| 928 | + ), | |
| 929 | + beforeSend() { | |
| 930 | + if (typeof onBeforeSend === "function") { | |
| 931 | + onBeforeSend(); | |
| 932 | + } else { | |
| 933 | + wrap.addClass("ultp-loading-active"); | |
| 934 | + } | |
| 935 | + }, | |
| 936 | + success(data) { | |
| 937 | + if (typeof onSuccess === "function") onSuccess(data); | |
| 938 | + }, | |
| 939 | + complete() { | |
| 940 | + wrap.removeClass("ultp-loading-active"); | |
| 941 | + contentUpdated(); | |
| 942 | + }, | |
| 943 | + error(xhr) { | |
| 944 | + console.log( | |
| 945 | + "Error occured. please try again " + | |
| 946 | + xhr.statusText + | |
| 947 | + xhr.responseText, | |
| 948 | + ); | |
| 949 | + wrap.removeClass("ultp-loading-active"); | |
| 950 | + }, | |
| 951 | + }); | |
| 952 | + } | |
| 953 | + | |
| 796 | 954 | $(document).on( |
| 797 | 955 | "click", |
| 798 | 956 | ".ultp-pagination-ajax-action li", |
| 799 | 957 | async function (e) { |
| @@ -803,9 +961,21 @@ | ||
| 803 | 961 | let that = $(this), |
| 804 | 962 | parents = that.closest(".ultp-pagination-ajax-action"), |
| 805 | 963 | wrap = that.closest(".ultp-block-wrapper"); |
| 806 | 964 | |
| 965 | + if (parents.is(".ultp-disable-editor-click")) { | |
| 966 | + return; | |
| 967 | + } | |
| 968 | + | |
| 969 | + let pageNum = 1; | |
| 970 | + let pages = parents.attr("data-pages"); | |
| 971 | + | |
| 972 | + const exclude = parents.data("expost"); | |
| 973 | + const builder = parents.data("builder"); | |
| 974 | + const blockName = parents.data("blockname"); | |
| 807 | 975 | const blockid = parents.attr("data-blockid"); |
| 976 | + const filterType = parents.data("filter-type") || ""; | |
| 977 | + const filterValue = parents.data("filter-value") || ""; | |
| 808 | 978 | |
| 809 | 979 | // Pagination block integration |
| 810 | 980 | if (wrap.length < 1) { |
| 811 | 981 | const pagiFor = parents.data("for"); |
| @@ -813,14 +983,8 @@ | ||
| 813 | 983 | wrap = $("." + pagiFor + " .ultp-block-wrapper"); |
| 814 | 984 | } |
| 815 | 985 | } |
| 816 | 986 | |
| 817 | - if (parents.is(".ultp-disable-editor-click")) { | |
| 818 | - return; | |
| 819 | - } | |
| 820 | - let pageNum = 1; | |
| 821 | - let pages = parents.attr("data-pages"); | |
| 822 | - | |
| 823 | 987 | if (that.attr("data-current")) { |
| 824 | 988 | pageNum = Number(that.attr("data-current")); |
| 825 | 989 | parents |
| 826 | 990 | .attr("data-paged", pageNum) |
| @@ -849,8 +1013,15 @@ | ||
| 849 | 1013 | showHide(parents, pageNum, pages); |
| 850 | 1014 | } |
| 851 | 1015 | } |
| 852 | 1016 | |
| 1017 | + let widgetBlockId = ""; | |
| 1018 | + let widgetBlock = that.parents(".widget_block:first"); | |
| 1019 | + if (widgetBlock.length > 0) { | |
| 1020 | + let widget_items = widgetBlock.attr("id").split("-"); | |
| 1021 | + widgetBlockId = widget_items[widget_items.length - 1]; | |
| 1022 | + } | |
| 1023 | + | |
| 853 | 1024 | let post_ID = |
| 854 | 1025 | parents.parents(".ultp-shortcode").length != 0 && |
| 855 | 1026 | parents.data("selfpostid") == "no" |
| 856 | 1027 | ? parents.parents(".ultp-shortcode").data("postid") |
| @@ -858,24 +1029,11 @@ | ||
| 858 | 1029 | |
| 859 | 1030 | if (that.closest(".ultp-builder-content").length > 0) { |
| 860 | 1031 | post_ID = that.closest(".ultp-builder-content").data("postid"); |
| 861 | 1032 | } |
| 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 | 1033 | |
| 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") || ""; | |
| 1034 | + // Build adv filter data from pagination element | |
| 876 | 1035 | const advFilterData = {}; |
| 877 | - | |
| 878 | 1036 | if (Array.isArray(filterValue) && filterValue.length > 0) { |
| 879 | 1037 | advFilterData.filterShow = true; |
| 880 | 1038 | advFilterData.checkFilter = true; |
| 881 | 1039 | advFilterData.isAdv = true; |
| @@ -884,69 +1042,37 @@ | ||
| 884 | 1042 | advFilterData.orderby = parents.data("filter-orderby") || ""; |
| 885 | 1043 | advFilterData.adv_sort = parents.data("filter-adv-sort") || ""; |
| 886 | 1044 | } |
| 887 | 1045 | |
| 888 | - if (pageNum) { | |
| 889 | - if (blockid) { | |
| 890 | - setCurrPage(blockid, pageNum, getCurrPage(blockid)); | |
| 891 | - } | |
| 1046 | + if (blockid) { | |
| 1047 | + setCurrPage(blockid, pageNum, getCurrPage(blockid)); | |
| 1048 | + } | |
| 892 | 1049 | |
| 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 | - ), | |
| 1050 | + // console.log(advFilterData, "advFilterData"); | |
| 1051 | + paginationAjaxCall({ | |
| 1052 | + wrap, | |
| 1053 | + pageNum, | |
| 1054 | + blockid, | |
| 1055 | + ultpNonce, | |
| 1056 | + blockName, | |
| 1057 | + post_ID, | |
| 1058 | + filterType, | |
| 1059 | + widgetBlockId, | |
| 1060 | + exclude, | |
| 1061 | + builder, | |
| 1062 | + filterValue, | |
| 1063 | + advFilterData, | |
| 1064 | + onSuccess(data) { | |
| 1065 | + wrap.find(".ultp-block-items-wrap").html(data); | |
| 1066 | + postsLoaded(wrap, "replace"); | |
| 1067 | + if ($(window).scrollTop() > wrap.offset().top) { | |
| 1068 | + $([document.documentElement, document.body]).animate( | |
| 1069 | + { scrollTop: wrap.offset().top - 80 }, | |
| 1070 | + 100, | |
| 925 | 1071 | ); |
| 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 | - } | |
| 1072 | + } | |
| 1073 | + }, | |
| 1074 | + }); | |
| 949 | 1075 | }, |
| 950 | 1076 | ); |
| 951 | 1077 | |
| 952 | 1078 | // ************************************* |
| @@ -995,14 +1121,10 @@ | ||
| 995 | 1121 | prevArrow: selector.parent().find(".ultp-slick-prev").html(), |
| 996 | 1122 | nextArrow: selector.parent().find(".ultp-slick-next").html(), |
| 997 | 1123 | }; |
| 998 | 1124 | |
| 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"; | |
| 1125 | + // Plain carousel (not centred): set by the block, which gets it from the layout. | |
| 1126 | + let layTemp = selector.data("plain") ? true : false; | |
| 1005 | 1127 | |
| 1006 | 1128 | if (!selector.data("layout")) { |
| 1007 | 1129 | // Slider 1 |
| 1008 | 1130 | if (selector.data("slidelg") < 2) { |
| @@ -1091,52 +1213,8 @@ | ||
| 1091 | 1213 | this.click(); |
| 1092 | 1214 | } |
| 1093 | 1215 | }); |
| 1094 | 1216 | // ************************************* |
| 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 | 1217 | // Advanced Filter |
| 1140 | 1218 | // ************************************* |
| 1141 | 1219 | function getTax(name) { |
| 1142 | 1220 | switch (name) { |
| @@ -1245,17 +1323,13 @@ | ||
| 1245 | 1323 | |
| 1246 | 1324 | filterData.taxonomy = selectedFilters; |
| 1247 | 1325 | |
| 1248 | 1326 | const searchVal = parent.find(".ultp-filter-search input"); |
| 1327 | + | |
| 1249 | 1328 | if (searchVal.length > 0) { |
| 1250 | 1329 | filterData.search = searchVal.val(); |
| 1251 | 1330 | } |
| 1252 | 1331 | |
| 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 | 1332 | let widgetBlockId = ""; |
| 1259 | 1333 | let widgetBlock = parent.parents(".widget_block:first"); |
| 1260 | 1334 | if (widgetBlock.length > 0) { |
| 1261 | 1335 | let widget_items = widgetBlock.attr("id").split("-"); |
| @@ -1264,28 +1338,34 @@ | ||
| 1264 | 1338 | |
| 1265 | 1339 | $(grids).each(function () { |
| 1266 | 1340 | const grid = $(this); |
| 1267 | 1341 | |
| 1268 | - $.ajax({ | |
| 1342 | + ultpAjax({ | |
| 1269 | 1343 | url: ultp_data_frontend.ajax, |
| 1270 | 1344 | type: "POST", |
| 1271 | - data: { | |
| 1272 | - action: "ultp_adv_filter", | |
| 1345 | + nonce: ultp_data_frontend.security, | |
| 1346 | + data: postsRequestData( | |
| 1347 | + { | |
| 1348 | + action: "ultp_adv_filter", | |
| 1273 | 1349 | |
| 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 | - }, | |
| 1350 | + ...filterData, | |
| 1351 | + builder_id: builder, | |
| 1352 | + blockId: blockId, | |
| 1353 | + blockName: blockName, | |
| 1354 | + postId: postId, | |
| 1355 | + widgetBlockId: widgetBlockId, | |
| 1356 | + }, | |
| 1357 | + parent, | |
| 1358 | + ), | |
| 1284 | 1359 | beforeSend: function () { |
| 1285 | 1360 | grid.addClass("ultp-loading-active"); |
| 1286 | 1361 | }, |
| 1287 | 1362 | success: function (response) { |
| 1363 | + // console.log( | |
| 1364 | + // JSON.parse(response.data.filteredData.data_attrs), | |
| 1365 | + // "response", | |
| 1366 | + // ); | |
| 1367 | + console.log("testing", searchVal); | |
| 1288 | 1368 | grid |
| 1289 | 1369 | .closest(".wp-block-ultimate-post-post-grid-parent") |
| 1290 | 1370 | ?.find(".ultp-not-found-message") |
| 1291 | 1371 | ?.remove(); |
| @@ -1326,9 +1406,14 @@ | ||
| 1326 | 1406 | .find(".ultp-pagination-wrap") |
| 1327 | 1407 | .replaceWith(response?.data?.filteredData?.pagination); |
| 1328 | 1408 | } |
| 1329 | 1409 | |
| 1330 | - // Pagination Block Integration | |
| 1410 | + // Lets other scripts react to the block being filtered. Nobody listens by default. | |
| 1411 | + $(document).trigger("ultp_block_filtered", [ | |
| 1412 | + grid, | |
| 1413 | + response.data.filteredData, | |
| 1414 | + ]); | |
| 1415 | + | |
| 1331 | 1416 | if (response?.data?.filteredData?.pagination) { |
| 1332 | 1417 | pagis?.map((pagiClass) => { |
| 1333 | 1418 | let pagi = []; |
| 1334 | 1419 | |
| @@ -1354,14 +1439,9 @@ | ||
| 1354 | 1439 | } |
| 1355 | 1440 | }, |
| 1356 | 1441 | complete: function () { |
| 1357 | 1442 | 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 | - ); | |
| 1443 | + postsLoaded(parent, "replace"); | |
| 1364 | 1444 | }, |
| 1365 | 1445 | error: function (xhr) { |
| 1366 | 1446 | console.log( |
| 1367 | 1447 | "Error occured.please try again" + |
| @@ -1687,71 +1767,15 @@ | ||
| 1687 | 1767 | const iconsize = currentParents.data("iconsize"); |
| 1688 | 1768 | const iconrev = currentParents.data("iconrev"); |
| 1689 | 1769 | |
| 1690 | 1770 | 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 | - } | |
| 1771 | + // A layout that animates the switch (PostX Pro) registers a function that does it and | |
| 1772 | + // returns the delay in milliseconds. | |
| 1773 | + const animate = window.ultpDarkLightAnimations | |
| 1774 | + ? window.ultpDarkLightAnimations[iconlay] | |
| 1775 | + : null; | |
| 1776 | + if (typeof animate === "function") { | |
| 1777 | + delay = animate($(this), { lightMode, iconsize, iconrev }) || 0; | |
| 1754 | 1778 | } |
| 1755 | 1779 | setCookie("ultplocalDLMode", lightMode ? "ultpdark" : "ultplight", 60); |
| 1756 | 1780 | setTimeout(() => { |
| 1757 | 1781 | currentParents.addClass("inactive"); |
| @@ -1884,30 +1908,25 @@ | ||
| 1884 | 1908 | ); |
| 1885 | 1909 | } |
| 1886 | 1910 | } |
| 1887 | 1911 | |
| 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 | - }); | |
| 1912 | + // Posts were added or replaced by an AJAX request. Other scripts listen to fix up the new markup. | |
| 1913 | + function contentUpdated() { | |
| 1914 | + $(document).trigger("ultp_content_updated"); | |
| 1905 | 1915 | } |
| 1906 | - if (isFront) { | |
| 1907 | - handleDailyMotion(); | |
| 1916 | + | |
| 1917 | + // The data of a request for a block's posts. Other scripts may add fields to `data` from the | |
| 1918 | + // `ultp_ajax_request` event; `scope` is the element of the block the request is for. | |
| 1919 | + function postsRequestData(data, scope) { | |
| 1920 | + $(document).trigger("ultp_ajax_request", [data, scope]); | |
| 1921 | + return data; | |
| 1908 | 1922 | } |
| 1909 | 1923 | |
| 1924 | + // A request put posts into `scope`. `mode` is "replace" or "append" (posts added after the | |
| 1925 | + // ones already shown). Nobody listens by default. | |
| 1926 | + function postsLoaded(scope, mode) { | |
| 1927 | + $(document).trigger("ultp_posts_loaded", [scope, mode]); | |
| 1928 | + } | |
| 1910 | 1929 | // /************************************* |
| 1911 | 1930 | // Tab Block |
| 1912 | 1931 | // *************************************/ |
| 1913 | 1932 | // $('.ultp-tabs-content[data-show="click"] .ultp-tab-item-label').on( |
| @@ -1938,5 +1957,13 @@ | ||
| 1938 | 1957 | // `> .ultp-tabs-content-warp > .wp-block-ultimate-post-tab-item.${tabId}` |
| 1939 | 1958 | // ) |
| 1940 | 1959 | // .addClass("pt-active"); |
| 1941 | 1960 | // } |
| 1961 | + | |
| 1962 | + // Helpers for add-on front-end scripts. Keep the names and the arguments: other scripts use them. | |
| 1963 | + window.ultpFrontendApi = Object.assign(window.ultpFrontendApi || {}, { | |
| 1964 | + level: 1, | |
| 1965 | + setSession, // Store a value in sessionStorage (skipped when undefined) | |
| 1966 | + getUltpNonce, // Get Nonce | |
| 1967 | + paginationAjaxCall, // Pagination API Call Function | |
| 1968 | + }); | |
| 1942 | 1969 | })(jQuery); |