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