PageSourceSearch

https://chocostreet.in/public/assets/front-end/js/custom.js

js chocostreet.in collected 2026-10-07 05:59:42 UTC 79,815 bytes, 2,429 lines download raw bytes

1"use strict";
2
3(function ($) {
4    $(".profile-aside-btn").on("click", function () {
5        $("#shop-sidebar, .profile-aside-overlay").toggleClass("active");
6    });
7    $(".profile-aside-close-btn, .profile-aside-overlay").on(
8        "click",
9        function () {
10            $("#shop-sidebar, .profile-aside-overlay").removeClass("active");
11        }
12    );
13
14    $(".stopPropagation").on("click", function (e) {
15        e.stopPropagation();
16    });
17    $('[data-toggle="tooltip"]').tooltip();
18})(jQuery);
19
20$(document).ready(function () {
21    const stickyElement = $(".bottom-sticky_ele");
22    const offsetElement = $(".bottom-sticky_offset");
23
24    if (stickyElement.length !== 0) {
25        $(window).on("scroll", function () {
26            const elementOffset =
27                offsetElement.offset().top - $(window).height() / 1.2;
28            const scrollTop = $(window).scrollTop();
29
30            if (scrollTop >= elementOffset) {
31                stickyElement.addClass("stick");
32            } else {
33                stickyElement.removeClass("stick");
34            }
35        });
36    }
37
38    getReferralCodeFromURL();
39
40    /*==================================
41    19: Changing svg color
42    ====================================*/
43    $("img.svg").each(function () {
44        var $img = jQuery(this);
45        var imgID = $img.attr("id");
46        var imgClass = $img.attr("class");
47        var imgURL = $img.attr("src");
48
49        jQuery.get(
50            imgURL,
51            function (data) {
52                // Get the SVG tag, ignore the rest
53                var $svg = jQuery(data).find("svg");
54
55                // Add replaced image's ID to the new SVG
56                if (typeof imgID !== "undefined") {
57                    $svg = $svg.attr("id", imgID);
58                }
59                // Add replaced image's classes to the new SVG
60                if (typeof imgClass !== "undefined") {
61                    $svg = $svg.attr("class", imgClass + " replaced-svg");
62                }
63
64                // Remove any invalid XML tags as per http://validator.w3.org
65                $svg = $svg.removeAttr("xmlns:a");
66
67                // Check if the viewport is set, else we gonna set it if we can.
68                if (
69                    !$svg.attr("viewBox") &&
70                    $svg.attr("height") &&
71                    $svg.attr("width")
72                ) {
73                    $svg.attr(
74                        "viewBox",
75                        "0 0 " + $svg.attr("height") + " " + $svg.attr("width")
76                    );
77                }
78                // Replace image with new SVG
79                $img.replaceWith($svg);
80            },
81            "xml"
82        );
83    });
84});
85
86toastr.options = {
87    closeButton: false,
88    debug: false,
89    newestOnTop: false,
90    progressBar: false,
91    positionClass: "toast-top-right",
92    preventDuplicates: false,
93    onclick: null,
94    showDuration: "300",
95    hideDuration: "1000",
96    timeOut: "5000",
97    extendedTimeOut: "1000",
98    showEasing: "swing",
99    hideEasing: "linear",
100    showMethod: "fadeIn",
101    hideMethod: "fadeOut",
102};
103
104$(".get-currency-change-function").on("click", function () {
105    let code = $(this).data("code");
106    currencyChangeFunction(code);
107});
108
109function currencyChangeFunction(currency_code) {
110    $.ajaxSetup({
111        headers: {"X-CSRF-TOKEN": $('meta[name="_token"]').attr("content")},
112    });
113    $.ajax({
114        type: "POST",
115        url: $("#route-currency-change").data("url"),
116        data: {currency_code: currency_code},
117        success: function (data) {
118            toastr.success(data.message);
119            location.reload();
120        },
121    });
122}
123
124$(".change-language").on("click", function () {
125    $.ajaxSetup({
126        headers: {
127            "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
128        },
129    });
130    $.ajax({
131        type: "POST",
132        url: $(this).data("action"),
133        data: {
134            language_code: $(this).data("language-code"),
135        },
136        success: function (data) {
137            toastr.success(data.message);
138            location.reload();
139        },
140    });
141});
142
143function getReferralCodeFromURL() {
144    let getAuthStatus = $("#is-customer-auth-active").data("value");
145    if (getAuthStatus == 0) {
146        const currentUrl = new URL(window.location.href);
147        const referralCodeParameter = new URLSearchParams(
148            currentUrl.search
149        ).get("referral_code");
150        if (referralCodeParameter) {
151            let referralCodeInput = $("#referral_code");
152            if ($("#is-request-customer-auth-sign-up").data("value"))
153                console.log(referralCodeInput.length);
154            if (referralCodeInput.length) {
155                referralCodeInput.val(referralCodeParameter);
156            } else {
157                let redirectLink = $("#route-customer-auth-sign-up").data(
158                    "url"
159                );
160                window.location.href =
161                    redirectLink + "?referral_code=" + referralCodeParameter;
162            }
163        }
164    }
165}
166
167$(".web-announcement-slideUp").on("click", function () {
168    $("#announcement").slideUp(300);
169});
170
171$(".category-menu-toggle-btn").on("click", function () {
172    $(".megamenu-wrap").toggleClass("show");
173});
174
175$(".navbar-tool-icon-box").on("click", function () {
176    $(".megamenu-wrap").removeClass("show");
177});
178
179$(window).on("scroll", function () {
180    $(".megamenu-wrap").removeClass("show");
181});
182
183$(".close-search-form-mobile").on("click", function () {
184    $(".search-form-mobile").removeClass("active");
185});
186$(".open-search-form-mobile").on("click", function () {
187    $(".search-form-mobile").addClass("active");
188});
189
190$(".get-view-by-onclick").on("click", function () {
191    location.href = $(this).data("link");
192});
193
194$(".get-login-recaptcha-verify").on("click", function () {
195    let url = $(this).data("link");
196    customerLoginRecaptcha(url);
197});
198
199function customerLoginRecaptcha(url) {
200    url =
201        url +
202        "/" +
203        Math.random() +
204        "?captcha_session_id=default_recaptcha_id_customer_login";
205    document.getElementById("customer_login_recaptcha_id").src = url;
206}
207
208$(".get-regi-recaptcha-verify").on("click", function () {
209    let url = $(this).data("link");
210    customerRegiRecaptcha(url);
211});
212
213function customerRegiRecaptcha(url) {
214    url =
215        url +
216        "/" +
217        Math.random() +
218        "?captcha_session_id=default_recaptcha_id_customer_regi";
219    document.getElementById("default_recaptcha_id").src = url;
220}
221
222$(".get-vendor-regi-recaptcha-verify").on("click", function () {
223    let genUrl = $(this).data("link");
224    genUrl = genUrl.replace(":dummy-id", Math.random());
225    vendorRegiRecaptcha(genUrl);
226});
227
228function vendorRegiRecaptcha(url) {
229    let genUrl = url + "?captcha_session_id=default_recaptcha_id_seller_regi";
230    document.getElementById("default_recaptcha_id").src = genUrl;
231    console.log("url: " + genUrl);
232}
233
234$("#inputChecked").change(function () {
235    if ($(this).is(":checked")) {
236        $("#sign-up").removeAttr("disabled");
237    } else {
238        $("#sign-up").attr("disabled", "disabled");
239    }
240});
241
242$(".submitVerifyForm").on('click', function () {
243    let formElement = $(this).closest('form');
244    formElement.attr('action', formElement.data('verify'));
245    $(this).closest('form').submit();
246});
247
248$(".resendVerifyForm").on('click', function () {
249    let formElement = $(this).closest('form');
250    formElement.attr('action', formElement.data('resend'));
251    $(this).closest('form').submit();
252});
253
254// $(".resendVerifyForm").on('click', function () {
255//     $("input.otp-field").val("");
256//     $.ajaxSetup({
257//         headers: {
258//             "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
259//         },
260//     });
261//     $.ajax({
262//         url: $(this).data("url"),
263//         method: "POST",
264//         dataType: "json",
265//         data: {
266//             user_id: $(this).data("userid"),
267//         },
268//         beforeSend: function () {
269//             $("#loading").show();
270//         },
271//         success: function (data) {
272//             if (data.status == 1) {
273//                 let new_counter = $(".verifyCounter");
274//                 let new_seconds = data.new_time;
275
276//                 function new_tick() {
277//                     let minutes = Math.floor(new_seconds / 60);
278//                     let seconds = new_seconds % 60;
279//                     new_seconds--;
280//                     new_counter.html(
281//                         minutes +
282//                             ":" +
283//                             (seconds < 10 ? "0" : "") +
284//                             String(seconds)
285//                     );
286//                     if (new_seconds > 0) {
287//                         setTimeout(new_tick, 1000);
288//                         $(".resend-otp-button").attr("disabled", true);
289//                         $(".resend_otp_custom").slideDown();
290//                     } else {
291//                         $(".resend-otp-button").removeAttr("disabled");
292//                         new_counter.html("0:00");
293//                         $(".resend_otp_custom").slideUp();
294//                     }
295//                 }
296
297//                 new_tick();
298
299//                 toastr.success($("#message-otp-sent-again").data("text"));
300//             } else {
301//                 toastr.error($("#message-wait-for-new-code").data("text"));
302//             }
303//         },
304//         complete: function () {
305//             $("#loading").hide();
306//         },
307//     });
308// });
309
310$("#customerOtpVerify").click(function () {
311    $("input.otp-field").val("");
312    $.ajaxSetup({
313        headers: {
314            "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
315        },
316    });
317    $.ajax({
318        url: $(this).data("url"),
319        method: "POST",
320        dataType: "json",
321        data: {
322            identity: $(this).data("identity"),
323        },
324        beforeSend: function () {
325            $("#loading").addClass("d-grid");
326        },
327        success: function (data) {
328            if (data.status == 1) {
329                let newCounter = $(".verifyCounter");
330                let newSeconds = data.new_time;
331
332                function new_tick() {
333                    let minutes = Math.floor(newSeconds / 60);
334                    let seconds = newSeconds % 60;
335                    newSeconds--;
336                    newCounter.html(
337                        minutes +
338                        ":" +
339                        (seconds < 10 ? "0" : "") +
340                        String(seconds)
341                    );
342                    if (newSeconds > 0) {
343                        setTimeout(new_tick, 1000);
344                        $(".resend-otp-button").attr("disabled", true);
345                        $(".resend_otp_custom").slideDown();
346                    } else {
347                        $(".resend-otp-button").removeAttr("disabled");
348                        newCounter.html("0:00");
349                        $(".resend_otp_custom").slideUp();
350                    }
351                }
352
353                new_tick();
354                toastr.success(data.message);
355            } else {
356                toastr.error(data.message);
357            }
358        },
359        complete: function () {
360            $("#loading").removeClass("d-grid");
361        },
362    });
363});
364
365$(".get-contact-recaptcha-verify").on("click", function () {
366    let url = $(this).data("link");
367    url = url + "/" + Math.random();
368    document.getElementById("default_recaptcha_id").src = url;
369});
370
371$(".check-password-match").on("change", function () {
372    checkPasswordMatch();
373});
374
375function checkPasswordMatch() {
376    let password = $("#password").val();
377    let confirmPassword = $("#confirm_password").val();
378    let messageElement = $("#message");
379    messageElement.removeAttr("style");
380    messageElement.html("");
381    if (confirmPassword === "") {
382        messageElement.attr("style", "color:black");
383        messageElement.html($("#message-please-retype-password").data("text"));
384    } else if (password === "") {
385        messageElement.removeAttr("style");
386        messageElement.html("");
387    } else if (password !== confirmPassword) {
388        messageElement.html($("#message-password-not-match").data("text"));
389        messageElement.attr("style", "color:red");
390    } else if (confirmPassword.length <= 6) {
391        messageElement.html($("#message-password-need-longest").data("text"));
392        messageElement.attr("style", "color:red");
393    } else {
394        messageElement.html($("#message-password-match").data("text"));
395        messageElement.attr("style", "color:green");
396    }
397}
398
399$(document).ready(function () {
400    $("#confirm_password").keyup(checkPasswordMatch);
401});
402
403function accountImageReadURL(input) {
404    if (input.files && input.files[0]) {
405        var reader = new FileReader();
406        reader.onload = function (e) {
407            $("#blah").attr("src", e.target.result);
408        };
409        reader.readAsDataURL(input.files[0]);
410    }
411}
412
413$("#files").change(function () {
414    accountImageReadURL(this);
415});
416
417$(".update-account-info").on("click", function () {
418    $("#profile_form").submit();
419});
420
421$(".call-route-alert").on("click", function () {
422    let route = $(this).data("route");
423    let message = $(this).data("message");
424    route_alert(route, message);
425});
426
427$(".filter-ico-button").on("click", function () {
428    $(".__shop-page-sidebar").toggleClass("active");
429});
430
431$(".shop-page-sidebar-close").on("click", function () {
432    $(".__shop-page-sidebar").removeClass("active");
433});
434
435$(".action-sort-shop-products-by-data").on("change", function () {
436    sortShopProductsByData($(this).val());
437});
438
439
440$("#shop-view-chat-form").on("submit", function (e) {
441    e.preventDefault();
442    $.ajaxSetup({
443        headers: {
444            "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
445        },
446    });
447    $.ajax({
448        type: "post",
449        url: $("#route-messages-store").data("url"),
450        data: $("#shop-view-chat-form").serialize(),
451        success: function (response) {
452            toastr.success($("#message-send-successfully").data("text"), {
453                CloseButton: true,
454                ProgressBar: true,
455            });
456            $("#shop-view-chat-form").trigger("reset");
457        },
458    });
459});
460
461$(".menu--caret").on("click", function (e) {
462    var element = $(this).closest(".menu--caret-accordion");
463    if (element.hasClass("open")) {
464        element.removeClass("open");
465        element.find(".menu--caret-accordion").removeClass("open");
466        element.find(".card-body").slideUp(300, "swing");
467    } else {
468        element.addClass("open");
469        element.children(".card-body").slideDown(300, "swing");
470        element
471            .siblings(".menu--caret-accordion")
472            .children(".card-body")
473            .slideUp(300, "swing");
474        element.siblings(".menu--caret-accordion").removeClass("open");
475        element
476            .siblings(".menu--caret-accordion")
477            .find(".menu--caret-accordion")
478            .removeClass("open");
479        element
480            .siblings(".menu--caret-accordion")
481            .find(".card-body")
482            .slideUp(300, "swing");
483    }
484});
485
486$("#seller-chat-form").on("submit", function (e) {
487    e.preventDefault();
488    $.ajaxSetup({
489        headers: {
490            "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
491        },
492    });
493    $.ajax({
494        type: "post",
495        url: $("#route-messages-store").data("url"),
496        data: $(this).serialize(),
497        success: function (response) {
498            toastr.success($("#message-send-successfully").data("text"), {
499                CloseButton: true,
500                ProgressBar: true,
501            });
502            $("#seller-chat-form").trigger("reset");
503        },
504    });
505});
506
507$("#deliveryman-chat-form").on("submit", function (e) {
508    e.preventDefault();
509    $.ajaxSetup({
510        headers: {
511            "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
512        },
513    });
514    $.ajax({
515        type: "post",
516        url: $("#route-messages-store").data("url"),
517        data: $(this).serialize(),
518        success: function (response) {
519            toastr.success($("#message-send-successfully").data("text"), {
520                CloseButton: true,
521                ProgressBar: true,
522            });
523            $("#deliveryman-chat-form").trigger("reset");
524        },
525    });
526});
527
528$(".rating-label-wrap input[type=range]").on("change", function () {
529    let ratingVal = $(this).val();
530    let ratingContent = $(".rating_content_delivery_man");
531    let rattingTextAreaClass = $(".text-area-class");
532    let rattingMessages = $("#message-ratingContent");
533    let htmlDir = $("#system-session-direction").data("value");
534    let position = "left";
535    if (htmlDir === "rtl") {
536        position = "right";
537    }
538    switch (ratingVal) {
539        case "1":
540            ratingContent
541                .text(rattingMessages.data("poor"))
542                .css(position, "5px");
543            rattingTextAreaClass.attr("placeholder", "");
544            break;
545        case "2":
546            ratingContent
547                .text(rattingMessages.data("average"))
548                .css(position, "36px");
549            rattingTextAreaClass.attr("placeholder", "");
550            break;
551        case "3":
552            ratingContent
553                .text(rattingMessages.data("good"))
554                .css(position, "85px");
555            rattingTextAreaClass.attr(
556                "placeholder",
557                rattingMessages.data("good-message")
558            );
559            break;
560        case "4":
561            ratingContent
562                .text(rattingMessages.data("good2"))
563                .css(position, "112px");
564            rattingTextAreaClass.attr(
565                "placeholder",
566                rattingMessages.data("good2-message")
567            );
568            break;
569        case "5":
570            ratingContent
571                .text(rattingMessages.data("excellent"))
572                .css(position, "155px");
573            rattingTextAreaClass.attr(
574                "placeholder",
575                rattingMessages.data("excellent-message")
576            );
577            break;
578        default:
579            break;
580    }
581});
582
583$("#add_fund_to_wallet_form_btn").on("click", function () {
584    if (!$("input[name='payment_method']:checked").val()) {
585        toastr.error($("#message-select-payment-method").data("text"));
586    }
587});
588
589$("#add-fund-amount-input").on("keyup", function () {
590    if (!isNaN($(this).val()) && $(this).val() < 0) {
591        $(this).val(0);
592        toastr.error($("#message-cannot-input-minus-value").data("text"));
593    }
594});
595
596$(".click-to-copy-coupon").on("click", function () {
597    let copiedText = $(this).data("value");
598    navigator.clipboard
599        .writeText(copiedText)
600        .then(function () {
601            toastr.success($("#message-successfully-copied").data("text"));
602        })
603        .catch(function (error) {
604            toastr.error($("#message-copied-failed").data("text"));
605        });
606});
607$(".click-to-copy-data-value").on("click", function () {
608    let copiedText = $(this).data("value");
609    let tempTextarea = $("<textarea>");
610    $("body").append(tempTextarea);
611    tempTextarea.val(copiedText).select();
612    document.execCommand("copy");
613    tempTextarea.remove();
614    toastr.success($("#message-successfully-copied").data("text"));
615});
616
617$("#customer-login-form").on("submit", function (e) {
618    var recaptchaContainer = document.getElementById('recaptcha_element');
619    if (recaptchaContainer && recaptchaContainer.innerHTML.trim()?.toString() !== "") {
620        var response = grecaptcha.getResponse();
621        if (response.length === 0) {
622            e.preventDefault();
623            toastr.error($("#message-please-check-recaptcha").data("text"));
624        }
625    }
626});
627
628$("#customer-register-form").on("submit", function (e) {
629    e.preventDefault();
630    $.ajax({
631        type: "POST",
632        url: $(this).data("action"),
633        data: $(this).serialize(),
634        beforeSend: function () {
635            $("#loading").addClass("d-grid");
636        },
637        success: function (response) {
638            if (response.errors) {
639                for (let index = 0; index < response.errors.length; index++) {
640                    toastr.error(response.errors[index].message);
641                }
642            } else if (response.error) {
643                toastr.error(response.error);
644            } else if (response.status === 1) {
645                toastr.success(response.message);
646                window.location.href = response.redirect_url;
647            } else if (response.redirect_url !== "") {
648                window.location.href = response.redirect_url;
649            }
650        },
651        error: function () {
652        },
653        complete: function () {
654            $("#loading").removeClass("d-grid");
655        },
656    });
657});
658
659$(".remove-img-row-by-key").on("click", function () {
660    let reviewId = $(this).data("review-id");
661    let getPhoto = $(this).data("photo");
662    let key = $(this).data("key");
663
664    $.ajaxSetup({
665        headers: {"X-CSRF-TOKEN": $('meta[name="_token"]').attr("content")},
666    });
667    $.ajax({
668        type: "POST",
669        url: $(this).data("route"),
670        data: {
671            id: reviewId,
672            name: getPhoto,
673        },
674        success: function (response) {
675            if (response.message) {
676                toastr.success(response.message);
677            }
678            $(".img_row" + key).remove();
679        },
680    });
681});
682
683$(".customer-account-delete-by-route").on("click", function () {
684    $("#shop-sidebar").removeClass("active");
685    $(".profile-aside-overlay ").removeClass("active");
686    let route = $(this).data("route");
687    let message = $(this).data("message");
688    route_alert(route, message);
689});
690
691$(".show-instant-image").on("click", function () {
692    let link = $(this).data("link");
693    showInstantImage(link);
694});
695
696function showInstantImage(link) {
697    $("#attachment-view").attr("src", link);
698    $("#show-modal-view").modal("toggle");
699}
700
701function couponCode() {
702    $("#apply-coupon-code").on("click", function () {
703        $.ajaxSetup({
704            headers: {
705                "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
706            },
707        });
708        $.ajax({
709            type: "POST",
710            url: $("#route-coupon-apply").data("url"),
711            data: $("#coupon-code-ajax").serializeArray(),
712            success: function (data) {
713                let messages = data.messages;
714                if (data.status) {
715                    messages.forEach(function (message, index) {
716                        toastr.success(message, index, {
717                            CloseButton: true,
718                            ProgressBar: true,
719                        });
720                    });
721                } else {
722                    messages.forEach(function (message, index) {
723                        toastr.error(message, index, {
724                            CloseButton: true,
725                            ProgressBar: true,
726                        });
727                    });
728                }
729                setTimeout(function () {
730                    location.reload();
731                }, 2000);
732            },
733        });
734    });
735}
736
737couponCode();
738
739$(".password-toggle-btn").on("click", function () {
740    let checkbox = $(this).find("input[type=checkbox]");
741    let eyeIcon = $(this).find("i");
742    checkbox.change(function () {
743        if (checkbox.is(":checked")) {
744            eyeIcon.removeClass("tio-hidden").addClass("tio-invisible");
745        } else {
746            eyeIcon.removeClass("tio-invisible").addClass("tio-hidden");
747        }
748    });
749});
750
751$(".filter-show-btn").on("click", function () {
752    $("#shop-sidebar").toggleClass("show active");
753});
754
755$(".cz-sidebar-header .close").on("click", function () {
756    $("#shop-sidebar").removeClass("show active");
757});
758
759$(".remove-address-by-modal").on("click", function () {
760    let link = $(this).data("link");
761    $("#remove-address-link").attr("href", link);
762    $("#remove-address").modal("show");
763});
764
765var backgroundImage = $("[data-bg-img]");
766backgroundImage
767    .css("background-image", function () {
768        return 'url("' + $(this).data("bg-img") + '")';
769    })
770    .removeAttr("data-bg-img")
771    .addClass("bg-img");
772
773$(".get-order-again-function").on("click", function () {
774    let orderId = $(this).data("id");
775    order_again(orderId);
776});
777
778function order_again(orderId) {
779    $.ajaxSetup({
780        headers: {
781            "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
782        },
783    });
784    $.ajax({
785        type: "POST",
786        url: $("#route-cart-order-again").data("url"),
787        data: {order_id: orderId},
788        beforeSend: function () {
789            $("#loading").show();
790        },
791        success: function (response) {
792            if (response.status === 1) {
793                updateNavCart();
794                toastr.success(response.message, {
795                    CloseButton: true,
796                    ProgressBar: true,
797                    timeOut: 3000,
798                });
799                location.href = response.redirect_url;
800                return false;
801            } else if (response.status === 0) {
802                toastr.warning(response.message, {
803                    CloseButton: true,
804                    ProgressBar: true,
805                    timeOut: 2000,
806                });
807                return false;
808            }
809        },
810        complete: function () {
811            $("#loading").hide();
812        },
813    });
814}
815
816$(".search-bar-input-mobile").keyup(function () {
817    $(".search-card").css("display", "block");
818    let name = $(".search-bar-input-mobile").val();
819    if (name.length > 0) {
820        $.get({
821            url: $("#route-searched-products").data("url"),
822            dataType: "json",
823            data: {
824                name: name,
825            },
826            beforeSend: function () {
827                $("#loading").show();
828            },
829            success: function (data) {
830                $(".search-result-box").empty().html(data.result);
831                $(".search-result-product").on("mouseover", function () {
832                    $(".search-bar-input-mobile").val(
833                        $(this).data("product-name")
834                    );
835                });
836            },
837            complete: function () {
838                $("#loading").hide();
839            },
840        });
841    } else {
842        $(".search-result-box").empty();
843    }
844});
845
846$(".search-bar-input").keyup(function () {
847    let searchBarInputElement = $(".search-bar-input");
848    $(".search-card").css("display", "block");
849    let name = searchBarInputElement.val();
850    searchBarInputElement.data("given-value", name);
851    if (name.length > 0) {
852        $.get({
853            url: $("#route-searched-products").data("url"),
854            dataType: "json",
855            data: {
856                name: name,
857            },
858            beforeSend: function () {
859                $("#loading").show();
860            },
861            success: function (data) {
862                $(".search-result-box").empty().html(data.result);
863                $(".search-result-product").on("mouseover", function () {
864                    searchBarInputElement.val($(this).data("product-name"));
865                });
866                $(".search-result-product").on("mouseleave", function () {
867                    searchBarInputElement.val(
868                        searchBarInputElement.data("given-value")
869                    );
870                });
871            },
872            complete: function () {
873                $("#loading").hide();
874            },
875        });
876    } else {
877        $(".search-result-box").empty();
878    }
879});
880
881$(".clickable").click(function () {
882    window.location = $(this).find("a").attr("href");
883    return false;
884});
885
886function addWishlist(product_id, modalId) {
887    $.ajaxSetup({
888        headers: {"X-CSRF-TOKEN": $('meta[name="_token"]').attr("content")},
889    });
890    $.ajax({
891        url: $("#route-store-wishlist").data("url"),
892        method: "POST",
893        data: {product_id: product_id},
894        success: function (data) {
895            if (data.value == 1) {
896                $(".countWishlist").html(data.count);
897                $(".countWishlist-" + product_id).text(data.product_count);
898                $(".tooltip").html("");
899                $(`.wishlist_icon_${product_id}`)
900                    .removeClass("fa fa-heart-o")
901                    .addClass("fa fa-heart");
902                $(".wishlist-tooltip").find(".remove").hide();
903                $(".wishlist-tooltip").find(".add").show();
904                $(".wishlist-tooltip").show();
905                const timer = setTimeout(() => {
906                    $(".wishlist-tooltip").hide();
907                }, 2000);
908                $(`#${modalId}`).modal("show");
909                return () => clearTimeout(timer);
910            } else if (data.value == 2) {
911                $(".wishlist-tooltip").find(".remove").show();
912                $(".wishlist-tooltip").find(".add").hide();
913                $(".wishlist-tooltip").show();
914                const timer = setTimeout(() => {
915                    $(".wishlist-tooltip").hide();
916                }, 2000);
917                $(".countWishlist").html(data.count);
918                $(".countWishlist-" + product_id).text(data.product_count);
919                $(`.wishlist_icon_${product_id}`)
920                    .removeClass("fa fa-heart")
921                    .addClass("fa fa-heart-o");
922                return () => clearTimeout(timer);
923            } else {
924                $("#login-alert-modal").modal("show");
925            }
926        },
927    });
928}
929
930$(".function-remove-wishList").on("click", function () {
931    let productId = $(this).data("id");
932    let modalId = $(this).data("modal");
933    removeWishlist(productId, modalId);
934});
935
936function removeWishlist(productId, modalId) {
937    $.ajaxSetup({
938        headers: {
939            "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
940        },
941    });
942    $.ajax({
943        url: $("#route-delete-wishlist").data("url"),
944        method: "POST",
945        data: {id: productId},
946        beforeSend: function () {
947            $("#loading").show();
948        },
949        success: function (data) {
950            $(`#${modalId}`).modal("show");
951            let countWishlistElement = $(".countWishlist");
952            let messageNoDataFound = $("#message-no-data-found").data("text");
953            countWishlistElement.html(
954                parseInt(countWishlistElement.html()) - 1
955            );
956            $("#row_id" + productId).hide();
957            $(".tooltip").html("");
958            if (parseInt(countWishlistElement.html()) % 15 === 0) {
959                let wishlistPaginatedPage = $("#wishlist_paginated_page");
960                if (wishlistPaginatedPage.val() == 1) {
961                    $("#set-wish-list")
962                        .empty()
963                        .append(
964                            `<h6 class="text-muted text-center">` +
965                            messageNoDataFound +
966                            `</h6>`
967                        );
968                } else {
969                    let pageValue = wishlistPaginatedPage.val();
970                    window.location.href =
971                        $("#route-wishlists").data("url") +
972                        "?page=" +
973                        (pageValue - 1);
974                }
975            }
976        },
977        complete: function () {
978            $("#loading").hide();
979        },
980    });
981}
982
983function renderQuickViewFunction() {
984    $(".action-product-quick-view").on("click", function () {
985        let productId = $(this).data("product-id");
986        productQuickView(productId);
987    });
988}
989
990$(window).on("load", function () {
991    renderQuickViewFunction();
992});
993
994function productQuickView(product_id) {
995    $.get({
996        url: $("#route-quick-view").data("url"),
997        dataType: "json",
998        data: {
999            product_id: product_id,
1000        },
1001        beforeSend: function () {
1002            $("#loading").show();
1003        },
1004        success: function (data) {
1005            $("#quick-view-modal").empty().html(data.view);
1006            renderOwlCarouselSilder();
1007            commonFunctionalityForProductView();
1008            $("#quick-view").modal("show");
1009        },
1010        complete: function () {
1011            $("#loading").hide();
1012        },
1013    });
1014}
1015
1016$(".action-hide-billing-address").on("click", function () {
1017    hideBillingAddressFunction();
1018});
1019
1020function hideBillingAddressFunction() {
1021    let checkSameAsShipping = $("#same_as_shipping_address").is(":checked");
1022    console.log(checkSameAsShipping);
1023    if (checkSameAsShipping) {
1024        $("#hide_billing_address").hide();
1025    } else {
1026        $("#hide_billing_address").show();
1027    }
1028}
1029
1030$(".action-billing-address-hide").on("click", function () {
1031    billingAddressFunction();
1032});
1033
1034function billingAddressFunction() {
1035    $("#bh-0").prop("checked", true);
1036    $("#billing_model").collapse();
1037}
1038
1039$(".minimum-order-amount-message").on("click", function () {
1040    toastr.error($(this).data("title"), {
1041        CloseButton: true,
1042        ProgressBar: true,
1043    });
1044});
1045
1046function productQuickViewFunctionalityInitialize() {
1047    cartQuantityInitialize();
1048    console.log("Called from 875");
1049    getVariantPrice();
1050    $("#add-to-cart-form input").on("change", function () {
1051        console.log("Called from 878");
1052        getVariantPrice();
1053    });
1054
1055    $(document).ready(function () {
1056        $('[data-toggle="tooltip"]').tooltip();
1057        $('[data-toggle="popover"]').popover();
1058    });
1059
1060    $(".quick-view-preview-image-by-color").on("click", function () {
1061        let id = $("#preview-img" + $(this).data("key"));
1062        $(id).click();
1063    });
1064}
1065
1066function addToCart(form_id = "add-to-cart-form", redirect_to_checkout = false, url = null) {
1067    if (checkAddToCartValidity()) {
1068        $.ajaxSetup({
1069            headers: {
1070                "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
1071            },
1072        });
1073
1074        let existCartItem = $('.in_cart_key[name="key"]').val();
1075        let redirectToCheckoutValue = redirect_to_checkout.toString();
1076
1077        let formActionUrl = $("#route-cart-add").data("url");
1078        if (existCartItem !== "" && !redirect_to_checkout) {
1079            formActionUrl = $("#route-cart-updateQuantity-guest").data("url");
1080        }
1081
1082        $.post({
1083            url: formActionUrl,
1084            data: $("#" + form_id)
1085                .serializeArray()
1086                .concat({
1087                    name: "buy_now",
1088                    value: redirect_to_checkout ? 1 : 0,
1089                }),
1090            beforeSend: function () {
1091                $("#loading").show();
1092            },
1093            success: function (response) {
1094                console.log(response);
1095                if (response.status === 2) {
1096                    if (redirectToCheckoutValue !== "false") {
1097                        $("#buyNowModal-body").html(
1098                            response.shippingMethodHtmlView
1099                        );
1100                        $("#quick-view").modal("hide");
1101                        $("#buyNowModal").modal("show");
1102                        return false;
1103                    }
1104                }
1105                if (response.status == 1) {
1106                    updateNavCart();
1107                    toastr.success(response.message, {
1108                        CloseButton: true,
1109                        ProgressBar: true,
1110                    });
1111
1112                    let actionAddToCartBtn = $(".action-add-to-cart-form");
1113                    $('.in_cart_key[name="key"]').val(response.in_cart_key);
1114                    actionAddToCartBtn.html(
1115                        actionAddToCartBtn.data("update-text")
1116                    );
1117
1118                    $(".call-when-done").click();
1119
1120                    if (
1121                        redirectToCheckoutValue === "true" &&
1122                        response.redirect_to_url
1123                    ) {
1124                        setTimeout(function () {
1125                            location.href = response.redirect_to_url;
1126                        }, 100);
1127                    } else if (redirectToCheckoutValue === "true") {
1128                        setTimeout(function () {
1129                            location.href = url;
1130                        }, 100);
1131                    }
1132
1133                    return false;
1134                } else if (response.status == 0) {
1135                    if (redirectToCheckoutValue !== "false" || !redirect_to_checkout) {
1136                        $("#out-of-stock-modal-message").html(response.message);
1137                        $("#out-of-stock-modal").modal("show");
1138                        return false;
1139                    }
1140                }
1141            },
1142            complete: function () {
1143                $("#loading").hide();
1144            },
1145        });
1146    } else {
1147        Swal.fire({
1148            type: "info",
1149            title: "Cart",
1150            text: $("#message-please-choose-all-options").data("text"),
1151        });
1152    }
1153}
1154
1155function commonFunctionalityForProductView() {
1156    $(".action-buy-now-this-product").on("click", function () {
1157        let redirectStatus = $(this).data("auth-status").toString();
1158        let url = $(this).data("route");
1159        addToCart("add-to-cart-form", redirectStatus, url);
1160        if (redirectStatus === "false") {
1161            setTimeout(function () {
1162                location.href = url;
1163            }, 100);
1164        }
1165    });
1166
1167    $(".action-add-to-cart-form").on("click", function () {
1168        addToCart("add-to-cart-form");
1169    });
1170
1171    $(".product-action-add-wishlist").on("click", function () {
1172        let id = $(this).data("product-id");
1173        addWishlist(id);
1174    });
1175
1176    $(".product-restock-request-button").on("click", function () {
1177        let isLoggedIn = $(this).data('auth')?.toString();
1178        if (isLoggedIn === 'true' || isLoggedIn === '1') {
1179            let parentElement = $(this).closest('.product-cart-option-container');
1180            let productCartForm = parentElement.find('.addToCartDynamicForm');
1181            let getFrom = $(this).data('form')?.toString();
1182
1183            if (productCartForm?.length <= 0 && getFrom && getFrom !== '') {
1184                productCartForm = $(getFrom);
1185            }
1186            getRequestForProductRestock(productCartForm);
1187        } else {
1188            $("#login-alert-modal").modal("show");
1189        }
1190    });
1191
1192    function getRequestForProductRestock(formElement) {
1193        let button = $(".product-restock-request-button");
1194        $.ajaxSetup({
1195            headers: {
1196                "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
1197            },
1198        });
1199        $.ajax({
1200            url: $("#route-product-restock-request").data("url"),
1201            type: "POST",
1202            data: formElement.serializeArray(),
1203            beforeSend: function () {
1204                $("#loading").show();
1205            },
1206            success: function (response) {
1207                responseManager(response)
1208                button.attr('disabled', true);
1209                button.text(button.data('requested'));
1210
1211                try {
1212                    startFCM([response?.fcm_topic]);
1213                } catch (e) {
1214                    console.log(e)
1215                }
1216            },
1217            complete: function () {
1218                $("#loading").hide();
1219            },
1220        });
1221    }
1222}
1223
1224commonFunctionalityForProductView();
1225
1226function checkoutFromCartList() {
1227    let orderNote = $("#order_note").val();
1228    $.post({
1229        url: $("#route-order-note").data("url"),
1230        data: {
1231            _token: $('meta[name="_token"]').attr("content"),
1232            order_note: orderNote,
1233        },
1234        beforeSend: function () {
1235            $("#loading").show();
1236        },
1237        success: function (response) {
1238            if (response.status === 0) {
1239                response.message.map(function (message) {
1240                    toastr.error(message);
1241                });
1242            } else {
1243                location.href = response.redirect
1244                    ? response.redirect
1245                    : $("#route-checkout-details").data("url");
1246            }
1247        },
1248        complete: function () {
1249            $("#loading").hide();
1250        },
1251    });
1252}
1253
1254function orderSummaryStickyFunction() {
1255    try {
1256        const stickyElement = $(".bottom-sticky3");
1257        const offsetElement = $(".__cart-total_sticky .proceed_to_next_button");
1258
1259        const elementOffset = offsetElement.offset().top;
1260        const scrollTop = $(window).scrollTop();
1261        if (scrollTop >= elementOffset - $(window).height() + 50) {
1262            stickyElement.addClass("stick");
1263            $(".floating-btn-grp").removeClass("style-2");
1264        } else {
1265            stickyElement.removeClass("stick");
1266            $(".floating-btn-grp").addClass("style-2");
1267        }
1268    } catch (e) {
1269    }
1270}
1271
1272$(window).on('resize', orderSummaryStickyFunction)
1273$(window).on('scroll', orderSummaryStickyFunction)
1274
1275function cartListQuantityUpdateInit() {
1276    $(".action-update-cart-quantity").on("click", function () {
1277        let cartId = $(this).data("cart-id");
1278        let productId = $(this).data("product-id");
1279        let action = $(this).data("action");
1280        let event = $(this).data("event");
1281        updateCartQuantity(cartId, productId, action, event);
1282    });
1283
1284    $(".action-update-cart-quantity-list").on("click", function () {
1285        let minimumOrderQuantity = $(this).data("minimum-order");
1286        let key = $(this).data("cart-id");
1287        let increment = $(this).data("increment");
1288        let event = $(this).data("event");
1289        updateCartQuantityList(minimumOrderQuantity, key, increment, event);
1290    });
1291
1292    $(".action-change-update-cart-quantity-list").on("change", function () {
1293        let minimumOrderQuantity = $(this).data("minimum-order");
1294        let key = $(this).data("cart-id");
1295        let increment = $(this).data("increment");
1296        let event = $(this).data("event");
1297        updateCartQuantityList(minimumOrderQuantity, key, increment, event);
1298    });
1299
1300    $(".action-update-cart-quantity-list-mobile").on("click", function () {
1301        let minimumOrderQuantity = $(this).data("minimum-order");
1302        let key = $(this).data("cart-id");
1303        let increment = $(this).data("increment");
1304        let event = $(this).data("event");
1305        updateCartQuantityListMobile(
1306            minimumOrderQuantity,
1307            key,
1308            increment,
1309            event
1310        );
1311    });
1312
1313    $(".action-change-update-cart-quantity-list-mobile").on(
1314        "change",
1315        function () {
1316            let minimumOrderQuantity = $(this).data("minimum-order");
1317            let key = $(this).data("cart-id");
1318            let increment = $(this).data("increment");
1319            let event = $(this).data("event");
1320            updateCartQuantityListMobile(
1321                minimumOrderQuantity,
1322                key,
1323                increment,
1324                event
1325            );
1326        }
1327    );
1328
1329    $(document).ready(function () {
1330        $(".cart_information").each(function () {
1331            let allShopItemsInChecked = true;
1332            $(this)
1333                .find(".shop-item-check")
1334                .each(function () {
1335                    if (!$(this).prop("checked")) {
1336                        allShopItemsInChecked = false;
1337                        return false;
1338                    }
1339                });
1340            $(this)
1341                .find(".shop-head-check")
1342                .prop("checked", allShopItemsInChecked);
1343        });
1344    });
1345
1346    $(".shop-head-check").on("change", function () {
1347        $(this)
1348            .parents(".cart_information")
1349            .find(".shop-item-check")
1350            .prop("checked", this.checked);
1351    });
1352
1353    $(".shop-item-check").on("change", function () {
1354        var allChecked = true;
1355        $(this)
1356            .parents(".cart_information")
1357            .find(".shop-item-check")
1358            .each(function () {
1359                if (!$(this).prop("checked")) {
1360                    allChecked = false;
1361                    return false;
1362                }
1363            });
1364        $(this)
1365            .parents(".cart_information")
1366            .find(".shop-head-check")
1367            .prop("checked", allChecked);
1368    });
1369
1370    $(".shop-head-check-desktop").on("change", function () {
1371        getCartSelectCartItemsCheckedValues(
1372            '.cart_information input[type="checkbox"].shop-item-check-desktop'
1373        );
1374    });
1375
1376    $(".shop-head-check-mobile").on("change", function () {
1377        getCartSelectCartItemsCheckedValues(
1378            '.cart_information input[type="checkbox"].shop-item-check-mobile'
1379        );
1380    });
1381
1382    $(".shop-item-check-desktop").on("change", function () {
1383        getCartSelectCartItemsCheckedValues(
1384            '.cart_information input[type="checkbox"].shop-item-check-desktop'
1385        );
1386    });
1387
1388    $(".shop-item-check-mobile").on("change", function () {
1389        getCartSelectCartItemsCheckedValues(
1390            '.cart_information input[type="checkbox"].shop-item-check-mobile'
1391        );
1392    });
1393
1394    function getCartSelectCartItemsCheckedValues(elementSelector) {
1395        let checkedValues = [];
1396        $(elementSelector).each(function () {
1397            if ($(this).prop("checked")) {
1398                checkedValues.push($(this).val());
1399            }
1400        });
1401        getCartSelectCartItemsRequest(checkedValues);
1402    }
1403
1404    function getCartSelectCartItemsRequest(checkedValues) {
1405        $.ajaxSetup({
1406            headers: {
1407                "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
1408            },
1409        });
1410        $.ajax({
1411            url: $("#get-cart-select-cart-items").data("route"),
1412            type: "POST",
1413            data: {
1414                ids: checkedValues,
1415            },
1416            beforeSend: function () {
1417                $("#loading").show();
1418            },
1419            success: function (response) {
1420                $("#cart-summary").empty().html(response.htmlView);
1421                toastr.success(response.message);
1422                cartListQuantityUpdateInit();
1423                setShippingIdFunctionCartDetails();
1424                $('[data-toggle="tooltip"]').tooltip();
1425                actionCheckoutFunctionInit();
1426                couponCode();
1427                updateNavCart();
1428            },
1429            complete: function () {
1430                $("#loading").hide();
1431            },
1432        });
1433    }
1434}
1435
1436cartListQuantityUpdateInit();
1437
1438function actionCheckoutFunctionInit() {
1439    $(".action-checkout-function").on("click", function () {
1440        let getRoute = $("#route-action-checkout-function").data("route");
1441        if (getRoute && getRoute.toString() === "shop-cart") {
1442            checkoutFromCartList();
1443        } else if (getRoute && getRoute.toString() === "checkout-details") {
1444            checkoutFromShipping();
1445        } else if (getRoute && getRoute.toString() === "checkout-payment") {
1446            checkoutFromPayment();
1447        }
1448    });
1449
1450    $(".action-set-shipping-id").on("change", function () {
1451        let cartGroupId = $(this).data("product-id");
1452        let id = $(this).val();
1453        setShippingId(id, cartGroupId);
1454    });
1455}
1456
1457actionCheckoutFunctionInit();
1458
1459function removeFromCart(key) {
1460    $.post(
1461        $("#route-cart-remove").data("url"),
1462        {
1463            _token: $('meta[name="_token"]').attr("content"),
1464            key: key,
1465        },
1466        function (response) {
1467            $("#cod-for-cart").hide();
1468            updateNavCart();
1469            $("#cart-summary").empty().html(response.data);
1470            couponCode();
1471            toastr.info(
1472                $("#message-item-has-been-removed-from-cart").data("text"),
1473                {
1474                    CloseButton: true,
1475                    ProgressBar: true,
1476                }
1477            );
1478            let segment_array = window.location.pathname.split("/");
1479            let segment = segment_array[segment_array.length - 1];
1480            if (
1481                segment === "checkout-payment" ||
1482                segment === "checkout-details"
1483            ) {
1484                location.reload();
1485            }
1486        }
1487    );
1488}
1489
1490function updateNavCart() {
1491    $.post(
1492        $("#route-cart-nav-cart").data("url"),
1493        {
1494            _token: $('meta[name="_token"]').attr("content"),
1495        },
1496        function (response) {
1497            $("#cart_items").html(response.data);
1498            cartListQuantityUpdateInit();
1499        }
1500    );
1501}
1502
1503$("#add-to-cart-form").on("submit", function (e) {
1504    e.preventDefault();
1505});
1506
1507function cartQuantityInitialize() {
1508    $(".btn-number").click(function (e) {
1509        e.preventDefault();
1510        let fieldName = $(this).attr("data-field");
1511        let type = $(this).attr("data-type");
1512        let productType = $(this).data("producttype");
1513        let input = $("input[name='" + fieldName + "']");
1514        let currentVal = parseInt($(".input-number").val());
1515        if (!isNaN(currentVal)) {
1516            if (type == "minus") {
1517                if (currentVal > $(".input-number").attr("min")) {
1518                    $(".input-number")
1519                        .val(currentVal - 1)
1520                        .change();
1521                }
1522                if (
1523                    parseInt($(".input-number").val()) ==
1524                    $(".input-number").attr("min")
1525                ) {
1526                    $(this).attr("disabled", true);
1527                }
1528            } else if (type == "plus") {
1529                if (
1530                    currentVal < $(".input-number").attr("max") ||
1531                    productType === "digital"
1532                ) {
1533                    $(".input-number")
1534                        .val(currentVal + 1)
1535                        .change();
1536                }
1537
1538                if (
1539                    parseInt(input.val()) == $(".input-number").attr("max") &&
1540                    productType === "physical"
1541                ) {
1542                    $(this).attr("disabled", true);
1543                }
1544            }
1545        } else {
1546            $(".input-number").val(0);
1547        }
1548    });
1549
1550    $(".input-number").focusin(function () {
1551        $(this).data("oldValue", $(this).val());
1552    });
1553
1554    $(".input-number").change(function () {
1555        let productType = $(this).data("producttype");
1556        let minValue = parseInt($(this).attr("min"));
1557        let maxValue = parseInt($(this).attr("max"));
1558        let valueCurrent = parseInt($(this).val());
1559        let name = $(this).attr("name");
1560        if (valueCurrent >= minValue) {
1561            $(
1562                ".btn-number[data-type='minus'][data-field='" + name + "']"
1563            ).removeAttr("disabled");
1564        } else {
1565            Swal.fire({
1566                icon: "error",
1567                title: $("#message-cart").data("text"),
1568                text: $(
1569                    "#message-sorry-the-minimum-order-quantity-not-match"
1570                ).data("text"),
1571            });
1572            $(this).val($(this).data("oldValue"));
1573        }
1574        if (productType === "digital" || valueCurrent <= maxValue) {
1575            $(
1576                ".btn-number[data-type='plus'][data-field='" + name + "']"
1577            ).removeAttr("disabled");
1578        } else {
1579            Swal.fire({
1580                icon: "error",
1581                title: $("#message-cart").data("text"),
1582                text: $("#message-sorry-stock-limit-exceeded").data("text"),
1583            });
1584            $(this).val($(this).data("oldValue"));
1585        }
1586    });
1587
1588    $(".input-number").keydown(function (e) {
1589        if (
1590            $.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
1591            (e.keyCode == 65 && e.ctrlKey === true) ||
1592            (e.keyCode >= 35 && e.keyCode <= 39)
1593        ) {
1594            return;
1595        }
1596        if (
1597            (e.shiftKey || e.keyCode < 48 || e.keyCode > 57) &&
1598            (e.keyCode < 96 || e.keyCode > 105)
1599        ) {
1600            e.preventDefault();
1601        }
1602    });
1603}
1604
1605function updateQuantity(key, element) {
1606    $.post(
1607        $("#route-cart-updateQuantity").data("url"),
1608        {
1609            _token: "<?php echo e(csrf_token()); ?>",
1610            key: key,
1611            quantity: element.value,
1612        },
1613        function (data) {
1614            updateNavCart();
1615            $("#cart-summary").empty().html(data);
1616            couponCode();
1617        }
1618    );
1619}
1620
1621function updateCartQuantity(cart_id, product_id, action, event) {
1622    let remove_url = $("#route-cart-remove").data("url");
1623    let update_quantity_url = $("#route-cart-updateQuantity-guest").data("url");
1624    let token = $('meta[name="_token"]').attr("content");
1625    let product_qyt =
1626        parseInt($(`.cartQuantity${cart_id}`).val()) + parseInt(action);
1627    let cart_quantity_of = $(`.cartQuantity${cart_id}`);
1628    let segment_array = window.location.pathname.split("/");
1629    let segment = segment_array[segment_array.length - 1];
1630
1631    if (cart_quantity_of.val() > cart_quantity_of.data("current-stock")) {
1632        cartItemRemoveFunction(remove_url, token, cart_id, segment);
1633        return false;
1634    }
1635
1636    if (cart_quantity_of.val() == 0) {
1637        toastr.info($(".cannot_use_zero").data("text"), {
1638            CloseButton: true,
1639            ProgressBar: true,
1640        });
1641        cart_quantity_of.val(cart_quantity_of.data("min"));
1642    } else if (
1643        cart_quantity_of.val() == cart_quantity_of.data("min") &&
1644        event == "minus"
1645    ) {
1646        cartItemRemoveFunction(remove_url, token, cart_id, segment);
1647    } else {
1648        if (cart_quantity_of.val() < cart_quantity_of.data("min")) {
1649            let min_value = cart_quantity_of.data("min");
1650            toastr.error(
1651                $("#message-minimum-order-quantity-cannot-less-than").data(
1652                    "text"
1653                ) +
1654                " " +
1655                min_value
1656            );
1657            cart_quantity_of.val(min_value);
1658            updateCartQuantity(cart_id, product_id, action, event);
1659        } else {
1660            $(`.cartQuantity${cart_id}`).html(product_qyt);
1661            $.post(
1662                update_quantity_url,
1663                {
1664                    _token: token,
1665                    key: cart_id,
1666                    product_id: product_id,
1667                    quantity: product_qyt,
1668                },
1669                function (response) {
1670                    if (response["status"] == 0) {
1671                        toastr.error(response["message"]);
1672                    } else {
1673                        toastr.success(response["message"]);
1674                    }
1675                    $('.in_cart_key[name="key"]').val(response.in_cart_key);
1676                    response["qty"] <= 1
1677                        ? $(`.quantity__minus${cart_id}`).html(
1678                            '<i class="tio-delete-outlined text-danger fs-10"></i>'
1679                        )
1680                        : $(`.quantity__minus${cart_id}`).html(
1681                            '<i class="tio-remove fs-10"></i>'
1682                        );
1683
1684                    $(`.cartQuantity${cart_id}`).val(response["qty"]);
1685                    $(`.cartQuantity${cart_id}`).html(response["qty"]);
1686                    $(`.cart_quantity_multiply${cart_id}`).html(
1687                        response["qty"]
1688                    );
1689                    $(".cart_total_amount").html(response.total_price);
1690                    $(".cart-total-price").html(response.total_price);
1691                    $(`.discount_price_of_${cart_id}`).html(
1692                        response["discount_price"]
1693                    );
1694                    $(`.quantity_price_of_${cart_id}`).html(
1695                        response["quantity_price"]
1696                    );
1697                    $(`.total_discount`).html(response["total_discount_price"]);
1698                    $(`.free_delivery_amount_need`).html(
1699                        response.free_delivery_status.amount_need
1700                    );
1701                    if (response.free_delivery_status.amount_need <= 0) {
1702                        $(".amount_fullfill").removeClass("d-none");
1703                        $(".amount_need_to_fullfill").addClass("d-none");
1704                    } else {
1705                        $(".amount_fullfill").addClass("d-none");
1706                        $(".amount_need_to_fullfill").removeClass("d-none");
1707                    }
1708                    const progressBar = document.querySelector(".progress-bar");
1709                    if (progressBar) {
1710                        progressBar.style.width =
1711                            response.free_delivery_status.percentage + "%";
1712                    }
1713                    if (response["qty"] == cart_quantity_of.data("min")) {
1714                        cart_quantity_of
1715                            .parent()
1716                            .find(".quantity__minus")
1717                            .html(
1718                                '<i class="tio-delete-outlined text-danger fs-10"></i>'
1719                            );
1720                    } else {
1721                        cart_quantity_of
1722                            .parent()
1723                            .find(".quantity__minus")
1724                            .html('<i class="tio-remove fs-10"></i>');
1725                    }
1726                    if (
1727                        segment === "shop-cart" ||
1728                        segment === "checkout-payment" ||
1729                        segment === "checkout-details"
1730                    ) {
1731                        location.reload();
1732                    }
1733                }
1734            );
1735        }
1736    }
1737}
1738
1739function cartItemRemoveFunction(remove_url, token, cart_id, segment) {
1740    $.post(
1741        remove_url,
1742        {
1743            _token: token,
1744            key: cart_id,
1745        },
1746        function (response) {
1747            updateNavCart();
1748            toastr.info(response.message, {
1749                CloseButton: true,
1750                ProgressBar: true,
1751            });
1752            getUpdateProductAddUpdateCartBtn(response)
1753            if (
1754                segment === "shop-cart" ||
1755                segment === "checkout-payment" ||
1756                segment === "checkout-details"
1757            ) {
1758                location.reload();
1759            }
1760        }
1761    );
1762}
1763
1764function getUpdateProductAddUpdateCartBtn(response) {
1765    try {
1766        let productInfo = $('.product-generated-variation-code');
1767        let productVariantExist = false;
1768
1769        response?.cartList?.map(function (item, index) {
1770            if (productInfo.data('product-id') == item?.id && productInfo.val() == item?.variant) {
1771                productVariantExist = true;
1772            }
1773        })
1774
1775        if (!productVariantExist) {
1776            let actionAddToCartBtn = $('.action-add-to-cart-form');
1777            actionAddToCartBtn.html(actionAddToCartBtn.data('add-text'))
1778            $('.in_cart_key[name="key"]').val('');
1779        }
1780    } catch (e) {
1781    }
1782}
1783
1784$("#add-to-cart-form input").on("change", function () {
1785    getVariantPrice();
1786});
1787
1788function getVariantPrice() {
1789    if (
1790        ($("#add-to-cart-form input[name=quantity]").val() > 0 &&
1791            checkAddToCartValidity()) ||
1792        ($("#add-to-cart-form input[name=quantity]").val() > 0 &&
1793            checkAddToCartValidity())
1794    ) {
1795        $.ajaxSetup({
1796            headers: {
1797                "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
1798            },
1799        });
1800        $.ajax({
1801            type: "POST",
1802            url: $("#route-cart-variant-price").data("url"),
1803            data: $("#add-to-cart-form").serializeArray(),
1804            success: function (data) {
1805                $("#add-to-cart-form #chosen_price_div").removeClass("d-none");
1806                $("#add-to-cart-form #chosen_price_div #chosen_price").html(
1807                    data.price
1808                );
1809                $("#chosen_price_mobile").html(data.price);
1810                $("#set-tax-amount-mobile").html(data.update_tax);
1811                $("#set-tax-amount").html(data.update_tax);
1812                $("#set-discount-amount").html(data.discount);
1813                $("#available-quantity").html(data.quantity);
1814                $(".cart-qty-field").attr("max", data.quantity);
1815
1816                if (data?.product_type?.toString() === 'physical') {
1817                    let productRestockRequestButton = $(".product-restock-request-button");
1818                    if (data.quantity <= 0) {
1819                        $(".product-restock-request-section").show();
1820                        productRestockRequestButton.removeAttr('disabled');
1821                        $(".product-add-and-buy-section").hide();
1822                    } else {
1823                        $(".product-restock-request-section").hide();
1824                        $(".product-add-and-buy-section").show();
1825                    }
1826                    if (data?.restock_request_status) {
1827                        productRestockRequestButton.html(productRestockRequestButton.data('requested'));
1828                        productRestockRequestButton.attr('disabled', true);
1829                    } else {
1830                        productRestockRequestButton.html(productRestockRequestButton.data('default'));
1831                    }
1832                }
1833
1834                $(".cart-qty-field").val(data.in_cart_quantity);
1835                $(".product-generated-variation-code").val(data.variation_code);
1836                if (
1837                    $(".cart-qty-field").attr("min") <
1838                    parseFloat($(".cart-qty-field").val())
1839                ) {
1840                    $(
1841                        ".btn-number[data-type='minus'][data-field='quantity']"
1842                    ).removeAttr("disabled");
1843                } else {
1844                    $(
1845                        ".btn-number[data-type='minus'][data-field='quantity']"
1846                    ).attr("disabled", true);
1847                }
1848
1849                $(".discounted_unit_price").html(data.discounted_unit_price);
1850                $(".total_unit_price").html(
1851                    data.discount_amount > 0 ? data.total_unit_price : ""
1852                );
1853
1854                let actionAddToCartBtn = $(".action-add-to-cart-form");
1855                if (data.in_cart_status === 1) {
1856                    $('.in_cart_key[name="key"]').val(data.in_cart_key);
1857                    actionAddToCartBtn.html(
1858                        actionAddToCartBtn.data("update-text")
1859                    );
1860                } else {
1861                    $('.in_cart_key[name="key"]').val(data.in_cart_key);
1862                    actionAddToCartBtn.html(
1863                        actionAddToCartBtn.data("add-text")
1864                    );
1865                }
1866            },
1867        });
1868    }
1869}
1870
1871function checkAddToCartValidity() {
1872    var names = {};
1873    $("#add-to-cart-form input:radio").each(function () {
1874        names[$(this).attr("name")] = true;
1875    });
1876    var count = 0;
1877    $.each(names, function () {
1878        count++;
1879    });
1880
1881    if ($("#add-to-cart-form input:radio:checked").length == count) {
1882        return true;
1883    }
1884    return false;
1885}
1886
1887function updateFlashDealProgressBar() {
1888    let getFlashDealsTime = $("#storage-flash-deals").data("value");
1889    const current_time_stamp = new Date().getTime();
1890    const start_date = new Date(getFlashDealsTime).getTime();
1891    const countdownElement = document.querySelector(".cz-countdown");
1892    try {
1893        const getEndTime = countdownElement.data("countdown");
1894        const endTime = new Date(getEndTime).getTime();
1895        let time_progress =
1896            ((current_time_stamp - start_date) / (endTime - start_date)) * 100;
1897        const progress_bar = document.querySelector(".flash-deal-progress-bar");
1898        progress_bar.style.width = time_progress + "%";
1899    } catch (e) {
1900    }
1901}
1902
1903$(".image-preview-before-upload").on("change", function () {
1904    let getElementId = $(this).data("preview");
1905    $(getElementId).attr("src", window.URL.createObjectURL(this.files[0]));
1906    $(getElementId).removeClass("d-none");
1907    $(getElementId)
1908        .closest(".custom_upload_input")
1909        .find(".placeholder-image")
1910        .css("opacity", "0");
1911});
1912
1913$(document).on("ready", function () {
1914    if ($(".image-preview-before-upload").length) {
1915        $(".image-preview-before-upload").each(function () {
1916            if ($(this).data("image")) {
1917                let getElementId = $(this).data("preview");
1918                $(getElementId).attr("src", $(this).data("image"));
1919                $(getElementId).removeClass("d-none");
1920                $(getElementId)
1921                    .closest(".custom_upload_input")
1922                    .find(".placeholder-image")
1923                    .css("opacity", "0");
1924            }
1925        });
1926    }
1927});
1928
1929$("#vendor-remember-input-checked").on("change", function () {
1930    if ($(this).is(":checked")) {
1931        $("#apply").removeAttr("disabled");
1932    } else {
1933        $("#apply").attr("disabled", "disabled");
1934    }
1935});
1936
1937$("#exampleInputPassword, #exampleRepeatPassword").on("keyup", function () {
1938    let password = $("#exampleInputPassword").val();
1939    let passwordRepeat = $("#exampleRepeatPassword").val();
1940    if (password != "" && passwordRepeat != "") {
1941        if (password.toString() === passwordRepeat.toString()) {
1942            $(".pass").hide();
1943        } else {
1944            $(".pass").show();
1945        }
1946    } else {
1947        $(".pass").hide();
1948    }
1949});
1950
1951$(".alert-insufficient-loyalty-point").on("click", function () {
1952    let message = $(this).data("insufficient-point");
1953    toastr.error(message);
1954});
1955
1956function shareOnSocialMedia() {
1957    $(".share-on-social-media").on("click", function () {
1958        let social = $(this).data("social-media-name");
1959        let url = $(this).data("action");
1960        let width = 600,
1961            height = 400,
1962            left = (screen.width - width) / 2,
1963            top = (screen.height - height) / 2;
1964        window.open(
1965            "https://" + social + encodeURIComponent(url),
1966            "Popup",
1967            "toolbar=0,status=0,width=" +
1968            width +
1969            ",height=" +
1970            height +
1971            ",left=" +
1972            left +
1973            ",top=" +
1974            top
1975        );
1976    });
1977}
1978
1979shareOnSocialMedia();
1980
1981var directionFromSession = $("#direction-from-session").data("value");
1982directionFromSession = directionFromSession ? directionFromSession : "ltr";
1983
1984const themeDirection = $("html").attr("dir");
1985
1986function renderOwlCarouselSilder() {
1987    var sync1 = $("#sync1");
1988    var sync2 = $("#sync2");
1989    var thumbnailItemClass = ".owl-item";
1990    var slides = sync1
1991        .owlCarousel({
1992            startPosition: 12,
1993            items: 1,
1994            loop: false,
1995            margin: 0,
1996            mouseDrag: true,
1997            touchDrag: true,
1998            pullDrag: false,
1999            scrollPerPage: true,
2000            autoplayHoverPause: false,
2001            nav: false,
2002            dots: false,
2003            rtl: themeDirection && themeDirection.toString() === "rtl",
2004        })
2005        .on("changed.owl.carousel", syncPosition);
2006
2007    function syncPosition(el) {
2008        var owl_slider = $(this).data("owl.carousel");
2009        var loop = owl_slider.options.loop;
2010
2011        if (loop) {
2012            var count = el.item.count - 1;
2013            var current = Math.round(el.item.index - el.item.count / 2 - 0.5);
2014            if (current < 0) {
2015                current = count;
2016            }
2017            if (current > count) {
2018                current = 0;
2019            }
2020        } else {
2021            var current = el.item.index;
2022        }
2023
2024        var owl_thumbnail = sync2.data("owl.carousel");
2025        var itemClass = "." + owl_thumbnail.options.itemClass;
2026
2027        var thumbnailCurrentItem = sync2
2028            .find(itemClass)
2029            .removeClass("synced")
2030            .eq(current);
2031        thumbnailCurrentItem.addClass("synced");
2032
2033        if (!thumbnailCurrentItem.hasClass("active")) {
2034            var duration = 500;
2035            sync2.trigger("to.owl.carousel", [current, duration, true]);
2036        }
2037    }
2038
2039    var thumbs = sync2
2040        .owlCarousel({
2041            startPosition: 12,
2042            items: 4,
2043            loop: false,
2044            margin: 10,
2045            autoplay: false,
2046            nav: false,
2047            dots: false,
2048            rtl: themeDirection && themeDirection.toString() === "rtl",
2049            responsive: {
2050                576: {
2051                    items: 4,
2052                },
2053                768: {
2054                    items: 4,
2055                },
2056                992: {
2057                    items: 4,
2058                },
2059                1200: {
2060                    items: 5,
2061                },
2062                1400: {
2063                    items: 5,
2064                },
2065            },
2066            onInitialized: function (e) {
2067                var thumbnailCurrentItem = $(e.target)
2068                    .find(thumbnailItemClass)
2069                    .eq(this._current);
2070                thumbnailCurrentItem.addClass("synced");
2071            },
2072        })
2073        .on("click", thumbnailItemClass, function (e) {
2074            e.preventDefault();
2075            var duration = 500;
2076            var itemIndex = $(e.target).parents(thumbnailItemClass).index();
2077            sync1.trigger("to.owl.carousel", [itemIndex, duration, true]);
2078        })
2079        .on("changed.owl.carousel", function (el) {
2080            var number = el.item.index;
2081            var owl_slider = sync1.data("owl.carousel");
2082            owl_slider.to(number, 500, true);
2083        });
2084    sync1.owlCarousel();
2085}
2086
2087renderOwlCarouselSilder();
2088
2089function findCountryObject(data) {
2090    return data.find((obj) => obj.types && obj.types.includes("country"));
2091}
2092
2093$(".close-element-onclick-by-data").on("click", function () {
2094    $($(this).data("selector")).slideUp("slow").fadeOut("slow");
2095});
2096$(".password-check").on("keyup keypress change click", function () {
2097    let password = $(this).val();
2098    let passwordError = $(".password-error");
2099    let passwordErrorMessage = $("#password-error-message");
2100    switch (true) {
2101        case password.length < 8:
2102            passwordError
2103                .html(passwordErrorMessage.data("max-character"))
2104                .removeClass("d-none");
2105            break;
2106        case !/[a-z]/.test(password):
2107            passwordError
2108                .html(passwordErrorMessage.data("lowercase-character"))
2109                .removeClass("d-none");
2110            break;
2111        case !/[A-Z]/.test(password):
2112            passwordError
2113                .html(passwordErrorMessage.data("uppercase-character"))
2114                .removeClass("d-none");
2115            break;
2116        case !/\d/.test(password):
2117            passwordError
2118                .html(passwordErrorMessage.data("number"))
2119                .removeClass("d-none");
2120            break;
2121        case !/[@.#$!%*?&]/.test(password):
2122            passwordError
2123                .html(passwordErrorMessage.data("symbol"))
2124                .removeClass("d-none");
2125            break;
2126        default:
2127            passwordError.addClass("d-none").empty();
2128    }
2129});
2130
2131function setEqualHeight(slides) {
2132    let maxHeight = 0;
2133
2134    slides.forEach(slide => {
2135        slide.style.height = '';
2136        if (slide.offsetHeight > maxHeight) {
2137            maxHeight = slide.offsetHeight;
2138        }
2139    });
2140
2141    slides.forEach(slide => {
2142        slide.style.height = maxHeight + 'px';
2143    });
2144}
2145
2146$(".footer-slider").owlCarousel({
2147    margin: 10,
2148    items: 3,
2149    // responsiveClass: true,
2150    nav: false,
2151    dots: false,
2152    loop: false,
2153    autoplay: false,
2154    rtl: themeDirection && themeDirection.toString() === "rtl",
2155    autoHeight: true,
2156    responsive: {
2157        768: {
2158            items: 3,
2159            margin: 40,
2160        },
2161    },
2162});
2163
2164$(".footer-top-slider").owlCarousel({
2165    margin: 20,
2166    items: 2,
2167    nav: false,
2168    dots: false,
2169    loop: false,
2170    autoplay: false,
2171    responsiveClass: true,
2172    rtl: themeDirection && themeDirection.toString() === "rtl",
2173    autoHeight: true,
2174    responsive: {
2175        500: {
2176            items: 3,
2177        },
2178        768: {
2179            items: 4,
2180        },
2181    },
2182});
2183
2184function sameHeight() {
2185    setEqualHeight(document.querySelectorAll('.footer-slider-container .footer-slider .owl-item'))
2186    setEqualHeight(document.querySelectorAll('.footer-top-slider .owl-item'))
2187}
2188
2189sameHeight()
2190
2191$(window).on('resize', sameHeight)
2192
2193$(".promotional-banner-slider").owlCarousel({
2194    margin: 20,
2195    items: 1,
2196    nav: true,
2197    dots: false,
2198    loop: true,
2199    rtl: themeDirection && themeDirection.toString() === "rtl",
2200    responsive: {
2201        768: {
2202            items: 2,
2203            nav: true,
2204            dots: false,
2205            loop: true,
2206        },
2207    },
2208});
2209
2210function playAudio() {
2211    document.getElementById("myAudio").play();
2212}
2213
2214$(window).on("load", function () {
2215    $(".upload-file__input").on("change", function () {
2216        if (this.files && this.files[0]) {
2217            let reader = new FileReader();
2218            let img = $(this)
2219                .siblings(".upload-file__img")
2220                .find("img")
2221                .removeAttr("hidden");
2222            $(this)
2223                .siblings(".upload-file__img")
2224                .find(".temp-img-box")
2225                .remove();
2226
2227            reader.onload = function (e) {
2228                img.attr("src", e.target.result);
2229            };
2230
2231            reader.readAsDataURL(this.files[0]);
2232        }
2233    });
2234});
2235
2236function downloadFileUsingFileUrl(url) {
2237    fetch(url)
2238        .then((response) => response.blob())
2239        .then((blob) => {
2240            const filename = url.substring(url.lastIndexOf("/") + 1);
2241            const blobUrl = window.URL.createObjectURL(new Blob([blob]));
2242            const link = document.createElement("a");
2243            link.href = blobUrl;
2244            link.setAttribute("download", filename);
2245            document.body.appendChild(link);
2246            link.click();
2247            link.parentNode.removeChild(link);
2248        })
2249        .catch((error) => console.error("Error downloading file:", error));
2250}
2251
2252$(".getDownloadFileUsingFileUrl").on("click", function () {
2253    let getLink = $(this).data("file-path");
2254    downloadFileUsingFileUrl(getLink);
2255});
2256$(".sidebar-overlay").on("click", function () {
2257    $(".cz-sidebar").removeClass("show active");
2258});
2259
2260
2261function getSessionRecaptchaCode(sessionKey, inputSelector) {
2262    try {
2263        let routeGetSessionRecaptchaCode = $('#route-get-session-recaptcha-code');
2264        if (routeGetSessionRecaptchaCode.data('mode').toString() === 'dev') {
2265            let string = '.';
2266            let intervalId = setInterval(() => {
2267                if (string === '......') {
2268                    string = '.';
2269                }
2270                string = string + '.';
2271                $(inputSelector).val(string);
2272            }, 100);
2273
2274            setTimeout(() => {
2275                clearInterval(intervalId);
2276                $.ajaxSetup({
2277                    headers: {
2278                        "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
2279                    },
2280                });
2281                $.ajax({
2282                    type: "POST",
2283                    url: $('#route-get-session-recaptcha-code').data('route'),
2284                    data: {
2285                        _token: $('meta[name="_token"]').attr("content"),
2286                        sessionKey: sessionKey,
2287                    },
2288                    success: function (response) {
2289                        $(inputSelector).val(response?.code);
2290                    },
2291                });
2292            }, 1000);
2293        }
2294    } catch (e) {
2295        console.log(e);
2296    }
2297}
2298
2299$('.get-session-recaptcha-auto-fill').each(function () {
2300    getSessionRecaptchaCode($(this).data('session'), $(this).data('input'))
2301});
2302
2303$('.get-session-recaptcha-auto-fill').on('click', function () {
2304    getSessionRecaptchaCode($(this).data('session'), $(this).data('input'));
2305});
2306
2307$('.otp-login-btn').on('click', function () {
2308    $(this).addClass('d-none');
2309    $('.manual-login-btn').removeClass('d-none');
2310    $('.manual-login-items').addClass('d-none');
2311    $('.otp-login-items').removeClass('d-none');
2312    $('.phone-input-with-country-picker').attr('required', true);
2313    $('.auth-email-input').attr('required', false);
2314    $('.auth-password-input').attr('required', false);
2315    $('.auth-login-type-input').val('otp-login');
2316})
2317
2318$('.manual-login-btn').on('click', function () {
2319    $(this).addClass('d-none');
2320    $('.otp-login-btn').removeClass('d-none');
2321    $('.otp-login-items').addClass('d-none');
2322    $('.manual-login-items').removeClass('d-none');
2323    $('.phone-input-with-country-picker').attr('required', false);
2324    $('.auth-email-input').attr('required', true);
2325    $('.auth-password-input').attr('required', true);
2326    $('.auth-login-type-input').val('manual-login');
2327})
2328
2329$('.customer-centralize-login-form').on('submit', async function (event) {
2330    event.preventDefault();
2331
2332    var recaptchaContainer = document.getElementById('recaptcha_element');
2333    if (recaptchaContainer && recaptchaContainer.innerHTML.trim()?.toString() !== "") {
2334        var response = grecaptcha.getResponse();
2335        if (response.length === 0) {
2336            toastr.error($("#message-please-check-recaptcha").data("text"));
2337            return false;
2338        }
2339    }
2340
2341    // var recaptchaFirebaseContainer = document.getElementById('recaptcha_element');
2342    // if (recaptchaFirebaseContainer && recaptchaFirebaseContainer.innerHTML.trim()?.toString() !== "") {
2343    //     var response = grecaptcha.getResponse();
2344    //     if (response.length === 0) {
2345    //         toastr.error($("#message-please-check-recaptcha").data("text"));
2346    //         return false;
2347    //     }
2348    // }
2349
2350    $.ajax({
2351        url: $(this).attr('action'),
2352        method: $(this).attr('method'),
2353        data: $(this).serialize(),
2354        beforeSend: function () {
2355            $("#loading").show();
2356        },
2357        success: function (response) {
2358            responseManager(response)
2359        },
2360        complete: function () {
2361            $("#loading").hide();
2362        },
2363    });
2364});
2365
2366
2367function responseManager(response) {
2368    if (response.status === 'success') {
2369        if (response.message) {
2370            toastr.success(response.message);
2371        }
2372        if (response?.redirectRoute) {
2373            location.href = response.redirectRoute;
2374        } else if (response?.redirect_url) {
2375            location.href = response?.redirect_url;
2376        }
2377    } else if (response.status === 'error') {
2378        if (response.message) {
2379            toastr.error(response.message);
2380        }
2381    } else if (response.status === 'warning') {
2382        if (response.message) {
2383            toastr.warning(response.message);
2384        }
2385    }
2386
2387    if (response.errors) {
2388        for (
2389            let index = 0;
2390            index < response.errors.length;
2391            index++
2392        ) {
2393            toastr.error(response.errors[index].message, {
2394                CloseButton: true,
2395                ProgressBar: true,
2396            });
2397        }
2398    } else if (response.error) {
2399        toastr.error(response.error, {
2400            CloseButton: true,
2401            ProgressBar: true,
2402        });
2403    }
2404
2405    if (response?.reload) {
2406        location.reload();
2407    }
2408}
2409
2410$('.clean-phone-input-value').on("input", function () {
2411    $(this).val($(this).val().replace(/\s/g, ""));
2412});
2413
2414function productRestockStockLimitStatus(response) {
2415    let mainElement = $('.product-restock-stock-alert');
2416    mainElement.find('.title').html(response?.title);
2417    mainElement.find('.image').attr("width", 50).attr('src', response?.image);
2418    mainElement.find('.message').html(response?.body);
2419    mainElement.find('.product-link').removeAttr('data-link');
2420    mainElement.find('.product-link').attr('data-link', response?.route);
2421    mainElement.addClass("active");
2422    setTimeout(() => {
2423        mainElement.removeClass("active");
2424    }, 100000)
2425}
2426
2427$(".product-restock-stock-close").on("click", function () {
2428    $(".product-restock-stock-alert").removeClass("active");
2429});

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.