1; (function ($) { 2 3 // Check video format. 4 function isVideo(url) { 5 var regex = /^(https?:\/\/)?((www\.)?youtube\.com|vimeo\.com|dailymotion\.com|wistia\.com|hubspot\.com|sproutvideo\.com|hippovideo\.io|brightcove\.com|spotlightr\.com|vidyard\.com)\/.+$/i; 6 return regex.test(url); 7 } 8 $(document).find('.sp-easy-accordion').each(function () { 9 var accordion_id = $(this).attr('id'), 10 _this = $(this), 11 ex_icon = _this.data('ex-icon'), 12 keep_accordion = _this.data('keep-accordion'), 13 col_icon = _this.data('col-icon'), 14 ea_active = _this.data('ea-active'), 15 ea_mode = _this.data('ea-mode'), 16 multiColumn = _this.data('ea-multi-column'), 17 preloader = _this.data('preloader'), 18 autoplaytime = _this.data('autoplaytime'), 19 autoclose = _this.data('autoclose'), 20 expand_collapse = _this.data('expand'), 21 scroll_active_item = _this.data('scroll-active-item'), 22 offset_to_scroll = _this.data('offset-to-scroll'); 23 var eap_collapse_button_id = $(this).parents('.sp-eap-container').attr('id'); 24 var multiColumnAccordion = multiColumn === ' ea-multi-column' ? '.eap-multi-items-container >' : ''; 25 if (' ea-multi-column' === multiColumn && 'ea-auto' === ea_active) { 26 ea_active = 'ea-hover'; 27 } 28 29 $(document).ready(function () { 30 31 var collapseLink = $("#" + eap_collapse_button_id + " .eap_faq_collapse_button a"), 32 collapseText = $(collapseLink).parent('.eap_faq_collapse_button').data('collapse-text'), 33 expandText = $(collapseLink).parent('.eap_faq_collapse_button').data('expand-text'), 34 numPanelOpen = $("#" + eap_collapse_button_id + '> .ea-expand').length; 35 36 if (numPanelOpen > 1) { 37 $(collapseLink).html(`${collapseText} <span><i class="fa fa-angle-down"></i></span> <span><i class="fa fa-angle-up"></i></span>`); 38 } else { 39 $(collapseLink).addClass("active"); 40 $(collapseLink).html(`${expandText} <span><i class="fa fa-angle-down"></i></span> <span><i class="fa fa-angle-up"></i></span>`); 41 } 42 }); 43 44 if (!$('body').attr('notLoadAfterAjaxRequest')) { 45 // Collapse/Expand button. 46 $("#" + eap_collapse_button_id + " .eap_faq_collapse_button > a").on("click", function (e) { 47 e.preventDefault(); 48 var numPanelOpen = $("#" + accordion_id + '> ' + multiColumnAccordion + ' .ea-expand').length; 49 numPanelItem = $("#" + accordion_id + '> .ea-card').length, 50 collapseText = $(this).parent('.eap_faq_collapse_button').data('collapse-text'), 51 expandText = $(this).parent('.eap_faq_collapse_button').data('expand-text'); 52 if (numPanelOpen == 0 || numPanelOpen < numPanelItem) { 53 $(this).addClass("active"); 54 } 55 if ($(this).hasClass('active')) { 56 $(this).html(`${collapseText} <span><i class="fa fa-angle-down"></i></span> <span><i class="fa fa-angle-up"></i></span>`); 57 $("#" + accordion_id + " > " + multiColumnAccordion + " .ea-card > .sp-collapse").spcollapse("show"); 58 $(this).removeClass("active"); 59 } else { 60 $(this).addClass("active"); 61 $(this).html(`${expandText} <span><i class="fa fa-angle-down"></i></span> <span><i class="fa fa-angle-up"></i></span>`); 62 $("#" + accordion_id + " > " + multiColumnAccordion + " .ea-card > .sp-collapse").spcollapse("hide"); 63 } 64 }) 65 } 66 67 function activeEvents() { 68 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("hide.bs.spcollapse", function (e) { 69 $(this).parent(".ea-card").removeClass("ea-expand"); 70 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(col_icon).removeClass(ex_icon); 71 e.stopPropagation(); 72 }); 73 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("show.bs.spcollapse", function (e) { 74 $(this).parent(".ea-card").addClass("ea-expand"); 75 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(ex_icon).removeClass(col_icon); 76 e.stopPropagation(); 77 }); 78 79 if (ea_mode === 'vertical') { 80 if (ea_active === 'ea-click') { 81 $("#" + accordion_id).each(function () { 82 $("#" + accordion_id + " > .ea-card > .ea-header").on("click", function () { 83 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("hide.bs.spcollapse", function (e) { 84 $(this).parent(".ea-card").removeClass("ea-expand"); 85 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(col_icon).removeClass(ex_icon); 86 e.stopPropagation(); 87 })
88 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("show.bs.spcollapse", function (e) { 89 $(this).parent(".ea-card").addClass("ea-expand"); 90 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(ex_icon).removeClass(col_icon); 91 e.stopPropagation(); 92 }) 93 }); 94 }); 95 }; 96 if (ea_active === 'ea-auto') { 97 98 $("#" + accordion_id).each(function () { 99 $("#" + accordion_id + " > .ea-card > .ea-header").on("click", function () { 100 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("hide.bs.spcollapse", function (e) { 101 $(this).parent(".ea-card").removeClass("ea-expand"); 102 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(col_icon).removeClass(ex_icon); 103 e.stopPropagation(); 104 }) 105 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("show.bs.spcollapse", function (e) { 106 $(this).parent(".ea-card").addClass("ea-expand"); 107 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(ex_icon).removeClass(col_icon); 108 e.stopPropagation(); 109 }) 110 }); 111 }); 112 113 function ea_autoplay() { 114 var nextItem = $("#" + accordion_id + " > .sp-ea-single.ea-expand").next(); 115 116 while (nextItem.length && nextItem.hasClass('eap_inactive')) { 117 nextItem = nextItem.next(); 118 } 119 120 if (expand_collapse) { 121 $("#" + accordion_id + " > .ea-card > .sp-collapse").spcollapse("hide"); 122 } 123 if (!nextItem.length) { 124 nextItem = $("#" + accordion_id + " > .ea-card").not('.eap_inactive').first(); 125 if (!nextItem.length) { 126 return; 127 } 128 } 129 130 $(nextItem).find('.sp-collapse').spcollapse("show"); 131 } 132 if (!$('body').attr('notLoadAfterAjaxRequest')) { 133 var interval = setInterval(ea_autoplay, autoplaytime); 134 $("#" + accordion_id + ".sp-easy-accordion").hover( 135 function () { 136 clearInterval(interval); 137 }, 138 function () { 139 interval = setInterval(ea_autoplay, autoplaytime); 140 } 141 ); 142 } 143 } 144 145 if (ea_active === 'ea-hover') { 146 if (autoclose == '1') { 147 $("#" + accordion_id + " > .ea-card") 148 .on("mouseenter", function () { 149 $(this).children(".sp-collapse").spcollapse("show"); 150 }) 151 .on("mouseleave", function () { 152 $(this).children(".sp-collapse").spcollapse("hide"); 153 }); 154 } else { 155 $("#" + accordion_id + " > .ea-card").on('mouseover', function () { 156 $(this).children(".sp-collapse").spcollapse("show"); 157 }); 158 } 159 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("hide.bs.spcollapse", function (e) { 160 $(this).parent(".ea-card").removeClass("ea-expand"); 161 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(col_icon).removeClass(ex_icon); 162 e.stopPropagation(); 163 }) 164 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("show.bs.spcollapse", function (e) { 165 $(this).parent(".ea-card").addClass("ea-expand"); 166 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(ex_icon).removeClass(col_icon); 167 e.stopPropagation(); 168 }) 169 }; 170 171 // Scroll to active item scripts. 172 if (scroll_active_item) { 173 $("#" + accordion_id + ' .sp-collapse').on('show.bs.spcollapse', function (e) { 174 var $panel = $(this).closest('.ea-card'); 175 setTimeout(function (e) { 176 $('html,body').animate({ 177 scrollTop: $panel.offset().top - offset_to_scroll 178 }, 500); 179 }, 500) 180 }); 181 } 182 } else if (ea_mode === 'horizontal') { 183 var sp_selector = $("#" + accordion_id + ".sp-horizontal-accordion > .single-horizontal:not(.ea-expand)"); 184 // Horizontal scrollbar scripts. 185 var singleItemWidth = sp_selector.outerWidth(); 186 var horizontalItemsWidth = sp_selector.length * (singleItemWidth + parseInt(sp_selector.css("margin-right"))) + 400; 187 var wrapperWidth = $("#" + accordion_id + ".sp-horizontal-accordion").parents('.sp-eap-container').outerWidth(); 188 var scrollableWidth = horizontalItemsWidth > wrapperWidth ? horizontalItemsWidth : wrapperWidth;
189 $("#" + accordion_id + ".sp-horizontal-accordion").css("width", scrollableWidth); 190 if (horizontalItemsWidth > wrapperWidth) { 191 $("#" + accordion_id + ".sp-horizontal-accordion").wrap("<div class='sp-horizontal-accordion-wrapper'></div>"); 192 } 193 var count = sp_selector.length, 194 itemMargin = count > 1 ? parseInt(sp_selector.css("margin-right")) * count : parseInt($("#" + accordion_id + ".sp-horizontal-accordion > .single-horizontal.ea-expand").css("margin-right")), 195 item_width = count > 1 ? (sp_selector.outerWidth() * count) + itemMargin : parseInt($("#" + accordion_id + ".sp-horizontal-accordion > .single-horizontal.ea-expand").outerWidth()) + itemMargin, 196 containerWidth = $("#" + accordion_id + ".sp-horizontal-accordion").outerWidth(), 197 activeWidth = containerWidth - item_width, 198 activeWidth = activeWidth >= 400 ? activeWidth : 400, 199 activeItem = $("#" + accordion_id + ".sp-horizontal-accordion > .single-horizontal.ea-expand"); 200 activeItem.addClass("active").css("width", activeWidth); 201 if (ea_active === 'ea-hover') { 202 $("#" + accordion_id + " > .ea-card > .ea-header").hover(function (e) { 203 $(this).siblings(".sp-collapse").spcollapse("toggle"); 204 e.stopPropagation(); 205 }); 206 } else { 207 $("#" + accordion_id + " > .ea-card > .ea-header").on('click', function (e) { 208 $(this).siblings(".sp-collapse").spcollapse("toggle"); 209 e.stopPropagation(); 210 }); 211 } 212 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("show.bs.spcollapse", function (e) { 213 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(ex_icon).removeClass(col_icon); 214 $(this).parent(".ea-card").addClass("ea-expand").css("width", activeWidth); 215 e.stopPropagation(); 216 }); 217 $("#" + accordion_id + " > .ea-card > .sp-collapse").on("hide.bs.spcollapse", function (e) { 218 var contentWidth = $(this).outerWidth() >= 400 ? $(this).outerWidth() : 400; 219 $(this).parent(".ea-card").removeClass("ea-expand").css("width", ""); 220 $(this).css("width", contentWidth); 221 $(this).siblings(".ea-header").find(".ea-expand-icon").addClass(col_icon).removeClass(ex_icon); 222 e.stopPropagation(); 223 }); 224 if (ea_active === 'ea-auto') { 225 function ea_autoplay() { 226 var nextItem = $("#" + accordion_id + " > .ea-card.ea-expand").next(); 227 if (!nextItem.length) { 228 $("#" + accordion_id + " > .ea-card > .ea-header a")[0].click(); 229 } 230 $(nextItem).find('.ea-header a').trigger('click'); 231 } 232 if (!$('body').attr('notLoadAfterAjaxRequest')) { 233 var interval = setInterval(ea_autoplay, autoplaytime); // Replace 3000 for delay between each slide. 234 $("#" + accordion_id + " > .ea-card").hover(function () { 235 clearInterval(interval); 236 }, function () { 237 interval = setInterval(ea_autoplay, autoplaytime); // Replace 3000 for delay between each slide. 238 }); 239 } 240 } 241 } 242 if ($('.ea-youtube-wrapper').length < 1) { 243 $(".ea-body object,.ea-body embed").wrap("<div class='ea-youtube-wrapper'></div>"); 244 } 245 // Fix of Twenty twenty theme iframe conflict issue. 246 setTimeout(function () { 247 $('.ea-body iframe[style*="width: 0px"]').css({ 'width': '', 'height': '' }); 248 }, 300); 249 // Iframe wrapper 250 $('#' + accordion_id + ' iframe:not(.ea-iframe,.skip,[src*="omny.fm/"])').each(function (i) { 251 let src = $(this).attr('src'); 252 // Check if the iframe source is video or not. 253 if (isVideo(src)) { 254 let max_width = $(this).attr('width') > 100 ? 'max-width:' + $(this).attr('width') + 'px' : ''; 255 $(this).addClass('ea-iframe').wrap("<div class='ea-iframe-container " + accordion_id + "_" + i + " '></div>"); 256 if (max_width) { 257 $(this).parent('.ea-iframe-container').wrap("<div style='" + max_width + ";width: 100%;display: inline-block;'></div>"); 258 } 259 } 260 }); 261 } 262 activeEvents(); 263 264 var preloader_id = $('.accordion-preloader').attr('id'); 265 if (preloader === 1) { 266 $("#" + accordion_id).each(function () { 267 $('#' + preloader_id).animate({ 268 opacity: 0, 269 }, 500).remove();
270 $('#' + accordion_id).find('.ea-card').animate({ 271 opacity: 1 272 }, 500); 273 }); 274 } 275 276 $("a[href*='#collapse']").on('click', function () { 277 const theTarget = $(this).prop("hash"); 278 $(theTarget + '.spcollapse').parents("[id*='collapse']").spcollapse('show'); 279 $(theTarget + '.spcollapse').spcollapse('show'); 280 }); 281 282 $(".eap_title_to_slug .sp-ea-single a.collapsed").on('click', (e) => { 283 e.preventDefault(); 284 const _this = $(e.currentTarget); 285 const theTarget = _this.data("title"); 286 287 setTimeout(() => { 288 if (_this.hasClass('collapsed')) { 289 // Remove hash from URL 290 history.pushState("", document.title, window.location.pathname + window.location.search); 291 } else { 292 // Update hash in URL 293 if (window.location.hash === `#${theTarget}`) { 294 $(window).trigger('hashchange'); 295 } else { 296 window.location.hash = theTarget; 297 } 298 } 299 }, 600); 300 }); 301 302 $(function () { 303 if (window.location.hash !== '') { 304 handleHashChange(window.location.hash); 305 } 306 307 // Handle hash changes dynamically. 308 $(window).on('hashchange', function () { 309 handleHashChange(window.location.hash); 310 }); 311 }); 312 313 // Function to handle hash-based actions 314 function handleHashChange(hash) { 315 const decodedHash = decodeURIComponent(hash); 316 if (decodedHash.indexOf('efaq') !== -1) { 317 // Find the matching element and expand it. 318 const $element = $('[data-title=' + decodedHash.substring(1) + ']'); 319 $element.parents(".ea-header") 320 .siblings('.sp-collapse') 321 .spcollapse('show'); 322 } 323 const $spCollapse = $(decodedHash + '.spcollapse'); 324 $spCollapse.parents("[id*='collapse']").spcollapse('show'); 325 $spCollapse.spcollapse('show'); 326 } 327 328 // FAQ search script. 329 var searchTerm, panelContainerId; 330 // Create a new contains that is case insensitive 331 $.expr.pseudos.containsCaseInsensitive = function (n, i, m) { 332 return $(n).text().toUpperCase().indexOf(m[1].toUpperCase()) >= 0; 333 }; 334 var Load_more = _this.parents('.sp-eap-container').find('.sp-eap-load-more'), 335 button_attr = Load_more.children('button'), 336 total_accordion = button_attr.data('total-post'); 337 338 $('#eap_faq_search_bar_' + accordion_id).on('keyup', debounce(function () { 339 const searchTerm = $(this).val(); 340 const postId = $(this).data('shortcode-id'); 341 const search_autocomplete = $(this).data('autocomplete'); 342 const containerId = `sp-eap-accordion-section-${postId}`; 343 const $container = $(this).parents('.sp-eap-container'); 344 345 // Preloader and opacity changes 346 $container.find('.ea-multi-column .sp-ea-single').css('opacity', '0'); 347 $container.find(".ea-multi-column .eap-multi-items-container").contents().unwrap(); 348 349 $.ajax({ 350 type: 'POST', 351 url: sp_eap_ajax_obj.ajax_url, 352 data: { 353 action: 'sp_eap_ajax_load_search', 354 nonce: sp_eap_ajax_obj.nonce, 355 id: postId, 356 keyword: searchTerm, 357 event: 'search', 358 }, 359 success: function (response) { 360 var $data = $(response); 361 // Autocomplete suggestion code. 362 if (search_autocomplete) { 363 initializeAutocomplete(accordion_id, $data); 364 } 365 updateAccordionContent(postId, containerId, $data, searchTerm); 366 // Highlight search term 367 $(`#${accordion_id} .ea-card`).css('opacity', 1); 368 $(`#sp-ea-${postId}.sp-easy-accordion`).removeHighlight().highlight(searchTerm); 369 // Expand the accordion inside a accordion if search found. 370 if (ea_mode === 'vertical' || ea_mode === 'multi-column') { 371 handleNestedAccordions(containerId, searchTerm); 372 } 373 } 374 }); 375 })); 376 377 // Global search script. 378 // $('#eap_global_faq_search_bar').on('keyup', debounce(function () { 379 // const searchTerm = $(this).val(); 380 // $('.sp-easy-accordion').each(function () { 381 // const $accordion = $(this); 382 // const accordionId = $accordion.attr('id'); 383 // const postId = $accordion.data('post-id'); 384 // const searchAutocomplete = $accordion.data('autocomplete'); 385 // const containerId = `sp-eap-accordion-section-${postId}`; 386 // const $container = $accordion.parents('.sp-eap-container'); 387 388 // // Preloader and opacity changes 389 // $container.find('.ea-multi-column .sp-ea-single').css('opacity', '0'); 390 // $container.find(".ea-multi-column .eap-multi-items-container").contents().unwrap(); 391 // // AJAX Request 392 // $.ajax({ 393 // type: 'POST', 394 // url: sp_eap_ajax_obj.ajax_url, 395 // data: { 396 // action: 'sp_eap_ajax_load_search', 397 // nonce: sp_eap_ajax_obj.nonce, 398 // id: postId, 399 // keyword: searchTerm, 400 // event: 'search', 401 // }, 402 // success: function (response) { 403 // const $data = $(response); 404 // // Autocomplete suggestions 405 // if (searchAutocomplete) { 406 // initializeAutocomplete(accordionId, $data, true); 407 // } 408 // // Update accordion content 409 // updateAccordionContent(postId, containerId, $data); 410 411 // // Highlight search term 412 // $(`#${accordionId} .ea-card`).css('opacity', 1); 413 // $(`#sp-ea-${postId}.sp-easy-accordion`).removeHighlight().highlight(searchTerm); 414 415 // // Expand matching cards 416 // if (['vertical', 'multi-column'].includes(ea_mode)) { 417 // handleNestedAccordions(containerId, searchTerm); 418 // } 419 // }, 420 // }); 421 // }); 422 // })); 423 // $('#eap_global_faq_search_bar').on('keyup', debounce(function () { 424 // const searchTerm = $(this).val(); 425 // // if (!searchTerm.trim()) return; 426 427 // const accordions = $('.sp-easy-accordion');
428 // const postIds = []; 429 // const accordionMeta = {}; 430 431 // accordions.each(function () { 432 // const $accordion = $(this); 433 // const postId = $accordion.data('post-id'); 434 // const autocomplete = $accordion.data('autocomplete'); 435 // const containerId = `sp-eap-accordion-section-${postId}`; 436 // const $container = $accordion.closest('.sp-eap-container'); 437 438 // postIds.push(postId); 439 // accordionMeta[postId] = { 440 // accordionId: $accordion.attr('id'), 441 // autocomplete, 442 // container: $container 443 // }; 444 445 // // Optional: visual feedback before request 446 // $container.find('.ea-multi-column .sp-ea-single').css('opacity', '0'); 447 // $container.find(".ea-multi-column .eap-multi-items-container").contents().unwrap(); 448 // }); 449 450 // if (!searchTerm) { 451 // // ð Reset full content if search is cleared 452 // $.ajax({ 453 // type: 'POST', 454 // url: sp_eap_ajax_obj.ajax_url, 455 // data: { 456 // action: 'sp_eap_ajax_load_search', 457 // nonce: sp_eap_ajax_obj.nonce, 458 // keyword: '', 459 // ids: postIds, 460 // event: 'search', 461 // }, 462 // success: function (response) { 463 // if (response.success && response.data) { 464 // $.each(response.data, function (postId, html) { 465 // const meta = accordionMeta[postId]; 466 // if (!meta) return; 467 468 // const $data = $(html); 469 // updateAccordionContent(postId, `sp-eap-accordion-section-${postId}`, $data); 470 // $(`#${meta.accordionId} .ea-card`).css('opacity', 1); 471 // }); 472 // } 473 // }, 474 // error: function (xhr) { 475 // console.error('Global reset AJAX error:', xhr); 476 // } 477 // }); 478 // return; 479 // } 480 481 // // One combined AJAX call 482 // $.ajax({ 483 // type: 'POST', 484 // url: sp_eap_ajax_obj.ajax_url, 485 // data: { 486 // action: 'sp_eap_ajax_load_search', 487 // nonce: sp_eap_ajax_obj.nonce, 488 // keyword: searchTerm, 489 // ids: postIds, 490 // event: 'search', 491 // }, 492 // success: function (response) { 493 // if (response.success && response.data) { 494 // $.each(response.data, function (postId, html) { 495 // const meta = accordionMeta[postId]; 496 // if (!meta) return; 497 498 // const $data = $(html); 499 // updateAccordionContent(postId, `sp-eap-accordion-section-${postId}`, $data); 500 // $(`#${meta.accordionId} .ea-card`).css('opacity', 1); 501 // $(`#sp-ea-${postId}.sp-easy-accordion`).removeHighlight().highlight(searchTerm); 502 503 // if (meta.autocomplete) { 504 // initializeAutocomplete(meta.accordionId, $data, true); 505 // } 506 507 // if (['vertical', 'multi-column'].includes(ea_mode)) { 508 // handleNestedAccordions(`sp-eap-accordion-section-${postId}`, searchTerm); 509 // } 510 // }); 511 // } 512 // }, 513 // error: function (xhr) { 514 // console.error('Global search AJAX error:', xhr); 515 // } 516 // }); 517 // })); 518 519 $('#eap_global_faq_search_bar').on('keyup', debounce(function () { 520 const $input = $(this); 521 const searchTerm = $input.val().trim(); 522 const isReset = searchTerm === ''; 523 524 const postIds = []; 525 const accordionMeta = {}; 526 527 // Cache meta for each accordion 528 $('.sp-easy-accordion').each(function () { 529 const $accordion = $(this); 530 const postId = $accordion.data('post-id'); 531 if (!postId) return; 532 533 const meta = { 534 accordionId: $accordion.attr('id'), 535 autocomplete: $accordion.data('autocomplete'), 536 container: $accordion.closest('.sp-eap-container') 537 }; 538 539 postIds.push(postId); 540 accordionMeta[postId] = meta; 541 542 // Visual feedback before AJAX 543 meta.container.addClass('loading'); 544 meta.container.find('.ea-multi-column .sp-ea-single').css('opacity', '0'); 545 meta.container.find('.ea-multi-column .eap-multi-items-container').contents().unwrap(); 546 }); 547 548 // Prepare AJAX data 549 const ajaxData = { 550 action: 'sp_eap_ajax_load_search', 551 nonce: sp_eap_ajax_obj.nonce, 552 keyword: searchTerm, 553 ids: postIds, 554 event: 'search' 555 }; 556 557 // AJAX call 558 $.ajax({ 559 type: 'POST', 560 url: sp_eap_ajax_obj.ajax_url, 561 data: ajaxData, 562 success: function (response) { 563 if (response.success && response.data) { 564 $.each(response.data, function (postId, html) { 565 const meta = accordionMeta[postId]; 566 if (!meta) return; 567 568 const $data = $(html); 569 updateAccordionContent(postId, `sp-eap-accordion-section-${postId}`, $data, searchTerm, true); 570 571 const $accordion = $(`#${meta.accordionId}`); 572 $accordion.find('.ea-card').css('opacity', 1); 573 meta.container.removeClass('loading'); 574 575 if (!isReset) { 576 $accordion.removeHighlight().highlight(searchTerm); 577 578 if (meta.autocomplete) { 579 initializeAutocomplete(meta.accordionId, $data, true); 580 } 581 582 if (['vertical', 'multi-column'].includes(ea_mode)) { 583 handleNestedAccordions(`sp-eap-accordion-section-${postId}`, searchTerm); 584 } 585 } 586 }); 587 } 588 } 589 }); 590 }, 500)); // Adjust debounce delay if needed 591 592 // ð Clear button 593 $('#sp-global-clear-search-button').on('click', function () { 594 $('#eap_global_faq_search_bar').val('').trigger('keyup'); 595 }); 596 597 598 // Autocomplete initialization 599 function initializeAutocomplete(accordionId, $data, $globalSearch = false) { 600 const optionTexts = []; 601 $data.find('.ea-header').each(function (i, v) { 602 JSON.stringify(v); 603 optionTexts[i] = $(v).text().trim(); 604 }); 605 $.widget('ui.customAutocompleteWidget', $.ui.autocomplete, { 606 renderItem: function (ul, item) { 607 return $('<li>') 608 .append($('<a>').html(decodeURI(item.label))) 609 .appendTo(ul); 610 } 611 }); 612 const searchInput = $globalSearch ? $('#eap_global_faq_search_bar') : $(`#eap_faq_search_bar_${accordionId}`); 613 searchInput.customAutocompleteWidget({ 614 source: optionTexts, 615 delay: 0, 616 create: function () { 617 $(this).customAutocompleteWidget('widget') 618 .addClass('eap-autocomplete-wrapper') 619 .css({ 620 'max-height': 500, 621 'overflow-y': 'scroll', 622 'overflow-x': 'hidden' 623 }); 624 }, 625 select: function (event, ui) { 626 $(this).val(ui.item.label).trigger('keyup'); 627 return false;
628 } 629 }); 630 } 631 632 function updateAccordionContent(id, containerId, $data, searchTerm = '', globalSearch = '') { 633 $(`#sp-ea-${id}`).empty().html($data); 634 const $container = $(`#${containerId}`); 635 $container.find('.sp-eap-load-more').hide(); 636 $container.find('.sp-eap-ajax-number-pagination').hide(); 637 $container.find('.accordion-preloader').fadeOut(100); 638 639 accordion_id = $container.find('.sp-easy-accordion').attr('id'), 640 _this = $container.find('.sp-easy-accordion'), 641 ex_icon = _this.data('ex-icon'), 642 keep_accordion = _this.data('keep-accordion'), 643 col_icon = _this.data('col-icon'), 644 ea_active = _this.data('ea-active'), 645 ea_mode = _this.data('ea-mode'), 646 multiColumn = _this.data('ea-multi-column'), 647 preloader = _this.data('preloader'), 648 autoplaytime = _this.data('autoplaytime'), 649 autoclose = _this.data('autoclose'), 650 expand_collapse = _this.data('expand'), 651 scroll_active_item = _this.data('scroll-active-item'), 652 offset_to_scroll = _this.data('offset-to-scroll'); 653 eap_collapse_button_id = $container.attr('id'); 654 multiColumnAccordion = multiColumn === ' ea-multi-column' ? '.eap-multi-items-container >' : ''; 655 if (' ea-multi-column' === multiColumn && 'ea-auto' === ea_active) { 656 ea_active = 'ea-hover'; 657 } 658 activeEvents(); 659 multiColumnAccordionWrapper(); 660 keepActiveAccordion(); 661 662 // Reset pagination if search is empty 663 const $searchInputHide = $container.find(`#eap_faq_search_bar_container`); 664 if (searchTerm && globalSearch) { 665 $searchInputHide.hide(); 666 } else { 667 $searchInputHide.show(); 668 } 669 670 if (!searchTerm) { 671 $container.find('.sp-eap-load-more').show(); 672 $container.find('.sp-eap-ajax-number-pagination').show(); 673 $.getScript(sp_eap_ajax_pagi.loadPagiScript); 674 } 675 const $sectionTitle = $container.find(`.eap_section_title_${id}`); 676 if ($container.find('.sp-ea-single').length > 0) { 677 $sectionTitle.show(); 678 } else { 679 $sectionTitle.hide(); 680 } 681 } 682 683 // Handle nested accordions during a search 684 function handleNestedAccordions(containerId, searchTerm) { 685 const $accordion = $(`#${containerId} .sp-easy-accordion`); 686 if ($accordion.length > 1) { 687 $accordion.find('.ea-card').each(function () { 688 const $card = $(this); 689 if (!$card.find('.eap-search-highlight').length && searchTerm) { 690 $card.remove(); 691 } 692 }); 693 } 694 } 695 696 function debounce(func, wait = 800) { 697 let timeout; 698 return function (...args) { 699 clearTimeout(timeout); 700 timeout = setTimeout(() => func.apply(this, args), wait); 701 }; 702 } 703 704 // FAQ search result highlighting script. 705 jQuery.fn.highlight = function (pat) { 706 function innerHighlight(node, pat) { 707 var skip = 0; 708 if (node.nodeType == 3) { 709 var pos = node.data.toUpperCase().indexOf(pat); 710 pos -= (node.data.substr(0, pos).toUpperCase().length - node.data.substr(0, pos).length); 711 if (pos >= 0) { 712 var spanTag = document.createElement('span'); 713 spanTag.className = 'eap-search-highlight'; 714 var middleBit = node.splitText(pos); 715 var endBit = middleBit.splitText(pat.length); 716 var middleClone = middleBit.cloneNode(true); 717 spanTag.appendChild(middleClone); 718 middleBit.parentNode.replaceChild(spanTag, middleBit); 719 skip = 1; 720 } 721 } 722 else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) { 723 for (var i = 0; i < node.childNodes.length; ++i) { 724 i += innerHighlight(node.childNodes[i], pat); 725 } 726 } 727 return skip; 728 } 729 return this.length && pat && pat.length ? this.each(function () { 730 innerHighlight(this, pat.toUpperCase()); 731 }) : this; 732 }; 733 jQuery.fn.removeHighlight = function () { 734 return this.find("span.eap-search-highlight").each(function () { 735 this.parentNode.firstChild.nodeName; 736 with (this.parentNode) { 737 replaceChild(this.firstChild, this); 738 normalize(); 739 } 740 }).end(); 741 }; 742 743 // highlight matching word. 744 $('#eap_faq_search_bar_' + accordion_id).on('keyup', function () { 745 searchTerm = $(this).val(); 746 $("#" + accordion_id + ".sp-easy-accordion").removeHighlight().highlight(searchTerm); 747 }); 748 // Add event listener to the " Search clear" button
749 $('#clear-search-button-' + accordion_id).on('click', function () { 750 $('#eap_faq_search_bar_' + accordion_id).val(''); 751 $('#eap_faq_search_bar_' + accordion_id).trigger('keyup'); 752 }); 753 754 // $('#eap_global_faq_search_bar').on('keyup', function () { 755 // searchTerm = $(this).val(); 756 // $('.sp-easy-accordion').removeHighlight().highlight(searchTerm); 757 // }); 758 // $('#sp-global-clear-search-button').on('click', function () { 759 // $('#eap_global_faq_search_bar').val(''); 760 // $('#eap_global_faq_search_bar').trigger('keyup'); 761 // }); 762 763 // Multi Column Accordion scripts. 764 function multiColumnAccordionWrapper() { 765 const container = $("#" + accordion_id + ".sp-easy-accordion.ea-multi-column"); 766 // Divide items into two divs 767 if (container.length > 0) { 768 const items = container.children(".sp-ea-single"); 769 const halfLength = Math.ceil(items.length / 2); 770 const div1 = $("<div>").addClass("eap-multi-items-container").appendTo(container); 771 items.slice(0, halfLength).appendTo(div1); 772 773 const div2 = $("<div>").addClass("eap-multi-items-container").appendTo(container); 774 items.slice(halfLength).appendTo(div2); 775 const checkPagination = container.parents('.sp-eap-container').find('.sp-eap-load-more'); 776 // Set the opacity of .sp-ea-single elements to 1 777 container.find(".eap-multi-items-container .sp-ea-single").css('opacity', '1'); 778 } 779 }; 780 multiColumnAccordionWrapper(); 781 782 // custom keep accordion. 783 function keepActiveAccordion() { 784 $(document).ready(function () { 785 if (keep_accordion) { 786 var active_col = keep_accordion; 787 $("#" + accordion_id).find(".ea-expand-icon").addClass(col_icon).removeClass(ex_icon); 788 if ($("#" + accordion_id).parents('.spcollapse').length > 0) { 789 if ($("#" + accordion_id).parents('.spcollapse.show').length > 0) { 790 $("#" + accordion_id + " > .ea-card:nth-child(" + active_col + "):not(.ea-expand) > .ea-header a").trigger('click'); 791 } 792 } else { 793 $("#" + accordion_id + " > .ea-card:nth-child(" + active_col + "):not(.ea-expand) > .ea-header a").trigger('click'); 794 } 795 } 796 }); 797 } 798 keepActiveAccordion(); 799 800 801 // Prevent the default link click behavior. 802 $("#" + accordion_id + " > .ea-card .ea-header a").on('click', function (event) { 803 event.preventDefault(); 804 }); 805 806 // Initialize the Image Accordion with improved practices 807 const initImageAccordion = ($accordion, activatorEvent, autoCloseTabs, animationClass, autoplayDelay, enablePauseOnHover) => { 808 const $items = $accordion.find(".sp-eap-image-accordion-item"); 809 let autoplayInterval; 810 let currentItemIndex = 1; 811 812 // Start the autoplay functionality 813 const startAutoplay = () => { 814 stopAutoplay(); 815 autoplayInterval = setInterval(() => { 816 let $currentItem = $items.eq(currentItemIndex); 817 818 // Skip inactive items 819 while ($currentItem.hasClass('eap_inactive_item')) { 820 currentItemIndex = (currentItemIndex + 1) % $items.length; 821 $currentItem = $items.eq(currentItemIndex); 822 823 // Stop autoplay if all items are inactive 824 if (currentItemIndex === 0 && $currentItem.hasClass('eap_inactive_item')) { 825 stopAutoplay(); 826 return; 827 } 828 } 829 830 // Activate the next valid item 831 activateItem($currentItem); 832 currentItemIndex = (currentItemIndex + 1) % $items.length; 833 }, autoplayDelay); 834 }; 835 836 // Stop the autoplay functionality 837 const stopAutoplay = () => { 838 clearInterval(autoplayInterval); 839 }; 840 841 // Activate an accordion item 842 const activateItem = ($item) => { 843 $item.addClass('active').siblings().removeClass('active'); 844 if (animationClass !== 'false') { 845 $items.not($item).find('.sp-eap-image-accordion-content-wrapper').removeClass(animationClass); 846 $item.find('.sp-eap-image-accordion-content-wrapper').addClass(animationClass); 847 } 848 }; 849 850 // Event binding for hover activation 851 if (activatorEvent === 'ea-hover') { 852 $accordion.on('mouseover', '.sp-eap-image-accordion-item', (e) => { 853 activateItem($(e.currentTarget)); 854 }); 855 if (autoCloseTabs) { 856 $accordion.on('mouseleave', () => { 857 $items.removeClass('active'); 858 }); 859 } 860 } 861 862 // Event binding for click activation
863 if (activatorEvent === 'ea-click' || activatorEvent === 'ea-auto') { 864 $accordion.on('click', '.sp-eap-image-accordion-item', (e) => { 865 const $clickedItem = $(e.currentTarget); 866 867 // Stop autoplay and activate the clicked item 868 stopAutoplay(); 869 activateItem($clickedItem); 870 currentItemIndex = $items.index($clickedItem); 871 872 // Restart autoplay if applicable 873 if (activatorEvent === 'ea-auto') { 874 startAutoplay(); 875 } 876 }); 877 } 878 879 // Enable autoplay 880 if (activatorEvent === 'ea-auto') { 881 startAutoplay(); 882 883 // Pause autoplay on hover 884 if (enablePauseOnHover) { 885 $accordion.on('mouseenter', stopAutoplay); 886 $accordion.on('mouseleave', startAutoplay); 887 } 888 } 889 }; 890 891 // Initialize the accordion dynamically on document ready 892 $(document).ready(() => { 893 $(".sp-eap-image-accordion-wrapper").each(function () { 894 const $parent = $(this).closest('.eap-image-accordion'); 895 const activatorEvent = $parent.data('ea-active'); 896 const autoCloseTabs = $parent.data('autoclose'); 897 const autoplayDelay = $parent.data('autoplaytime'); 898 const enablePauseOnHover = $parent.data('pause'); 899 const animationClass = $parent.data('animation'); 900 901 // Initialize each accordion 902 initImageAccordion($(this), activatorEvent, autoCloseTabs, animationClass, autoplayDelay, enablePauseOnHover); 903 }); 904 }); 905 906 // Product quantity scripts. 907 $('.eap-product-quantity .eap_input_text').on('change', function () { 908 var new_quantity = $(this).val(); 909 var selector = $(this).parents('.eap-product-cart-button').find(".product_type_simple.add_to_cart_button"); 910 selector[0].setAttribute("data-quantity", new_quantity); 911 }); 912 }); 913 914 if ($('body').find('.sp-easy-accordion').length > 0) { 915 $('body').attr('notLoadAfterAjaxRequest', '1'); 916 } 917 918 // wpforms initialization. 919 $(document).ajaxComplete(function () { 920 if (typeof wpforms !== 'undefined') { 921 wpforms.init(); 922 } 923 }); 924 925})(jQuery); 926 927
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.