1(function($) { 2 "use strict"; 3 4 $(document).ready(function() { 5 thim_widget_loginout.init(); 6 }); 7 8 var thim_widget_loginout = window.$thim_widget_loginout = { 9 10 init: function() { 11 // this.login_popup(); 12 this.login_error(); 13 this.page_login_error(); 14 }, 15 16 /** 17 * Login popup form 18 */ 19 login_popup: function() { 20 21 $('.thim-login').on('click', '.display-box', function(e) { 22 e.preventDefault(); 23 24 var classbox = $(this).attr('data-display'); 25 26 $('.thim-login' + classbox).addClass('active').siblings().removeClass('active'); 27 }); 28 29 $('.thim-loginout .login').magnificPopup({ 30 type: 'inline', 31 removalDelay: 500, //delay removal by X to allow out-animation 32 callbacks: { 33 beforeOpen: function() { 34 this.st.mainClass = this.st.el.attr('data-effect'); 35 } 36 }, 37 focus: '#thim_login', 38 midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source. 39 }); 40 41 42 $(function($) { 43 $('#thim_login, #thim_login_ac').attr('placeholder', 'Username'); 44 $('#thim_pass, #thim_pass_ac').attr('placeholder', 'Password'); 45 }); 46 47 $("#thim-popup-login #loginform .login-password").each(function() { 48 $(this).append("<span id=\"show_pass\"><i class=\"thimcon-eye-slash\"></i></span>"); 49 }); 50 51 var el = document.getElementById('show_pass'); 52 53 if (el) { 54 el.addEventListener("click", function(e) { 55 var pwd = document.getElementById("thim_pass"); 56 57 if (pwd.getAttribute("type") == "password") { 58 pwd.setAttribute("type", "text"); 59 } else { 60 pwd.setAttribute("type", "password"); 61 } 62 }); 63 } 64 65 $(".my-account #loginform .login-password").each(function() { 66 $(this).append("<span id=\"show_pass_ac\"><i class=\"thimcon-eye-slash\"></i></span>"); 67 }); 68 69 var el2 = document.getElementById('show_pass_ac'); 70 71 if (el2) { 72 el2.addEventListener("click", function() { 73 var pwd2 = document.getElementById("thim_pass_ac"); 74 75 if (pwd2.getAttribute("type") == "password") { 76 pwd2.setAttribute("type", "text"); 77 } else { 78 pwd2.setAttribute("type", "password"); 79 } 80 }); 81 } 82 83 }, 84 /** 85 * Notifications error for formsub-menu 86 */ 87 login_error: function() { 88 89 // Validate login submit 90 $('.thim-login form#loginform').submit(function(event) { 91 var elem = $(this), 92 input_username = elem.find('#thim_login, #thim_login_ac'), 93 input_pass = elem.find('#thim_pass, #thim_pass_ac'); 94 95 if (input_username.length > 0 && input_username.val() == '') { 96 input_username.addClass('invalid'); 97 event.preventDefault(); 98 } 99 100 if (input_pass.length > 0 && input_pass.val() == '') { 101 input_pass.addClass('invalid'); 102 event.preventDefault(); 103 } 104 }); 105 106 //Register form untispam 107 $('.thim-login form#registerform').submit(function(event) { 108 var elem = $(this), 109 input_username = elem.find('#user_login'), 110 input_email = elem.find('#user_email'), 111 input_pass = elem.find('#password'), 112 input_rppass = elem.find('#repeat_password'); 113 114 var email_valid = /[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/igm; 115 116 if (input_username.length > 0 && input_username.val() == '') { 117 input_username.addClass('invalid'); 118 event.preventDefault(); 119 } 120 121 if (input_email.length > 0 && (input_email.val() == '' || !email_valid.test(input_email.val()))) { 122 input_email.addClass('invalid'); 123 event.preventDefault(); 124 } 125 126 if (input_pass.val() !== input_rppass.val() || input_pass.val() == '') { 127 input_pass.addClass('invalid'); 128 input_rppass.addClass('invalid'); 129 event.preventDefault(); 130 } 131 }); 132 133 // Validate lostpassword submit 134 $('.thim-login form#lostpasswordform').submit(function(event) { 135 var elem = $(this), 136 input_username = elem.find('#user_login'); 137 138 if (input_username.length > 0 && input_username.val() == '') { 139 input_username.addClass('invalid'); 140 event.preventDefault(); 141 } 142 }); 143
144 // Remove class invalid 145 $('.thim-login #thim_login, .thim-login #thim_pass, .thim-login #user_login, .thim-login #thim_login_ac, .thim-login #thim_pass_ac').on('focus', function() { 146 $(this).removeClass('invalid'); 147 }); 148 149 }, 150 page_login_error: function() { 151 // Validate login submit 152 $('.thim-form-login form.loginfrom').submit(function(event) { 153 var elem = $(this), 154 input_username = elem.find('.login-username input'), 155 input_pass = elem.find('.login-password input'); 156 157 if (input_username.length > 0 && input_username.val() == '') { 158 input_username.addClass('invalid'); 159 event.preventDefault(); 160 } 161 162 if (input_pass.length > 0 && input_pass.val() == '') { 163 input_pass.addClass('invalid'); 164 event.preventDefault(); 165 } 166 }); 167 // Remove class invalid 168 169 $('.thim-form-login form.thim-register-form').submit(function(event) { 170 var elem = $(this), 171 input_username = elem.find('.login-username input'), 172 user_email = elem.find('.login-email input'), 173 password = elem.find('.login-password .rg_password'), 174 repeat_password = elem.find('.login-password .rg_rp_password'); 175 var login_path = 'login'; 176 if (input_username.length > 0 && input_username.val() == '') { 177 input_username.addClass('invalid'); 178 event.preventDefault(); 179 } else { 180 document.cookie = "user_login=" + input_username.val() + ";path=login_path"; 181 } 182 if (user_email.length > 0 && user_email.val() == '') { 183 user_email.addClass('invalid'); 184 event.preventDefault(); 185 } else { 186 document.cookie = "user_email=" + user_email.val() + ";path=login_path"; 187 } 188 if (password.length > 0 && password.val() == '') { 189 password.addClass('invalid'); 190 event.preventDefault(); 191 } 192 if (repeat_password.length > 0 && repeat_password.val() == '') { 193 repeat_password.addClass('invalid'); 194 event.preventDefault(); 195 } 196 197 }); 198 $('.login-username input,.login-password input,.login-email input').on('focus', function() { 199 $(this).removeClass('invalid'); 200 }); 201 }, 202 203 }; 204 205})(jQuery); 206/** 207 * Script custom for theme 208 * 209 * TABLE OF CONTENT 210 * 211 * Header: main menu 212 * Header: main menu mobile 213 * Sidebar: sticky sidebar 214 * Feature: Preloading 215 * Feature: Back to top 216 */ 217 218(function($) { 219 "use strict"; 220 $(document).ready(function () { 221 222 $('.single-accordion').each(function () { 223 $(this).find('.single-accordion-header').on('click', function () { 224 var parent_class = $(this).parent() 225 if (parent_class.hasClass('single-accordion-changelog-inner')) { 226 parent_class.find('.single-accordion-content').toggle(); 227 } else { 228 parent_class.find('.single-accordion-content').slideToggle(); 229 } 230 parent_class.toggleClass('active') 231 }) 232 }) 233 234 $(document).on('click', '.thim-extend-support-notice__toggle', function (e) { 235 e.preventDefault(); 236 var $notice = $(this).closest('.thim-extend-support-notice'); 237 var $body = $notice.find('.thim-extend-support-notice__body'); 238 $notice.toggleClass('is-open'); 239 $body.stop(true, true).slideToggle(250); 240 }); 241 $('.comment-reply-link').each(function () { 242 $(this).click(function (e) { 243 e.preventDefault(); 244 $('#review_form').find('.woocommerce-review__author').hide(); 245 }) 246 }) 247 $('#cancel-comment-reply-link').each(function () { 248 $(this).click(function (e) { 249 e.preventDefault(); 250 $('#review_form').find('.woocommerce-review__author').show(); 251 }) 252 }) 253 $('.performance-rating').each(function () { 254 var performanceScore = ($('.star-filled', this).attr('data-performance-rating') / 5 * 100); 255 $('.star-filled', this).addClass('star-visible').css('width', performanceScore
255+ '%'); 256 }); 257 258 $('#filter-product').click(function (e) { 259 e.stopPropagation(); 260 $(".widget_filter-price").toggleClass('bar') 261 }); 262 $('body').click(function (e) { 263 if ($('.widget_filter-price').hasClass('bar')) { 264 $(".widget_filter-price").toggleClass('bar') 265 } 266 }); 267 $('.table-collapsible').each(function() { 268 var $wrapper = $(this); 269 var $table = $wrapper.find('table'); 270 var $thead = $table.find('thead'); 271 var $tbody = $table.find('tbody'); 272 // 1. Append toggle icon to last th 273 var $lastTh = $thead.find('tr th').last(); 274 if ($lastTh.find('.toggle-icon').length === 0) { 275 $lastTh.append(' <i class="toggle-icon thimcon-angle-down"></i>'); 276 } 277 // 2. Click anywhere on thead to toggle tbody 278 $thead.css('cursor', 'pointer').on('click', function() { 279 $wrapper.toggleClass('is-collapsed'); 280 $tbody.stop(true, true).fadeToggle(200); 281 }); 282 // 3. Wrap checkmarks 'â' or 'â' in green badge span 283 $tbody.find('td').each(function() { 284 var text = $.trim($(this).text()); 285 if (text === 'â' || text === 'â') { 286 $(this).html('<span class="thimcon-check"></span>'); 287 } 288 }); 289 }); 290 291 // Smooth scroll to target ID on anchor click 292 $('a[href^="#"]').on('click', function (e) { 293 var target = this.hash; 294 if (target && target !== '#') { 295 var $target = $(target); 296 if ($target.length) { 297 e.preventDefault(); 298 var offset = $target.offset().top - 80; 299 $('html, body').stop().animate({ 300 scrollTop: offset > 0 ? offset : 0 301 }, 600); 302 } 303 } 304 }); 305 306 // Toggle .single-product .menu-sticky-button when scrolling 100px or more 307 if ($('.single-product .menu-sticky-button').length) { 308 var $stickyBtn = $('.single-product .menu-sticky-button'); 309 var handleStickyBtn = function() { 310 if ($(window).scrollTop() >= 100) { 311 $stickyBtn.addClass('show'); 312 } else { 313 $stickyBtn.removeClass('.menu-sticky-button'); 314 } 315 }; 316 handleStickyBtn(); 317 $(window).on('scroll', handleStickyBtn); 318 } 319 }); 320 $(document).ready(function() { 321 thim_thimpress.ready(); 322 thim_sc_megamenu.init(); 323 }); 324 $(document).resize(function() { 325 thim_thimpress.resize(); 326 }); 327 328 $(window).load(function() { 329 thim_thimpress.load(); 330 }); 331 var thim_sc_megamenu = window.thim_sc_megamenu = { 332 333 data: {}, 334 init: function() { 335 this.tabs(); 336 this.nav_prev_next(); 337 }, 338 339 tabs: function() { 340 var $sc = $('.thim-sc-megamenu'); 341 $sc.on("mouseenter mouseleave", '.nav-filter .cat-item a', function(event) { 342 event.preventDefault(); 343 $sc = $(this).parents('.thim-sc-megamenu'); 344 345 var cat_slug = $(this).attr('data-cat'); 346 347 $sc.find('.nav-filter .cat-item').removeClass('current'); 348 349 $(this).parents('.cat-item').addClass('current'); 350 351 $sc.find('.tab.' + cat_slug).show().addClass('current').siblings().hide().removeClass('current'); 352 }); 353 }, 354 355 /** 356 * <> navigation 357 * 358 * page navigation with ajax loader 359 */ 360 nav_prev_next: function() { 361 var $sc = $('.thim-sc-megamenu'); 362 363 $sc.on('click', '.page-navigation .nav', function(event) { 364 event.preventDefault(); 365 366 $sc = $(this).parents('.thim-sc-megamenu'); 367 368 var page = parseInt($(this).attr('data-page')), 369 max_page = parseInt($sc.attr('data-max-page')), 370 params = $sc.attr('data-params'), 371 loading = false, 372 sc_id = $sc.attr('id'); 373 if (page <= max_page && page > 0) { 374 if (!loading) { 375 376 loading = true; 377 var data = { 378 action: 'thim_sc_megamenu', 379 page: page, 380 params: params, 381 }; 382 383 var current_page = 1; 384 385 if ($(this).hasClass('nav-next')) { 386 current_page = page - 1; 387 } else { 388 current_page = page + 1; 389 } 390 391 392 if ($sc.hasClass('layout-tabs')) { 393 data['category'] = $sc.find('.tab.current').attr('data-cat'); 394 sc_id = sc_id + data['category']; 395 } 396 397 thim_sc_megamenu.data[sc_id + current_page] = $sc.find('.sc-loop').html(); 398 399 if (thim_sc_megamenu.data[sc_id + page]) { 400 $sc.find('.sc-loop').hide().html(thim_sc_megamenu.data[sc_id + page]).fadeIn('slow'); 401 } else { 402 $.ajax({ 403 type: "POST", 404 url: ajaxurl, 405 data: data, 406 beforeSend: function() { 407 $sc.addClass('loading'); 408 }, 409 success: function(res) { 410 if (res.success) { 411 if ($sc.hasClass('layout-tabs')) { 412 $sc.find('.tab.current').hide().html(res.data).fadeIn('slow'); 413 } else { 414 $sc.find('.sc-loop').hide().html(res.data).fadeIn('slow'); 415 } 416 page = page + 1; 417 loading = false;
418 } 419 $sc.removeClass('loading'); 420 } 421 }); 422 } 423 424 } 425 } 426 }); 427 } 428 }; 429 var thim_thimpress = { 430 431 /** 432 * Call functions when document ready 433 */ 434 ready: function() { 435 this.header_menu(); 436 this.back_to_top(); 437 this.feature_preloading(); 438 this.sticky_sidebar(); 439 this.contactform7(); 440 // this.header_search(); 441 this.minicart_hover(); 442 this.social_share(); 443 this.video_product(); 444 this.fix_navtab(); 445 this.effect_loading_btn(); 446 this.slick_slider(); 447 this.popup_sale(); 448 this.chatbot_notice(); 449 this.messenger_notice(); 450 this.countdown(); 451 this.copy_coupon_code(); 452 this.cart_coupon_form(); 453 this.cart_quantity_buttons(); 454 this.knowledge_base(); 455 this.search(); 456 this.single_product_gallery(); 457 this.content_theme_toggle(); 458 }, 459 resize: function() { 460 this.slick_slider(); 461 }, 462 /** 463 * Call functions when window load. 464 */ 465 load: function() { 466 this.header_menu_mobile(); 467 // this.parallax(); 468 this.thim_post_gallery(); 469 }, 470 471 // CUSTOM FUNCTION IN BELOW 472 content_theme_toggle: function() { 473 $(document).on('click', '.content-theme-toggle', function(e) { 474 e.preventDefault(); 475 var $btn = $(this); 476 var $content = $btn.siblings('.content-theme'); 477 if (!$content.length) { 478 $content = $btn.prev('.content-theme'); 479 } 480 481 if ($btn.hasClass('is-expanded')) { 482 $btn.removeClass('is-expanded'); 483 $content.removeClass('is-expanded'); 484 if ($content.length) { 485 var headerHeight = $('#masthead').outerHeight() || 80; 486 $(window).scrollTop($content.offset().top - headerHeight); 487 } 488 } else { 489 $btn.addClass('is-expanded'); 490 $content.addClass('is-expanded'); 491 } 492 }); 493 }, 494 single_product_gallery: function() { 495 var $mainSlider = $('#thim-product-main-slider'); 496 var $thumbSlider = $('#thim-product-thumb-slider'); 497 498 if (!$mainSlider.length) { 499 return; 500 } 501 502 if ($thumbSlider.length) { 503 $mainSlider.not('.slick-initialized').slick({ 504 slidesToShow: 1, 505 slidesToScroll: 1, 506 arrows: false, 507 fade: true, 508 asNavFor: '#thim-product-thumb-slider' 509 }); 510 511 $thumbSlider.not('.slick-initialized').slick({ 512 slidesToShow: 4, 513 slidesToScroll: 1, 514 asNavFor: '#thim-product-main-slider', 515 dots: false, 516 arrows: false, 517 focusOnSelect: true, 518 responsive: [ 519 { 520 breakpoint: 921, 521 settings: { 522 slidesToShow: 3 523 } 524 }, 525 { 526 breakpoint: 481, 527 settings: { 528 slidesToShow: 2 529 } 530 } 531 ] 532 }); 533 } else { 534 $mainSlider.not('.slick-initialized').slick({ 535 slidesToShow: 1, 536 slidesToScroll: 1, 537 arrows: false, 538 fade: true 539 }); 540 } 541 542 $mainSlider.on('beforeChange', function(event, slick, currentSlide, nextSlide) { 543 var $slide = $(slick.$slides[currentSlide]); 544 $slide.find('iframe').each(function() { 545 var win = this.contentWindow; 546 if (win) { 547 try { 548 win.postMessage(JSON.stringify({ 549 event: 'command', 550 func: 'pauseVideo', 551 args: '' 552 }), '*'); 553 win.postMessage(JSON.stringify({ 554 method: 'pause' 555 }), '*'); 556 } catch (err) {} 557 } 558 }); 559 $slide.find('video').each(function() { 560 if (typeof this.pause === 'function') { 561 this.pause(); 562 } 563 }); 564 }); 565 }, 566 567 thim_post_gallery: function() { 568 if (jQuery().slick) { 569 $('article.format-gallery .flexslider, article.format-gallery .slick-slider-post').not('.slick-initialized').slick({ 570 slidesToShow: 1, 571 slidesToScroll: 1, 572 autoplay: true, 573 autoplaySpeed: 5000, 574 fade: true, 575 dots: false, 576 arrows: true 577 }); 578 } 579 }, 580 581 582 /** 583 * Mobile menu 584 */ 585 header_menu_mobile: function() { 586 $(document).on('click', '.menu-mobile-effect', function(e) { 587 e.stopPropagation(); 588 $('body #wrapper-container').toggleClass('mobile-menu-open'); 589 }); 590 591 $(document).on('click', '.mobile-menu-open #main-content', function() { 592 $('body #wrapper-container.mobile-menu-open').removeClass('mobile-menu-open'); 593 }); 594 595 $('body .mobile-menu-container .navbar-nav>li.menu-item-has-children >a,body .mobile-menu-container .navbar-nav>li.tc-menu-layout-builder >a').after('<span class="icon-toggle"><i class="thimcon-angle-down"></i></span>'); 596 597 598 $('body .mobile-menu-container .navbar-nav>li .icon-toggle').on('click', function(e) { 599 e.stopPropagation(); 600 var title = $(this).prev().text(); 601 $(this).next().prepend('<li class="title-sub-menu">' + title + '</li>'); 602 $(this).parent().addClass('show-sub-menu'); 603 $('.mobile-menu-container .icon-menu-back').addClass('show-icon'); 604 }) 605 606 $('.mobile-menu-container .icon-menu-back').on('click', function(e) { 607 e.stopPropagation(); 608 $('body .mobile-menu-container .navbar-nav>li').removeClass('show-sub-menu'); 609 $('body .mobile-menu-container .navbar-nav>li>.sub-menu > li').remove('.title-sub-menu'); 610 $(this).removeClass('show-icon'); 611 }) 612 }, 613 614 header_menu: function() { 615 var $header = $('#masthead.sticky-header'), 616 off_Top = ($('.content-pusher').length > 0) ? $('.content-pusher').offset().top : 0, 617 menuH = $header.outerHeight(), 618 latestScroll = 0, 619 $topbar = $('#thim-header-topbar'),
620 $main = $('#main-content'), 621 target_top = 0, 622 searchPopup = $("#search-popup"); 623 624 if ($header.length) { 625 $('.top_heading').css({ 626 'padding-top': menuH - 1, 627 }); 628 629 $header.addClass('menu-show'); 630 631 if ($topbar.length) { 632 target_top += $topbar.outerHeight(); 633 } 634 } 635 636 if ($(window).width() <= 768) { 637 $('html').addClass('thim'); 638 $(document).bind('touchmove', function(e) { 639 if ($('body').hasClass('thim-active-search')) { 640 e.preventDefault(); 641 } 642 }); 643 } 644 645 $(window).scroll(function() { 646 647 var current = $(this).scrollTop(), 648 $wrapper = $('body.single'), 649 maxWpadmin = 0, 650 maxHeight = 0; 651 652 if (current > latestScroll) { 653 $header.css({ 654 top: target_top, 655 }); 656 657 if (current > target_top + menuH) { 658 $header.removeClass('affix-top').addClass('affix').removeClass('menu-show').addClass('menu-hidden'); 659 searchPopup.addClass('menu-hidden'); 660 $header.css({ 661 top: off_Top, 662 }); 663 $wrapper.each(function() { 664 if (maxHeight < $(this).find('#masthead.affix').height()) { 665 maxHeight = $(this).find('#masthead.affix').height(); 666 } 667 }); 668 // if (maxHeight > 0 && $(window).width() > 768) { 669 // $wrapper.each(function () { 670 // if ($("#wpadminbar").length) { 671 // maxWpadmin = $("#wpadminbar").height(); 672 // } 673 // var mobile_top = $header.height() + maxWpadmin; 674 // $(this).find('.mobile-menu-container').css('top', mobile_top); 675 676 // }); 677 // } 678 } else { 679 $header.addClass('no-transition'); 680 } 681 682 } else { 683 // scroll up 684 if (current <= target_top) { 685 $header.removeClass('affix').addClass('affix-top').addClass('no-transition'); 686 $header.css({ 687 top: target_top, 688 }); 689 } else { 690 $header.removeClass('no-transition'); 691 $('body').removeClass('mobile-menu-open'); 692 $header.css({ 693 top: off_Top, 694 }); 695 } 696 697 $header.removeClass('menu-hidden').addClass('menu-show'); 698 searchPopup.removeClass('menu-hidden'); 699 } 700 701 latestScroll = current; 702 }); 703 704 $('body:not(.mobile-menu-open) .site-header .nav >li, body:not(.mobile-menu-open) .site-header .nav li,.site-header .nav li ul li').on({ 705 'mouseenter': function() { 706 var $this = $(this); 707 var $subMenu = $this.children('.sub-menu'); 708 if ($subMenu.length) { 709 var hasActiveSubMenu = $this.closest('.nav').find('.sub-menu:visible').length > 0; 710 var delay = hasActiveSubMenu ? 50 : 120; 711 712 var timer = setTimeout(function() { 713 $subMenu.stop(true, true).fadeIn(200); 714 }, delay); 715 $this.data('hoverTimer', timer); 716 } 717 }, 718 'mouseleave': function() { 719 var $this = $(this); 720 var timer = $this.data('hoverTimer'); 721 if (timer) { 722 clearTimeout(timer); 723 $this.removeData('hoverTimer'); 724 } 725 $this.children('.sub-menu').stop(true, true).fadeOut(150); 726 } 727 }); 728 729 }, 730 /** 731 * Back to top 732 */ 733 back_to_top: function() { 734 var $element = $('.back-to-top'); 735 $element.on('click', function() { 736 $('html,body').animate({ scrollTop: '0px' }, 800); 737 return false;
738 }); 739 var $element = $('.button-scroll-to-cart'); 740 $element.on('click', function() { 741 $('html,body').animate({ scrollTop: '400px' }, 800); 742 return false; 743 }); 744 $('.scroll-link').on('click', function() { 745 var target = $(this).find('a').attr('href'); 746 if ($(target).length) { 747 $('html, body').animate({ 748 scrollTop: $(target).offset().top 749 }, 600); 750 } 751 }); 752 }, 753 754 /** 755 * Sticky sidebar 756 */ 757 sticky_sidebar: function() { 758 var offsetTop = 20; 759 760 if ($("#wpadminbar").length) { 761 offsetTop += $("#wpadminbar").outerHeight(); 762 } 763 if ($("#masthead.sticky-header").length) { 764 offsetTop += $("#masthead").outerHeight(); 765 } 766 767 if ($('.sticky-sidebar').length > 0) { 768 $(".sticky-sidebar").theiaStickySidebar({ 769 "containerSelector": "", 770 "additionalMarginTop": offsetTop, 771 "additionalMarginBottom": "0", 772 "updateSidebarHeight": false, 773 "minWidth": "768", 774 "sidebarBehavior": "modern" 775 }); 776 } 777 778 }, 779 780 /** 781 * feature: Preloading 782 */ 783 feature_preloading: function() { 784 var $preload = $('#thim-preloading'); 785 if ($preload.length > 0) { 786 $preload.fadeOut(1000, function() { 787 $preload.remove(); 788 }); 789 } 790 }, 791 792 793 /**
794 * Custom effect and UX for contact form. 795 */ 796 contactform7: function() { 797 $(".wpcf7-submit").on('click', function() { 798 $(this).css("opacity", 0.2); 799 $(this).parents('.wpcf7-form').addClass('processing'); 800 $('input:not([type=submit]), textarea').attr('style', ''); 801 }); 802 803 $(document).on('spam.wpcf7', function() { 804 $(".wpcf7-submit").css("opacity", 1); 805 $('.wpcf7-form').removeClass('processing'); 806 }); 807 808 $(document).on('invalid.wpcf7', function() { 809 $(".wpcf7-submit").css("opacity", 1); 810 $('.wpcf7-form').removeClass('processing'); 811 }); 812 813 $(document).on('mailsent.wpcf7', function() { 814 $(".wpcf7-submit").css("opacity", 1); 815 $('.wpcf7-form').removeClass('processing'); 816 }); 817 818 $(document).on('mailfailed.wpcf7', function() { 819 $(".wpcf7-submit").css("opacity", 1); 820 $('.wpcf7-form').removeClass('processing'); 821 }); 822 823 $('body').on('click', 'input:not([type=submit]).wpcf7-not-valid, textarea.wpcf7-not-valid', function() { 824 $(this).removeClass('wpcf7-not-valid'); 825 }); 826 }, 827 828 header_search: function() { 829 $('#masthead .search-form').on({ 830 'mouseenter': function() { 831 $(this).addClass('active'); 832 // $(this).find('input.search-field').focus(); 833 }, 834 'mouseleave': function() { 835 $(this).removeClass('active'); 836 } 837 }); 838 839 $('.search-submit').on('click', function(e) { 840 var $form = $(this).parents('form'); 841 var s = $form.find('.search-field').val(); 842 if ($form.hasClass('active') && s) { 843 //nothing 844 } else { 845 e.preventDefault(); 846 $form.find('.search-field').focus(); 847 } 848 }); 849 }, 850 851 /** 852 * Effect when hover on mini cart. 853 */ 854 minicart_hover: function() { 855 $('#masthead .widget_shopping_cart').on({ 856 'mouseenter': function() { 857 $(this).addClass('active'); 858 }, 859 'mouseleave': function() { 860 $(this).removeClass('active'); 861 } 862 }); 863 }, 864 865 /** 866 * Social share popup when click 867 */ 868 social_share: function() { 869 $(document).on('click', '.thim-social-share a', function(event) { 870 event.preventDefault(); 871 var shareurl = $(this).attr('href'); 872 873 var top = (screen.availHeight - 500) / 2; 874 var left = (screen.availWidth - 500) / 2; 875 var popup = window.open(shareurl, 'social sharing', 'width=650,height=520,left=' + left + ',top=' + top + ',location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1'); 876 return false; 877 }); 878 }, 879 880 881 /** 882 * Video Product 883 */ 884 video_product: function() { 885 $('.video-container').on('click', '.beauty-intro .btns', function() { 886 var iframe = '<iframe src="' + $(this).closest(".video-container").find(".yt-player").attr('data-video') + '" height= "' + $('.parallaxslider').height() + '"></iframe>'; 887 $(this).closest(".video-container").find(".yt-player").replaceWith(iframe); 888 //debug >HP 889 $(this).closest(".video-container").find('.hideClick:first').css('display', 'none'); 890 }); 891 }, 892 893 894 /** 895 * Fixed tab issue in create topic form 896 */ 897 fix_navtab: function() { 898 $('.nav-tabs').on('shown.bs.tab', 'a', function(e) { 899 if (e.relatedTarget) { 900 $(e.relatedTarget).removeClass('active'); 901 } 902 }); 903 }, 904 905 effect_loading_btn: function() { 906 $('.bbp-submit-wrapper button.button.submit').on('click', function() { 907 $(this).html('<i class="fa fa-spinner fa-spin"></i> Submitting'); 908 $(this).addClass('disable'); 909 }); 910 }, 911 slick_slider: function() { 912 // $('.slick-carousel').imagesLoaded(function() { 913 var slick = $(".slick-carousel"); 914 slick.each(function() { 915 var opt_slider = $(this).data('opt_slider'); 916 $(this).not('.slick-initialized').slick({ 917 autoplay: false, 918 centerPadding: '0px', 919 // centerMode: true, 920 dots: opt_slider['dots'], 921 arrows: opt_slider['arrows'], 922 infinite: true, 923 autoplaySpeed: opt_slider['autoplay'], 924 vertical: opt_slider['vertical'], 925 slidesToShow: opt_slider['item'], 926 slidesToScroll: 1, 927 lazyLoad: 'ondemand', 928 rows: opt_slider['row'], 929 swipeToSlide: true, 930 responsive: [{ 931 breakpoint: 1200, 932 settings: { 933 slidesToShow: opt_slider['item_lg'], 934 slidesToScroll: 1, 935 } 936 }, 937 { 938 breakpoint: 1025, 939 settings: { 940 slidesToShow: opt_slider['item_md'], 941 slidesToScroll: 1, 942 } 943 }, 944 { 945 breakpoint: 768, 946 settings: { 947 slidesToShow: opt_slider['item_sm'], 948 slidesToScroll: 1, 949 } 950 }, 951 { 952 breakpoint: 660, 953 settings: { 954 slidesToShow: opt_slider['item_mb'], 955 slidesToScroll: 1, 956 957 } 958 } 959 ] 960 }); 961 }); 962 // });
963 // $('.thim-list-product.style_2').imagesLoaded(function() { 964 $('.thim-list-product.style_2').not('.slick-initialized').slick({ 965 // centerMode: true, 966 centerPadding: '0', 967 slidesToShow: 1, 968 autoplaySpeed: 5000, 969 speed: 1000, 970 autoplay: false, 971 dots: true, 972 arrows: true, 973 lazyLoad: 'ondemand', 974 responsive: [] 975 }); 976 // }); 977 // Seller 978 // $('.thim-list-product.style_1').imagesLoaded(function() { 979 $('.thim-list-product.style_1').not('.slick-initialized').slick({ 980 // centerMode: true, 981 centerPadding: '33%', 982 slidesToShow: 3, 983 autoplaySpeed: 5000, 984 speed: 1000, 985 autoplay: false, 986 dots: true, 987 arrows: false, 988 lazyLoad: 'ondemand', 989 responsive: [{ 990 breakpoint: 1200, 991 settings: { 992 centerPadding: '20%', 993 } 994 }, 995 { 996 breakpoint: 1024, 997 settings: { 998 centerMode: true, 999 centerPadding: '0', 1000 slidesToShow: 2 1001 } 1002 }, 1003 { 1004 breakpoint: 678, 1005 settings: { 1006 centerMode: true, 1007 centerPadding: '0', 1008 slidesToShow: 1 1009 } 1010 } 1011 ] 1012 }); 1013 // }); 1014 // testimonial-slider 1015 // $('.testimonial-slider-style_1').imagesLoaded(function() { 1016 $('.testimonial-slider-style_1').not('.slick-initialized').slick({ 1017 dots: true, 1018 infinite: true, 1019 speed: 300, 1020 slidesToShow: 2, 1021 lazyLoad: 'ondemand', 1022 slidesToScroll: 1, 1023 responsive: [{ 1024 breakpoint: 1360, 1025 settings: { 1026 slidesToShow: 2, 1027 centerPadding: '40px', 1028 slidesToScroll: 1, 1029 arrows: false 1030 } 1031 }, 1032 { 1033 breakpoint: 1200, 1034 settings: { 1035 centerPadding: '40px', 1036 slidesToShow: 2, 1037 slidesToScroll: 1, 1038 arrows: false 1039 } 1040 }, 1041 { 1042 breakpoint: 769, 1043 settings: { 1044 centerMode: true, 1045 centerPadding: '0', 1046 slidesToShow: 1, 1047 slidesToScroll: 1, 1048 arrows: false 1049 } 1050 } 1051 ] 1052 }); 1053 // }); 1054 $(".slrv_slide-wrappersr").not('.slick-initialized').slick({ 1055 slidesToShow: 3, 1056 slidesToScroll: 1, 1057 infinite: true, 1058 arrows: false, 1059 centerPadding: '30px', 1060 // draggable: false,
1061 prevArrow: false, 1062 nextArrow: false, 1063 dots: true, 1064 responsive: [{ 1065 breakpoint: 1101, 1066 settings: { 1067 slidesToShow: 2, 1068 }, 1069 }, 1070 { 1071 breakpoint: 767, 1072 settings: { 1073 slidesToShow: 1, 1074 arrows: false, 1075 infinite: false, 1076 }, 1077 1078 }, 1079 { 1080 breakpoint: 600, 1081 settings: { 1082 slidesToShow: 1, 1083 arrows: false, 1084 infinite: false, 1085 }, 1086 1087 }, 1088 ], 1089 }); 1090 $('.uagb-slides .swiper-wrapper').not('.slick-initialized').slick({ 1091 dots: true, 1092 infinite: true, 1093 arrows: false, 1094 autoplaySpeed: 5000, 1095 speed: 1000, 1096 autoplay: true, 1097 slidesToShow: 1, 1098 lazyLoad: 'ondemand', 1099 slidesToScroll: 1, 1100 }); 1101 1102 }, 1103 popup_sale: function() { 1104 1105 var sale = $('.inwood-campaign-wrapper'); 1106 if (sale.length < 0) { 1107 return; 1108 } 1109 const EXPIRE_TIME = sale.find('.content-body').data('time_expire'); 1110 const now = new Date().getTime(); 1111 sale.find('.custom-html-widget').after('<button class="inwood-close" title="Close"><i class="thimcon-times"></i></button>'); 1112 var setupTime = localStorage.getItem('thim-sale-popup'); 1113 1114 setTimeout(function() { 1115 if (setupTime == null) { 1116 sale.addClass('inwood-campaign-open'); 1117 } else { 1118 if (now - setupTime > EXPIRE_TIME * 1000 * 60 * 60) { 1119 localStorage.removeItem("thim-sale-popup"); 1120 sale.addClass('inwood-campaign-open'); 1121 } 1122 } 1123 }, 9000); 1124 $('.inwood-close').on('click', function() { 1125 sale.removeClass('inwood-campaign-open') 1126 localStorage.setItem('thim-sale-popup', now); 1127 }) 1128 1129 }, 1130 chatbot_notice: function() { 1131 var noticeChat = $('.notice-chatbot'); 1132 if (noticeChat.length < 0) { 1133 return; 1134 } 1135 const EXPIRE_TIME = 1; 1136 const now = new Date().getTime(); 1137 var setupTime = localStorage.getItem('thim-notice-chatbot'); 1138 setTimeout(function() { 1139 if (setupTime == null) { 1140 noticeChat.addClass('open-notice'); 1141 } else { 1142 if (now - setupTime > EXPIRE_TIME * 1000 * 60 * 60) { 1143 localStorage.removeItem("thim-notice-chatbot"); 1144 noticeChat.addClass('open-notice'); 1145 } 1146 } 1147 }, 200); 1148 $('.notice-chatbot .close-notice').on('click', function() { 1149 noticeChat.removeClass('open-notice') 1150 localStorage.setItem('thim-notice-chatbot', now); 1151 }) 1152 1153 }, 1154 messenger_notice: function() { 1155 var noticeMes = $('.notice-messenger'); 1156 if (noticeMes.length < 0) { 1157 return; 1158 } 1159 const EXPIRE_TIME = 1; 1160 const AUTO_HIDE_TIME = 5000; 1161 const now = new Date().getTime(); 1162 var setupTime = localStorage.getItem('thim-notice-messenger'); 1163 1164 setTimeout(function() { 1165 if (setupTime == null || now - setupTime > EXPIRE_TIME * 1000 * 60 * 60) { 1166 localStorage.removeItem('thim-notice-messenger'); 1167 noticeMes.addClass('open-notice'); 1168 1169 setTimeout(function () { 1170 noticeMes.removeClass('open-notice'); 1171 localStorage.setItem('thim-notice-messenger', new Date().getTime()); 1172 }, AUTO_HIDE_TIME); 1173 } 1174 1175 // if (setupTime == null) { 1176 // noticeMes.addClass('open-notice'); 1177 // } else { 1178 // if (now - setupTime > EXPIRE_TIME * 1000 * 60 * 60) { 1179 // localStorage.removeItem("thim-notice-messenger"); 1180 // noticeMes.addClass('open-notice'); 1181 // } 1182 // } 1183 }, 500); 1184 $('.notice-messenger .close-notice').on('click', function() { 1185 noticeMes.removeClass('open-notice') 1186 localStorage.setItem('thim-notice-messenger', now); 1187 }) 1188 1189 }, 1190 countdown: function() { 1191 var offers = $('.data-coundown'); 1192 if (offers.length <= 0) { 1193 return; 1194 } 1195 1196 offers.each(function() { 1197 var offer = $(this); 1198 const dateEnd = new Date(offer.data('date_end') * 1000); 1199 1200 var x = setInterval(function() { 1201 var distance = dateEnd - new Date(); 1202 1203 var days = Math.floor(distance / (1000 * 60 * 60 * 24)); 1204 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); 1205 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); 1206 var seconds = Math.floor((distance % (1000 * 60)) / 1000); 1207 days = days.toString().padStart(2, '0'); 1208 hours = hours.toString().padStart(2, '0'); 1209 minutes = minutes.toString().padStart(2, '0'); 1210 seconds = seconds.toString().padStart(2, '0'); 1211 if (distance > 0) { 1212 offer.html(days + ' : ' + hours + ' : ' + minutes + ' : ' + seconds); 1213 } 1214 if (distance < 0) { 1215 clearInterval(x); 1216 offer.html('expired'); 1217 } 1218 }, 100); 1219 }); 1220 1221 1222 }, 1223 copy_coupon_code: function() { 1224 $(document).on('click', '.get_code_coupon', function() { 1225 var couponCode = $(this).closest('.right').find('.coupon-code span').text(); 1226 var $temp = $('<textarea>'); 1227 $('body').append($temp); 1228 $temp.val(couponCode).select(); 1229 document.execCommand('copy'); 1230 $temp.remove(); 1231 // Gán giá trá» cho input có ID là coupon_code 1232 if ($('#coupon_code').length) { 1233 $('#coupon_code').val(couponCode).trigger('input'); 1234 } 1235 var $message = $('<div class="copy-message">Coupon code copied: ' + couponCode + '</div>'); 1236 $(this).parent().append($message); 1237 1238 setTimeout(function() { 1239 $message.remove(); 1240 }, 1200); 1241 }); 1242 $('.has-sub-info').click(function(event) { 1243 event.stopPropagation(); 1244 1245 // Hide all other .ps-absolute elements 1246 $('.ps-absolute').not($(this).next()).removeClass('show'); 1247 1248 // Toggle the current .ps-absolute element 1249 $(this).next('.ps-absolute').toggleClass('show'); 1250 }); 1251 1252 // Hide .ps-absolute elements when clicking outside 1253 $(document).click(function() { 1254 $('.ps-absolute').removeClass('show'); 1255 }); 1256 1257 // Prevent click inside .ps-absolute from closing it 1258 $('.ps-absolute').click(function(event) { 1259 event.stopPropagation(); 1260 }); 1261 }, 1262 cart_coupon_form: function() { 1263 var block_coupon = function() { 1264 var $coupon = $('.coupon'); 1265 if (typeof $.fn.block === 'function' && !$coupon.is('.processing')) { 1266 $coupon.addClass('processing').block({ 1267 message: null, 1268 overlayCSS: { 1269 background: '#fff', 1270 opacity: 0.6 1271 } 1272 }); 1273 } 1274 }; 1275 1276 var unblock_coupon = function() { 1277 var $coupon = $('.coupon'); 1278 if (typeof $.fn.unblock === 'function') { 1279 $coupon.removeClass('processing').unblock(); 1280 } 1281 }; 1282 1283 // Hà m áp dụng coupon riêng cho Checkout bằng AJAX chuẩn cá»§a WooCommerce 1284 var apply_coupon_checkout = function() { 1285 var $coupon_field = $('#coupon_code'); 1286 var coupon_code = $coupon_field.val().trim(); 1287 var $coupon_wrapper = $coupon_field.closest('.coupon'); 1288 1289 if (typeof wc_checkout_params === 'undefined') { 1290 return; 1291 } 1292 1293 // Xóa thông báo cÅ© 1294 $('.woocommerce-error, .woocommerce-message, .is-error, .is-success, .checkout-inline-error-message, .coupon-error-notice').remove(); 1295 $coupon_field.removeClass('has-error').removeAttr('aria-invalid').removeAttr('aria-describedby'); 1296 1297 block_coupon(); 1298 1299 var data = { 1300 security: wc_checkout_params.apply_coupon_nonce, 1301 coupon_code: coupon_code, 1302 billing_email: $('form.checkout').find('input[name="billing_email"]').val() || '' 1303 }; 1304 1305 $.ajax({ 1306 type: 'POST', 1307 url: wc_checkout_params.wc_ajax_url.toString().replace('%%endpoint%%', 'apply_coupon'), 1308 data: data, 1309 dataType: 'html', 1310 success: function(response) { 1311 $('.woocommerce-error, .woocommerce-message, .is-error, .is-success, .checkout-inline-error-message, .coupon-error-notice').remove(); 1312 unblock_coupon(); 1313 1314 if (response) { 1315 // Nếu không có thông báo lá»i -> áp dụng coupon thà nh công 1316 if (response.indexOf('woocommerce-error') === -1 && response.indexOf('is-error') === -1) { 1317 $coupon_field.val('').removeClass('has-error'); 1318 1319 var $notice_target = $('.woocommerce-notices-wrapper:first'); 1320 if ($notice_target.length) { 1321 $notice_target.prepend(response); 1322 } else { 1323 $('form.checkout').before(response); 1324 } 1325 1326 if (typeof $.scroll_to_notices === 'function') { 1327 $.scroll_to_notices($('.woocommerce-message')); 1328 } 1329 1330 $(document.body).trigger('applied_coupon_in_checkout', [data.coupon_code]); 1331 $(document.body).trigger('update_checkout', { update_shipping_method: false }); 1332 } else { 1333 // Có thông báo lá»i khi áp dụng mã 1334 var msg = $($.parseHTML(response)).text().trim(); 1335 $coupon_field.addClass('has-error').attr('aria-invalid', 'true').attr('aria-describedby', 'coupon-error-notice'); 1336 1337 var $error_notice = $('<p>', { 1338 class: 'coupon-error-notice', 1339 id: 'coupon-error-notice', 1340 role: 'alert', 1341 text: msg 1342 }); 1343 1344 if ($coupon_wrapper.length) { 1345 $coupon_wrapper.append($error_notice); 1346 } else { 1347 $coupon_field.after($error_notice); 1348 } 1349 1350 $(document.body).trigger('errored_coupon_in_checkout', [data.coupon_code, response]); 1351 } 1352 } 1353 }, 1354 error: function() { 1355 unblock_coupon(); 1356 } 1357 }); 1358 }; 1359 1360 // Khi click button Apply coupon 1361 $(document).on('click', ':input[name="apply_coupon"]', function(e) { 1362 var $button = $(this); 1363 1364 // 1. Trưá»ng hợp trang CART 1365 var $cart_form = $('.woocommerce-cart-form'); 1366 if ($cart_form.length) { 1367 if (!$button.closest('.woocommerce-cart-form').length) { 1368 e.preventDefault(); 1369 block_coupon(); 1370 $(':input[type=submit]').removeAttr('clicked'); 1371 $button.attr('clicked', 'true'); 1372 $cart_form.trigger('submit'); 1373 } 1374 return; 1375 } 1376 1377 // 2. Trưá»ng hợp trang CHECKOUT 1378 var $checkout_form = $('form.checkout'); 1379 if ($checkout_form.length && typeof wc_checkout_params !== 'undefined') { 1380 e.preventDefault(); 1381 apply_coupon_checkout(); 1382 return; 1383 } 1384 }); 1385 1386 // Khi nhấn phÃm Enter trong ô #coupon_code 1387 $(document).on('keydown', '#coupon_code', function(e) { 1388 if ((e.which || e.keyCode) === 13) { 1389 // 1. Trang CART 1390 var $cart_form = $('.woocommerce-cart-form'); 1391 if ($cart_form.length) { 1392 if (!$(this).closest('.woocommerce-cart-form').length) { 1393 e.preventDefault(); 1394 block_coupon(); 1395 $(':input[type=submit]').removeAttr('clicked'); 1396 $(':input[name="apply_coupon"]').attr('clicked', 'true'); 1397 $cart_form.trigger('submit'); 1398 } 1399 return; 1400 } 1401 1402 // 2. Trang CHECKOUT: tránh submit cả form checkout (Äặt hà ng) 1403 var $checkout_form = $('form.checkout'); 1404 if ($checkout_form.length && typeof wc_checkout_params !== 'undefined') { 1405 e.preventDefault(); 1406 apply_coupon_checkout(); 1407 return; 1408 } 1409 } 1410 }); 1411 1412 // Khi WooCommerce áp dụng coupon thà nh công trên Cart: clear ô #coupon_code theo rule mặc Äá»nh 1413 $(document.body).on('applied_coupon', function() { 1414 $('#coupon_code').val(''); 1415 unblock_coupon(); 1416 }); 1417 1418 // Toggle accordion box-coupons chá» trên trang Checkout 1419 $(document).on('click', '.checkout-coupon-accordion .box-coupons-toggle', function(e) { 1420 e.preventDefault(); 1421 var $accordion = $(this).closest('.checkout-coupon-accordion'); 1422 var $content = $accordion.find('.box-coupons-content'); 1423 1424 if ($accordion.hasClass('is-open')) {
1425 $content.stop(true, true).slideUp(300, function() { 1426 $accordion.removeClass('is-open').addClass('is-closed'); 1427 }); 1428 } else { 1429 $content.stop(true, true).slideDown(300, function() { 1430 $accordion.removeClass('is-closed').addClass('is-open'); 1431 }); 1432 } 1433 }); 1434 1435 // Khi áp dụng coupon thà nh công trên Checkout: Äóng accordion 1436 $(document.body).on('applied_coupon_in_checkout', function() { 1437 var $accordion = $('.checkout-coupon-accordion'); 1438 if ($accordion.length) { 1439 $accordion.find('.box-coupons-content').stop(true, true).slideUp(300, function() { 1440 $accordion.removeClass('is-open').addClass('is-closed'); 1441 }); 1442 } 1443 }); 1444 1445 // Khi xóa coupon trên Checkout: clear ô #coupon_code, unblock và má» lại accordion nếu không còn mã nà o 1446 $(document.body).on('removed_coupon_in_checkout', function() { 1447 $('#coupon_code').val('').removeClass('has-error'); 1448 $('.coupon-error-notice').remove(); 1449 unblock_coupon(); 1450 1451 var $accordion = $('.checkout-coupon-accordion'); 1452 if ($accordion.length) { 1453 setTimeout(function() { 1454 var remainingCoupons = $('.woocommerce-checkout-review-order .cart-discount').length; 1455 if (remainingCoupons === 0) { 1456 $accordion.find('.box-coupons-content').stop(true, true).slideDown(300, function() { 1457 $accordion.removeClass('is-closed').addClass('is-open'); 1458 }); 1459 } 1460 }, 500); 1461 } 1462 }); 1463 1464 // Khi coupon bá» lá»i hoặc cart totals ÄÆ°á»£c cáºp nháºt: unblock loading 1465 $(document.body).on('errored_coupon updated_wc_div updated_cart_totals', function() { 1466 unblock_coupon(); 1467 }); 1468 }, 1469 cart_quantity_buttons: function() { 1470 var add_buttons = function() { 1471 $('.woocommerce-cart-form td.product-quantity .quantity').each(function() { 1472 var $quantity = $(this); 1473 var $input = $quantity.find('input.qty'); 1474 1475 if ($input.length && !$input.prop('readonly') && $input.attr('type') !== 'hidden') { 1476 var min = parseFloat($input.attr('min')); 1477 var max = parseFloat($input.attr('max')); 1478 if (!isNaN(min) && !isNaN(max) && min === max) { 1479 return; 1480 } 1481 1482 $quantity.addClass('buttons_added'); 1483 if (!$quantity.find('.minus').length) { 1484 $input.before('<button type="button" class="minus" aria-label="Decrease quantity">−</button>'); 1485 } 1486 if (!$quantity.find('.plus').length) { 1487 $input.after('<button type="button" class="plus" aria-label="Increase quantity">+</button>'); 1488 } 1489 } 1490 }); 1491 }; 1492 1493 add_buttons(); 1494 $(document.body).on('updated_wc_div', add_buttons); 1495 1496 // Click Plus và Minus 1497 $(document).on('click', '.woocommerce-cart-form .product-quantity .minus, .woocommerce-cart-form .product-quantity .plus', function(e) { 1498 e.preventDefault(); 1499 var $btn = $(this); 1500 var $qty = $btn.closest('.quantity').find('input.qty'); 1501 1502 if (!$qty.length || $qty.prop('disabled') || $qty.prop('readonly')) { 1503 return; 1504 } 1505 1506 var currentVal = parseFloat($qty.val()) || 0; 1507 var max = parseFloat($qty.attr('max')); 1508 var min = parseFloat($qty.attr('min')); 1509 var step = parseFloat($qty.attr('step')) || 1; 1510 1511 if (isNaN(min)) { 1512 min = 0; 1513 } 1514 1515 if ($btn.is('.plus')) { 1516 if (!isNaN(max) && currentVal >= max) { 1517 return; 1518 } 1519 var newVal = !isNaN(max) ? Math.min(max, currentVal + step) : currentVal + step; 1520 $qty.val(newVal).trigger('input').trigger('change'); 1521 } else if ($btn.is('.minus')) { 1522 if (currentVal <= min) { 1523 return; 1524 } 1525 var newVal = Math.max(min, currentVal - step); 1526 $qty.val(newVal).trigger('input').trigger('change'); 1527 } 1528 }); 1529 1530 // Tá»± Äá»ng kÃch hoạt Update cart khi thay Äá»i sá» lượng vá»i debounce 500ms 1531 var update_cart_timeout;
1532 $(document).on('change', '.woocommerce-cart-form input.qty', function() { 1533 clearTimeout(update_cart_timeout); 1534 var $update_btn = $('.woocommerce-cart-form :input[name="update_cart"]'); 1535 if ($update_btn.length) { 1536 $update_btn.prop('disabled', false); 1537 update_cart_timeout = setTimeout(function() { 1538 $update_btn.trigger('click'); 1539 }, 500); 1540 } 1541 }); 1542 }, 1543 knowledge_base: function() { 1544 var pages = Array.prototype.slice.call(document.querySelectorAll('[data-kb-page]')); 1545 1546 pages.forEach(function(page) { 1547 var search = page.querySelector('[data-kb-search]'); 1548 var form = page.querySelector('[data-kb-search-form]'); 1549 var tabs = Array.prototype.slice.call(page.querySelectorAll('[data-kb-tab]')); 1550 var items = Array.prototype.slice.call(page.querySelectorAll('[data-kb-item]')); 1551 var pagination = page.querySelector('[data-kb-pagination]'); 1552 var empty = page.querySelector('[data-kb-empty]'); 1553 var perPage = 8; 1554 var currentPage = 1; 1555 var activeTerm = ''; 1556 1557 if (!items.length || !pagination || !empty) { 1558 return; 1559 } 1560 1561 tabs.some(function(tab) { 1562 if (tab.classList.contains('is-active')) { 1563 activeTerm = tab.getAttribute('data-kb-tab'); 1564 return true; 1565 } 1566 1567 return false; 1568 }); 1569 1570 function itemHasTerm(item, termId) { 1571 var terms = item.getAttribute('data-kb-terms') || ''; 1572 return !termId || terms.split(',').indexOf(termId) !== -1; 1573 } 1574 1575 function filteredItems() { 1576 var keyword = search ? (search.value || '').trim().toLocaleLowerCase() : ''; 1577 1578 return items.filter(function(item) { 1579 var title = item.getAttribute('data-kb-title') || ''; 1580 var matchesSearch = !keyword || title.indexOf(keyword) !== -1; 1581 var matchesTerm = keyword ? true : itemHasTerm(item, activeTerm); 1582 1583 return matchesSearch && matchesTerm; 1584 }); 1585 } 1586 1587 function paginationButton(label, pageNumber, isActive, isDisabled, iconClass) { 1588 var element = document.createElement('button'); 1589 element.type = 'button'; 1590 element.disabled = !!isDisabled; 1591 1592 if (iconClass) { 1593 var icon = document.createElement('i'); 1594 icon.className = iconClass; 1595 icon.setAttribute('aria-hidden', 'true'); 1596 element.setAttribute('aria-label', label); 1597 element.appendChild(icon); 1598 } else { 1599 element.textContent = label; 1600 } 1601 1602 if (isActive) { 1603 element.className = 'is-active'; 1604 } 1605 1606 if (!isDisabled && pageNumber) { 1607 element.addEventListener('click', function() { 1608 currentPage = pageNumber; 1609 render(); 1610 }); 1611 } 1612 1613 return element; 1614 } 1615 1616 function render() { 1617 var visibleItems = filteredItems(); 1618 var totalPages = Math.max(1, Math.ceil(visibleItems.length / perPage)); 1619 var start; 1620 var end; 1621 1622 currentPage = Math.min(currentPage, totalPages); 1623 start = (currentPage - 1) * perPage; 1624 end = start + perPage; 1625 1626 items.forEach(function(item) { 1627 item.classList.remove('is-visible'); 1628 item.hidden = true; 1629 }); 1630
1631 visibleItems.slice(start, end).forEach(function(item) { 1632 item.hidden = false; 1633 item.classList.add('is-visible'); 1634 }); 1635 1636 empty.hidden = visibleItems.length > 0; 1637 pagination.innerHTML = ''; 1638 1639 if (visibleItems.length <= perPage) { 1640 return; 1641 } 1642 1643 if (currentPage > 1) { 1644 pagination.appendChild(paginationButton('Previous', currentPage - 1, false, false, 'thimcon-angle-left')); 1645 } 1646 1647 for (var i = 1; i <= totalPages; i++) { 1648 if (i === 1 || i === totalPages || Math.abs(i - currentPage) <= 1) { 1649 pagination.appendChild(paginationButton(String(i), i, i === currentPage, false)); 1650 } else if (i === currentPage - 2 || i === currentPage + 2) { 1651 var dots = document.createElement('span'); 1652 dots.textContent = '...'; 1653 pagination.appendChild(dots); 1654 } 1655 } 1656 1657 if (currentPage < totalPages) { 1658 pagination.appendChild(paginationButton('Next', currentPage + 1, false, false, 'thimcon-angle-right')); 1659 } 1660 } 1661 1662 if (form) { 1663 form.addEventListener('submit', function(event) { 1664 event.preventDefault(); 1665 currentPage = 1; 1666 render(); 1667 }); 1668 } 1669 1670 if (search) { 1671 search.addEventListener('input', function() { 1672 currentPage = 1; 1673 render(); 1674 }); 1675 } 1676
1677 tabs.forEach(function(tab) { 1678 tab.addEventListener('click', function() { 1679 activeTerm = tab.getAttribute('data-kb-tab'); 1680 currentPage = 1; 1681 1682 tabs.forEach(function(item) { 1683 item.classList.toggle('is-active', item === tab); 1684 item.setAttribute('aria-selected', item === tab ? 'true' : 'false'); 1685 }); 1686 1687 if (search) { 1688 search.value = ''; 1689 } 1690 1691 render(); 1692 }); 1693 }); 1694 1695 render(); 1696 }); 1697 }, 1698 search: function() { 1699 const currentPage = { all: 1, posts: 1, products: 1 }; 1700 const totalPages = { all: 1, posts: 1, products: 1 }; 1701 let query = ''; 1702 let layout = 'widget'; 1703 let type_active = 'all'; 1704 const suggestionsContainer = $(".search-suggestions"); 1705 // Hà m cáºp nháºt URL theo domain hiá»n tại 1706 function updateURLParams(params) { 1707 const baseUrl = window.location.origin + '/'; // Giữ nguyên URL gá»c 1708 const urlParams = new URLSearchParams(); // Tạo Äá»i tượng URLSearchParams má»i 1709 1710 // Lặp qua object params và thêm từng tham sá» và o URL 1711 for (const key in params) { 1712 if (params.hasOwnProperty(key)) { 1713 urlParams.set(key, encodeURIComponent(params[key])); 1714 } 1715 } 1716 1717 const newUrl = baseUrl + "?" + urlParams.toString(); // Tạo URL má»i vá»i các tham sá» 1718 window.history.pushState({}, "", newUrl); // Cáºp nháºt URL mà không tải lại trang 1719 } 1720 // Function to load search suggestions 1721 function loadSearchSuggestions(query) { 1722 if (query.length < 2) { 1723 suggestionsContainer.html("").hide(); 1724 return; 1725 } 1726 1727 $.ajax({ 1728 url: ajaxurl, 1729 type: "POST", 1730 data: { action: "ajax_search_suggestions", query: query }, 1731 beforeSend: () => { 1732 suggestionsContainer.html("<p class='search-loading'>Loading...</p>").show() 1733 $('.reset-text').addClass('loading'); 1734 }, 1735 success: (response) => { 1736 suggestionsContainer.html(response.content); 1737 setTimeout(function() { 1738 $('.reset-text').removeClass('loading'); 1739 }, 1000); 1740 }, 1741 error: () => suggestionsContainer.html("<p>Error loading.</p>").show() 1742 }); 1743 } 1744 1745 // Function to load search results 1746 function loadSearchResults(query, type, layout, page, type_active) { 1747 const cacheKey = `cache_${type}_page_${page}`; 1748 const cachedData = getFromCache(cacheKey); // Lấy dữ liá»u từ cache vá»i TTL 1749 const lastQuery = localStorage.getItem("lastQuery"); 1750 // Nếu query thay Äá»i, xóa cache cÅ© 1751 if (query !== lastQuery) { 1752 currentPage[type] = 1; // Reset vá» 1 cho type hiá»n tại 1753 localStorage.clear(); // Xóa cache cÅ© 1754 } 1755 // Nếu page lá»n hÆ¡n 1 nhưng query thay Äá»i, ghi Äè page vá» 1 1756 if (query !== lastQuery && page > 1) { 1757 page = 1; // Äảm bảo bắt Äầu từ trang 1 1758 } 1759 // Nếu dữ liá»u có trong cache và query không thay Äá»i 1760 if (cachedData && query === localStorage.getItem("lastQuery")) { 1761 renderSearchResults(cachedData, type, page, layout); // Hiá»n thá» kết quả từ cache 1762 return; 1763 } 1764 1765 $.ajax({ 1766 url: ajaxurl, 1767 type: "POST", 1768 data: { action: "ajax_search", query, type, layout, page }, 1769 beforeSend: () => { 1770 if (page === 1) { 1771 $(`.${type} .search-results`).html("<p>Searching...</p>"); 1772 } 1773 }, 1774 success: (response) => { 1775 saveToCache(cacheKey, response); // Lưu kết quả và o cache vá»i TTL 1776 localStorage.setItem("lastQuery", query); // Lưu truy vấn hiá»n tại 1777 localStorage.setItem("totalposts", response.count_all); 1778 renderSearchResults(response, type, page, layout); // Hiá»n thá» kết quả 1779 } 1780 }); 1781 } 1782 // Hà m hiá»n thá» kết quả tìm kiếm
1783 function renderSearchResults(response, type, page, layout, type_active) { 1784 const lastQuery = localStorage.getItem("lastQuery"); 1785 const totalposts = localStorage.getItem("totalposts"); 1786 if (layout == 'page') { 1787 if (response.count_all > 0) { 1788 $('.search-tabs').addClass('active'); 1789 } else { 1790 $('.search-tabs').removeClass('active'); 1791 } 1792 } 1793 const targetClass = type === 'posts' ? 'blog-content' : type === 'products' ? 'list-products' : 'search-results'; 1794 if (response.count_all == 0) { 1795 $(`.${type} .search-results`).html(''); 1796 } 1797 if (page === 1) { 1798 $(`.${type} .search-results`).html(response.content); 1799 } else { 1800 // $(`.${type} .search-results`).html(''); 1801 // $(`.${type} .search-results`).append(response.content); 1802 $(`.${type} .${targetClass}`).append(response.content); 1803 } 1804 if (response.count_all < 1) { 1805 $(".tab-link").removeClass("active"); 1806 $(".tab-link").first().addClass("active"); 1807 $('.tab-content').removeClass('active'); 1808 $('.tab-content.all').addClass('active'); 1809 } 1810 $('.count_all').html('(' + response.count_all + ')'); 1811 $('.count_blog').html('(' + response.count_blog + ')'); 1812 $('.count_product').html('(' + response.count_product + ')'); 1813 $('.search-results-number').html(totalposts); 1814 $('.search-results-title').html(lastQuery); 1815 $(`.${type} .search-results`).promise().done(function() { 1816 totalPages[type] = response.total_pages; 1817 // Xóa nút Load More cÅ© nếu có 1818 $(`.${type} .load-more-container`).remove(); 1819 1820 // Thêm nút Load More nếu còn trang Äá» tải 1821 if (page < totalPages[type] && type != 'all') {
1822 const loadMoreButton = ` 1823 <div class="load-more-container"> 1824 <button class="load-more-btn" data-type="${type}" data-page="${page + 1}">Load More</button> 1825 </div> 1826 `; 1827 $(`.${type} .search-results`).after(loadMoreButton); 1828 } 1829 // console.log(totalPages[type]); 1830 // if (totalPages[type] > 1) { 1831 // setTimeout(function () { 1832 // renderPagination(type, totalPages[type], currentPage[type]); 1833 // }, 2000); 1834 // } 1835 }); 1836 1837 } 1838 // Function to render pagination 1839 function renderPagination(type, totalPages, currentPage) { 1840 const paginationList = $(`.tab-content.${type} .pagination-list`); 1841 paginationList.empty(); // Xóa ná»i dung cÅ© 1842 // if (totalPages <= 1) { 1843 // return; 1844 // } 1845 1846 // Sá» trang hiá»n thá» xung quanh trang hiá»n tại 1847 const maxPagesToShow = 5; // Và dụ: hiá»n thá» 5 trang 1848 const halfMaxPages = Math.floor(maxPagesToShow / 2); 1849 1850 // TÃnh toán phạm vi trang cần hiá»n thá» 1851 let startPage = Math.max(1, currentPage - halfMaxPages); 1852 let endPage = Math.min(totalPages, currentPage + halfMaxPages); 1853 1854 // Äảm bảo luôn hiá»n thá» Äá»§ sá» trang tá»i Äa 1855 if (currentPage <= halfMaxPages) { 1856 endPage = Math.min(totalPages, maxPagesToShow); 1857 } 1858 if (currentPage >= totalPages - halfMaxPages) { 1859 startPage = Math.max(1, totalPages - maxPagesToShow + 1); 1860 } 1861 // Tạo nút "First" (Trang Äầu tiên) 1862 if (startPage > 1) { 1863 const firstItem = $('<li class="page-item"></li>'); 1864 const firstLink = $(`<a class="page-link page-numbers" href="#" data-type="${type}" data-page="1">1</a>`); 1865 firstItem.append(firstLink); 1866 paginationList.append(firstItem); 1867 } 1868 1869 // Hiá»n thá» "..." nếu cần 1870 if (startPage > 1) { 1871 const ellipsisItem = $('<li class="page-item disabled"><span class="page-link">...</span></li>'); 1872 paginationList.append(ellipsisItem); 1873 } 1874 1875 // Tạo các nút sá» trang 1876 for (let i = startPage; i <= endPage; i++) { 1877 1878 const pageItem = $('<li class="page-item"></li>'); 1879 const pageLink = $(`<a class="page-link page-numbers" href="#" data-type="${type}" data-page="${i}">${i}</a>`); 1880 1881 if (i === currentPage) { 1882 pageLink.addClass("active current"); // Äánh dấu trang hiá»n tại 1883 } 1884 1885 pageItem.append(pageLink); 1886 paginationList.append(pageItem); 1887 } 1888 1889 // Hiá»n thá» "..." nếu cần 1890 if (endPage < totalPages) { 1891 const ellipsisItem = $('<li class="page-item disabled"><span class="page-link">...</span></li>'); 1892 paginationList.append(ellipsisItem); 1893 } 1894 1895 1896 // Tạo nút "Last" (Trang cuá»i cùng) 1897 if (currentPage < totalPages && endPage < totalPages) { 1898 const lastItem = $('<li class="page-item"></li>'); 1899 const lastLink = $(`<a class="page-link page-numbers" href="#" data-type="${type}" data-page="${totalPages}">${totalPages}</a>`); 1900 lastItem.append(lastLink); 1901 paginationList.append(lastItem); 1902 } 1903 } 1904 // Handle input event 1905 $(".search-input").on("input", function() { 1906 query = $(this).val().trim(); 1907 // Xóa cache nếu truy vấn thay Äá»i 1908 if (query !== localStorage.getItem("lastQuery")) { 1909 localStorage.clear(); // Xóa toà n bá» cache 1910 currentPage.all = 1; // Reset tất cả type khi query thay Äá»i từ input 1911 currentPage.posts = 1; 1912 currentPage.products = 1; 1913 } 1914 loadSearchSuggestions(query); 1915 if ($(this).val().length <= 0) { 1916 $('.reset-text').hide(); 1917 } else { 1918 $('.reset-text').show(); 1919 } 1920 if ($('body').hasClass('search-results') || $('body').hasClass('search-no-results')) { 1921 $('.top_heading').css('z-index', '999'); 1922 1923 } 1924 // Cáºp nháºt URL sá» dụng domain hiá»n tại 1925 // updateURLParam("s", query); 1926 updateURLParams({ s: query, layout_search: layout }); 1927 1928 }); 1929 1930 $(".ajax-search-form .search-input").on("input", function(e) { 1931 e.preventDefault(); 1932 if ($(this).val().length > 0) { 1933 $('.search-container').addClass('searching'); 1934 $('.wrapper-icon-sticky').hide(); 1935 } else { 1936 $('.search-container').removeClass('searching'); 1937 $('.wrapper-icon-sticky').show(); 1938 } 1939 }); 1940 1941 // Hide suggestions when clicking outside 1942 $(document).on("click", function(e) { 1943 if (!$(e.target).closest(".search-input, .search-suggestions").length) { 1944 suggestionsContainer.hide(); 1945 $('.search-container').removeClass('searching'); 1946 } 1947 }); 1948 1949 // Handle selection of a search suggestion 1950 if (!$('body').hasClass('search-results')) { 1951 $(document).on("click", "#ajax-search-form-wd .submit,#ajax-search-form-wd .search-view-all", function() { 1952 if ($('.search-input').val().length > 0) { 1953 // Submit the form and redirect to the search results page 1954 $('#ajax-search-form-wd').submit(); 1955 $("#search-popup").removeClass("show"); 1956 1957 } else { 1958 alert('Please enter a search query'); 1959 } 1960 1961 1962 }); 1963 } 1964 1965 // Handle form submission for #ajax-search-form-wd 1966 $(document).on("click", "#ajax-search-form-wd .submit, #ajax-search-form-wd .search-view-all", function(e) { 1967 e.preventDefault(); // Prevent default form submission 1968 const type = 'all'; 1969 const layout = 'page'; 1970 query = $('#ajax-search-form-wd .search-input').val(); // Get value from search input 1971 if (query.length > 0) { 1972 loadSearchResults(query, type, layout, currentPage[type], type_active); 1973 } 1974 $('.search-container').removeClass('searching'); 1975 $("#search-popup").removeClass("show"); 1976 }); 1977 1978 // Handle form submission for .ajax-search-form (không ảnh hưá»ng Äến #ajax-search-form-wd) 1979 $(document).on("click", ".ajax-search-form .submit, .ajax-search-form .search-view-all", function(e) { 1980 e.preventDefault(); // Prevent default form submission 1981 const type = 'all'; 1982 const layout = 'page'; 1983 query = $(this).closest(".ajax-search-form").find(".search-input").val(); // Get value from search input 1984 $('.search-container').removeClass('searching'); 1985 $('.wrapper-icon-sticky').show(); 1986 $(".tab-link").removeClass("active"); 1987 $(".tab-content").removeClass("active"); 1988 $(".tab-link[data-tab='all']").addClass("active"); 1989 $(".tab-content.all").addClass("active"); 1990 suggestionsContainer.html("").hide(); 1991 updateURLParams({ s: query, layout_search: 'page' }); 1992 if (query.length > 0) { 1993 loadSearchResults(query, type, layout, currentPage[type], type_active); 1994 } else { 1995 alert('Please enter a search query'); 1996 } 1997 }); 1998 1999 // Handle page number click 2000 $(document).on("click", ".page-link.page-numbers", function(e) { 2001 e.preventDefault(); 2002 const page = $(this).text(); 2003 const type = $(this).data("type"); 2004 currentPage[type] = parseInt(page);
2005 const urlParams = new URLSearchParams(window.location.search); 2006 query = urlParams.get("s") || $(this).closest(".search-container").find(".search-input").val(); 2007 if (query) { 2008 loadSearchResults(query, type, layout, currentPage[type], type_active); 2009 } 2010 var class_loading = type == 'posts' ? 'blog-content' : 'list-products'; 2011 $(`.${type} .search-results .${class_loading}`).addClass('loading'); 2012 setTimeout(function() { 2013 $(`.${type} .search-results .${class_loading}`).removeClass('loading'); 2014 }, 2000); 2015 }); 2016 2017 2018 // Handle reset button click 2019 $('.reset-text').each(function() { 2020 $(this).on('click', function(e) { 2021 e.preventDefault(); 2022 $('.search-input').val(''); 2023 $('.all-result').html(''); 2024 localStorage.clear(); // Xóa toà n bá» cache 2025 $('.search-container').removeClass('searching'); 2026 $(this).hide(); 2027 // Cáºp nháºt URL khi reset truy vấn 2028 updateURLParams({ s: '', layout_search: layout }); 2029 2030 }); 2031 }); 2032 2033 // Handle tab switching 2034 $(".tab-link").on("click", function(e) { 2035 e.preventDefault(); 2036 $(".tab-link").removeClass("active"); 2037 $(".tab-content").removeClass("active"); 2038 $(this).addClass("active"); 2039 layout = 'page'; 2040 const type = $(this).attr("data-tab"); 2041 $(`.${type}`).addClass("active"); 2042 const urlParams = new URLSearchParams(window.location.search); 2043 query = urlParams.get("s") || $(this).closest(".search-container").find(".search-input").val(); 2044 const lastQuery = localStorage.getItem("lastQuery"); 2045 2046 // Reset currentPage[type] vá» 1 nếu query thay Äá»i 2047 if (query !== lastQuery) { 2048 currentPage[type] = 1; 2049 } 2050 if (query) { 2051 loadSearchResults(query, type, layout, currentPage[type], type_active); 2052 } 2053 }); 2054 2055 $(document).on("click", ".searh-result-all", function(e) { 2056 e.preventDefault(); 2057 const tabType = $(this).data("tab"); 2058 $(".tab-link").removeClass("active"); 2059 $(".tab-content").removeClass("active"); 2060 $(`.tab-link[data-tab="${tabType}"]`).addClass("active"); 2061 $(`.tab-content.${tabType}`).addClass("active"); 2062 $("#search-popup").removeClass("show"); 2063 suggestionsContainer.hide(); 2064 $('.search-container').removeClass('searching'); 2065 var co_layout = $(this).parent().parent().parent().parent().find(".layout_search").val(); 2066 layout = co_layout != undefined ? co_layout : 'page'; 2067 // Cáºp nháºt type_active và lưu và o localStorage 2068 type_active = tabType; 2069 localStorage.setItem("type_active", type_active); 2070 const urlParams = new URLSearchParams(window.location.search); 2071 query = urlParams.get("s") || $(this).closest(".search-container").find(".search-input").val(); 2072 // console.log(co_layout); 2073 if (co_layout == 'widget') { 2074 $('#ajax-search-form-wd').submit(); 2075 } else { 2076 if (query) { 2077 loadSearchResults(query, tabType, layout, currentPage[tabType], tabType); 2078 } 2079 } 2080 2081 }); 2082 // Show search popup 2083 $(document).on("click", '#open-search', function(event) { 2084 $("#search-popup").toggleClass("show"); 2085 $('.search-input').focus(); 2086 }); 2087 $(document).on("click", '#close-search', function(event) { 2088 $("#search-popup").removeClass("show") 2089 }); 2090 $(document).on("click", function(event) { 2091 if (!$(event.target).closest("#search-popup, #open-search").length) { 2092 $("#search-popup").removeClass("show"); 2093 } 2094 }); 2095 // Handle Load More button click 2096 $(document).on("click", ".load-more-btn", function(e) { 2097 e.preventDefault(); 2098 const type = $(this).data("type"); 2099 const nextPage = parseInt($(this).data("page")); 2100 currentPage[type] = nextPage; 2101
2102 const urlParams = new URLSearchParams(window.location.search); 2103 query = urlParams.get("s") || $(".search-input").val(); 2104 2105 if (query) { 2106 loadSearchResults(query, type, layout, currentPage[type], type_active); 2107 } 2108 2109 // Thêm hiá»u ứng loading 2110 // var class_loading = type == 'posts' ? 'blog-content' : 'list-products'; 2111 // $(`.${type} .search-results .${class_loading}`).addClass('loading'); 2112 $(this).addClass('loading'); 2113 setTimeout(function() { 2114 // $(`.${type} .search-results .${class_loading}`).removeClass('loading'); 2115 $(this).removeClass('loading'); 2116 }, 1000); 2117 2118 }); 2119 // Handle page reload (chỠáp dụng cho #ajax-search-form-wd) 2120 $(document).ready(function() { 2121 // Kiá»m tra xem các phần tá» có class #ajax-search-form-wd .submit hoặc #ajax-search-form-wd .search-view-all có tá»n tại không 2122 if ($('#ajax-search-form-wd .submit').length > 0 || $('#ajax-search-form-wd .search-view-all').length > 0) { 2123 // Get search query from URL 2124 const urlParams = new URLSearchParams(window.location.search); 2125 const query = urlParams.get("s"); 2126 // Lấy type_active từ localStorage 2127 const savedTypeActive = localStorage.getItem("type_active") || "all"; 2128 type_active = savedTypeActive; 2129 if (query) { 2130 // Call loadSearchResults with query from URL 2131 const layout = "page"; // Or get layout from URL if needed 2132 const currentPage = { all: 1, posts: 1, products: 1 }; 2133 2134 ["all", "posts", "products"].forEach(type => { 2135 loadSearchResults(query, type, layout, currentPage[type], type_active); 2136 }); 2137 } 2138 // KÃch hoạt tab Äã chá»n trưá»c Äó 2139 $(".tab-link").removeClass("active"); 2140 $(".tab-content").removeClass("active"); 2141 $(`.tab-link[data-tab="${type_active}"]`).addClass("active"); 2142 $(`.tab-content.${type_active}`).addClass("active"); 2143 } 2144 }); 2145 2146 function getWidgetsHeight() { 2147 var totalHeight = 0; 2148 2149 $(".site-header .widget").each(function() { 2150 if (!$(this).closest(".container").length) { 2151 totalHeight += $(this).outerHeight(); 2152 } 2153 }); 2154 2155 return totalHeight; 2156 } 2157 2158 function updateSearchPopupTop() { 2159 var searchPopup = $("#search-popup"); 2160
2161 if ($(window).width() <= 880) { 2162 searchPopup.css("top", "0px"); 2163 return; 2164 } 2165 2166 var widgetsHeight = getWidgetsHeight(); 2167 var adminBarHeight = $("#wpadminbar").outerHeight() || 0; 2168 var totalHeight = widgetsHeight + adminBarHeight; 2169 2170 searchPopup.css("top", totalHeight + "px"); 2171 } 2172 2173 updateSearchPopupTop(); 2174 $(window).resize(updateSearchPopupTop); 2175 2176 function saveToCache(key, data) { 2177 const cacheItem = { 2178 data: data, 2179 timestamp: new Date().getTime() // Lưu thá»i gian tạo cache 2180 }; 2181 localStorage.setItem(key, JSON.stringify(cacheItem)); 2182 } 2183 2184 function getFromCache(key, ttl = 60000) { // TTL mặc Äá»nh: 60 giây 2185 const cachedItem = localStorage.getItem(key); 2186 if (!cachedItem) return null; 2187 2188 const { data, timestamp } = JSON.parse(cachedItem); 2189 const now = new Date().getTime(); 2190 2191 // Kiá»m tra thá»i gian sá»ng cá»§a cache 2192 if (now - timestamp > ttl) { 2193 localStorage.removeItem(key); // Xóa cache nếu hết hạn 2194 return null; 2195 } 2196 2197 return data; 2198 } 2199 }, 2200 }; 2201 $(window).on('elementor/frontend/init', function() { 2202 elementorFrontend.hooks.addAction('frontend/element_ready/thim-theme-list.default', thim_thimpress.slick_slider); 2203 elementorFrontend.hooks.addAction('frontend/element_ready/thim-carousel-image.default', thim_thimpress.slick_slider); 2204 elementorFrontend.hooks.addAction('frontend/element_ready/thim-box-html.default', thim_thimpress.slick_slider); 2205 elementorFrontend.hooks.addAction('frontend/element_ready/thim-slide-review.default', thim_thimpress.slick_slider); 2206 }) 2207})(jQuery); 2208 2209function setScrollbarWidthOnResizeEnd() { 2210 document.documentElement.style.setProperty('--scrollbar-width', (window.innerWidth - document.documentElement.clientWidth) + "px"); 2211} 2212 2213setScrollbarWidthOnResizeEnd(); 2214 2215var timeOutScrollbarWidthOnResizeEnd; 2216 2217window.addEventListener("resize", function() { 2218 clearTimeout(timeOutScrollbarWidthOnResizeEnd); 2219 timeOutScrollbarWidthOnResizeEnd = setTimeout(setScrollbarWidthOnResizeEnd, 500); 2220}); 2221 2222document.addEventListener('DOMContentLoaded', () => { 2223 const blocks = document.querySelectorAll('[data-pagination]'); 2224 2225 blocks.forEach((block) => { 2226 const pagination = block.getAttribute('data-pagination'); 2227 const perPage = parseInt(block.getAttribute('data-per-page') || '0', 10); 2228 if (!pagination || pagination === 'none' || !perPage) return; 2229 2230 const allItems = Array.from(block.querySelectorAll('.changelog-info-item')); 2231 const versionLinks = Array.from(block.querySelectorAll('.changeloger-version-list-wrapper a')); 2232 let currentPage = 1; 2233 let loadMoreBtn; // Declare early to avoid hoisting issue 2234 2235 const updateDisplay = () => { 2236 const max = currentPage * perPage; 2237 allItems.forEach((el, idx) => { 2238 el.style.display = idx < max ? '' : 'none'; 2239 }); 2240 2241 if (pagination === 'load-more' && loadMoreBtn) { 2242 loadMoreBtn.style.display = max >= allItems.length ? 'none' : ''; 2243 } 2244 2245 versionLinks.forEach((link, idx) => { 2246 const li = link.closest('li'); 2247 if (li) li.style.display = idx < max ? '' : 'none'; 2248 }); 2249 }; 2250 2251 allItems.forEach((el) => (el.style.display = 'none')); 2252 updateDisplay(); 2253 2254 // Smooth scroll on sidebar link click 2255 versionLinks.forEach((link) => { 2256 link.addEventListener('click', (e) => { 2257 e.preventDefault(); 2258 const targetId = link.getAttribute('href').replace('#', ''); 2259 const target = block.querySelector(`#${CSS.escape(targetId)}`); 2260 if (target) { 2261 target.scrollIntoView({ behavior: 'smooth', block: 'start' }); 2262 } 2263 }); 2264 }); 2265 2266 if (pagination === 'load-more' && allItems.length > perPage) {
2267 loadMoreBtn = document.createElement('button'); 2268 loadMoreBtn.className = 'lp-changelog-load-more'; 2269 loadMoreBtn.innerText = block.getAttribute('data-load-more-text') || 'Load More'; 2270 loadMoreBtn.addEventListener('click', () => { 2271 currentPage++; 2272 updateDisplay(); 2273 }); 2274 block.appendChild(loadMoreBtn); 2275 } 2276 2277 if (pagination === 'infinite') { 2278 const sentinel = document.createElement('div'); 2279 sentinel.className = 'lp-changelog-sentinel'; 2280 sentinel.style.height = '1px'; 2281 block.appendChild(sentinel); 2282 2283 const observer = new IntersectionObserver( 2284 (entries) => { 2285 if (entries[0].isIntersecting && currentPage * perPage < allItems.length) { 2286 currentPage++; 2287 updateDisplay(); 2288 } 2289 }, 2290 { 2291 rootMargin: '200px', 2292 threshold: 0.1, 2293 }, 2294 ); 2295 observer.observe(sentinel); 2296 } 2297 }); 2298 // document.querySelectorAll('.animate-box').forEach(box => { 2299 // const targets = box.querySelectorAll('.childs'); 2300 // anime({ 2301 // targets: targets, 2302 // translateY: [0, 0], 2303 // perspective: [1200, 1200], 2304 // scale: [1.05, 1], 2305 // rotateX: [50, 0], 2306 // opacity: [0, 1], 2307 // duration: 600, 2308 // delay: anime.stagger(300, { start: 0 }), 2309 // easing: 'easeOutQuad' 2310 // }); 2311 // }); 2312});
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.