| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { exit; } ?> |
| 2 |
<script> |
| 3 |
jQuery(document).ready(function($) { |
| 4 |
let listSidebarCatTitles = $( |
| 5 |
".betterdocs-sidebar-content .betterdocs-sidebar-list-wrapper .betterdocs-sidebar-list .betterdocs-category-header" |
| 6 |
); |
| 7 |
let catTitleList = $( |
| 8 |
".betterdocs-sidebar-content .betterdocs-category-grid-wrapper .betterdocs-single-category-wrapper .betterdocs-category-header" |
| 9 |
); |
| 10 |
let currentActiveCat = $( |
| 11 |
".betterdocs-sidebar-content .betterdocs-category-grid-wrapper .betterdocs-single-category-wrapper.active" |
| 12 |
); |
| 13 |
let listSidebarCurrentCat = $( |
| 14 |
".betterdocs-sidebar-content .betterdocs-sidebar-list-wrapper .betterdocs-sidebar-list.active" |
| 15 |
); |
| 16 |
|
| 17 |
let nestedCategoriesToggle = $(".betterdocs-nested-category-title"); |
| 18 |
|
| 19 |
// When "Lazy Load Sidebar Docs & Subcategories" is on, non-active |
| 20 |
// categories render an empty body (data-bd-lazy="1") and the docs are |
| 21 |
// fetched on click. That fetch normally lives in category-toggler.js, |
| 22 |
// which binds on window.load and does NOT run inside the Elementor editor |
| 23 |
// preview — so replicate it here. The AJAX returns the category's full |
| 24 |
// doc list, so all docs display (no cap). No-ops for non-lazy bodies. |
| 25 |
function loadLazyBody($body) { |
| 26 |
if (!$body.length || $body.attr("data-bd-lazy") !== "1") return; |
| 27 |
if ($body.attr("data-bd-loaded") === "1" || $body.attr("data-bd-loading") === "1") return; |
| 28 |
var cfg = window.betterdocsCategoryGridConfig || {}; |
| 29 |
// The config object is not reliably printed into the Elementor editor |
| 30 |
// preview, so fall back to the PHP-injected admin-ajax URL. Without this |
| 31 |
// the editor fetch bailed on `!cfg.ajax_url` and no docs loaded, even |
| 32 |
// though the front end (where the config IS present) worked fine. |
| 33 |
var ajaxUrl = cfg.ajax_url || <?php echo wp_json_encode( esc_url_raw( admin_url( 'admin-ajax.php' ) ) ); ?>; |
| 34 |
var lazyAction = cfg.lazy_load_action || "betterdocs_lazy_category_body"; |
| 35 |
if (!ajaxUrl) return; |
| 36 |
var category_icon = $body.closest(".betterdocs-sidebar-layout-7").length ? "folder" : ""; |
| 37 |
$body.attr("data-bd-loading", "1"); |
| 38 |
$.post(ajaxUrl, { |
| 39 |
action: lazyAction, |
| 40 |
term_id: $body.attr("data-bd-term-id"), |
| 41 |
category_icon: category_icon |
| 42 |
}).done(function (resp) { |
| 43 |
if (resp && resp.success && resp.data && typeof resp.data.html === "string") { |
| 44 |
$body.html(resp.data.html).attr("data-bd-loaded", "1").removeAttr("data-bd-lazy"); |
| 45 |
} |
| 46 |
}).always(function () { |
| 47 |
$body.removeAttr("data-bd-loading"); |
| 48 |
}); |
| 49 |
} |
| 50 |
|
| 51 |
function categoryAccordion() { |
| 52 |
let $parentThis = this; |
| 53 |
currentActiveCat |
| 54 |
.addClass("show") |
| 55 |
.find(".betterdocs-body") |
| 56 |
.css("display", "block"); |
| 57 |
currentActiveCat |
| 58 |
.siblings() |
| 59 |
.find(".betterdocs-body") |
| 60 |
.css("display", "none"); |
| 61 |
catTitleList.on("click", function (e) { |
| 62 |
e.preventDefault(); |
| 63 |
let $parentCat = jQuery(e.target).closest( |
| 64 |
".betterdocs-single-category-wrapper" |
| 65 |
); |
| 66 |
let $body = $parentCat |
| 67 |
.children(".betterdocs-single-category-inner") |
| 68 |
.children(".betterdocs-body"); |
| 69 |
if (!$body.length) { |
| 70 |
$body = $parentCat.find(".betterdocs-body").first(); |
| 71 |
} |
| 72 |
loadLazyBody($body); |
| 73 |
$body.slideToggle(); |
| 74 |
$parentCat |
| 75 |
.addClass("active") |
| 76 |
.toggleClass("show") |
| 77 |
.siblings() |
| 78 |
.removeClass("active") |
| 79 |
.find(".betterdocs-body") |
| 80 |
.slideUp(); |
| 81 |
}); |
| 82 |
} |
| 83 |
categoryAccordion(); |
| 84 |
|
| 85 |
function categoryListAccordion() { |
| 86 |
let $parentThis = this; |
| 87 |
listSidebarCurrentCat |
| 88 |
.find(".betterdocs-body") |
| 89 |
.css("display", "block"); |
| 90 |
listSidebarCurrentCat |
| 91 |
.siblings() |
| 92 |
.find(".betterdocs-body") |
| 93 |
.css("display", "none"); |
| 94 |
listSidebarCatTitles.on("click", function (e) { |
| 95 |
console.log(e.target); |
| 96 |
e.preventDefault(); |
| 97 |
let $parentCat = jQuery(e.target).closest( |
| 98 |
".betterdocs-sidebar-list" |
| 99 |
); |
| 100 |
$parentCat.find(".betterdocs-body").slideToggle(); |
| 101 |
$parentCat |
| 102 |
.toggleClass("active") |
| 103 |
.siblings() |
| 104 |
.removeClass("active") |
| 105 |
.find(".betterdocs-body") |
| 106 |
.slideUp(); |
| 107 |
}); |
| 108 |
} |
| 109 |
categoryListAccordion(); |
| 110 |
|
| 111 |
function nestedCategoryToggler() { |
| 112 |
nestedCategoriesToggle.on("click", function (e) { |
| 113 |
e.preventDefault(); |
| 114 |
jQuery(this).children(".toggle-arrow").toggle(); |
| 115 |
jQuery(this).next(".betterdocs-nested-category-list").slideToggle(); |
| 116 |
}); |
| 117 |
} |
| 118 |
nestedCategoryToggler(); |
| 119 |
}); |
| 120 |
</script> |
| 121 |
|
| 122 |
|
| 123 |
|