PageSourceSearch

https://chinlee.com.sg/Scripts/js_newUI/custom_js_ui.js?v=235.20261006-120

js chinlee.com.sg collected 2026-10-08 07:21:47 UTC 35,298 bytes, 877 lines download raw bytes

1var rowPromotionHtml = "";
2var quantityOpenPrice = 0;
3var currentVariantId = "";
4var myCartProductItems = [];
5
6$(document).ready(function () {
7    if (typeof isMerchantOS == 'undefined' || isMerchantOS == false) {
8        if ($(window).width() < 991) {
9            $('#header').height($("#header .header__navbar").height() - 3);
10        }
11        else {
12            $('#header').height($("#header .inner").height() - 3);
13        }
14    }
15
16    var sectionPromotion = $("#home-page-promotion, #MenuGridViewLoadMore");
17    sectionPromotion.on("click", ".descript__text--overflow", function (e) {
18        e.preventDefault();
19        const parentDP = $(this).parents(".descript-promotion");
20        const attrHidden = parentDP.find(".read-less-lable").attr('hidden');
21        if (typeof attrHidden === typeof undefined || attrHidden === false) {
22            parentDP.find(".read-less-lable").trigger("click");
23        }
24    });
25
26    const descriptEl = $(".descript-promotion .descript__text--overflow");
27    descriptEl.each((_, item) => {
28        if (item.innerHTML?.length && item.innerHTML.trim().length > 140) {
29            item.parentNode.querySelector('.button__read-more').removeAttribute('hidden');
30            item.parentNode.querySelector('.button__read-less').setAttribute('hidden', 'hidden');
31        } else {
32            item.parentNode.querySelector('.button__read-more').setAttribute('hidden', 'hidden');
33            item.parentNode.querySelector('.button__read-less').setAttribute('hidden', 'hidden');
34        }
35    });
36
37    sectionPromotion.on("click", ".button__read-more", function (e) {
38        e.preventDefault();
39        const descPromo = $(this).parents(".descript-promotion");
40        const descriptEl = descPromo.find(".descript__text--overflow");
41        const lines = descriptEl.text().split(/\r\n|\r|\n/).length;
42        descriptEl.addClass("descript__text--full");
43        descPromo.find(".button__read-less").removeAttr("hidden");
44        $(this).attr('hidden', 'hidden');
45    });
46
47    sectionPromotion.on("click", ".button__read-less", function (e) {
48        e.preventDefault();
49        const descPromo = $(this).parents(".descript-promotion");
50        descPromo.find(".descript__text--overflow").removeClass("descript__text--full");
51        descPromo.find(".button__read-more").removeAttr("hidden");
52        $(this).attr('hidden', 'hidden');
53    });
54
55    var sectionCartBlock = $(".cart-block");
56    sectionCartBlock.on("click", ".back-to-menu", function () {
57        $('.menu__cart').trigger("click");
58
59        activeCategory();
60    });
61
62    function activeCategory() {
63        setTimeout(function () { $(window).scrollTop(scrTop); }, 10);
64    }
65
66    sectionCartBlock.on("click", ".btn-number", function (e) {
67        e.preventDefault();
68        let that = $(this);
69
70        fieldName = that.attr('data-field');
71        type = that.attr('data-type');
72        var input = that.parents(".input-group").find("input[name='" + fieldName + "']");
73        var currentVal = parseInt(input.val());
74
75        var isChangeItemPromotion = false;
76
77        if (!isNaN(currentVal) && typeof isMerchantOS !== 'undefined' && isMerchantOS == true) {
78            let currentDataItem = GetCurrentDataItem(fieldName);
79
80            if (currentDataItem != null && (currentDataItem.promotionId == null || currentDataItem.promotionId == '')) {
81                let valueChange = type == 'plus' ? 1 : -1;
82                checkCartOfMerchantOS(fieldName, currentDataItem, valueChange);
83
84                return false;
85            }
86            else {
87                isChangeItemPromotion = true;
88            }
89        }
90
91        if (!isNaN(currentVal) && (typeof isMerchantOS === 'undefined' || isChangeItemPromotion == true)) {
92            let elementPlus = "#btn-plus-" + fieldName;
93            let elementMinus = "#btn-minus-" + fieldName;
94            let newCurrentVal = currentVal;
95
96            if (type == 'minus') {
97
98                if (currentVal > input.attr('min')) {
99                    newCurrentVal = currentVal - 1;
100                    input.val(newCurrentVal);
101                }
102                if (parseInt(input.val()) == input.attr('min')) {
103                    that.attr('disabled', true);
104                    if (input.attr('max') > parseInt(input.val())) {
105                        $(elementPlus).removeAttr('disabled');
106                        $(elementPlus).removeAttr('style');
107                    }
108                }
109
110                $(elementPlus).attr('disabled', true);
111
112            } else if (type == 'plus') {
113
114                if (currentVal < input.attr('max')) {
115                    newCurrentVal = currentVal + 1;
116                    input.val(newCurrentVal);
117                }
118                if (parseInt(input.val()) == input.attr('max')) {
119                    that.attr('disabled', true);
120                }
121
122                $(elementMinus).attr('disabled', true);
123
124            }
125
126            delayTimer(function () {
127                input.change();
128            }, 1000);
129
130        } else {
131            input.val(input.attr('min'));
132        }
133    });
134
135    sectionCartBlock.on("focus", "input.variant_quantity", function () {
136        if ($(window).width() < 992) {
137            $("#btn-collapse-func").removeAttr("data-toggle");
138        }
139        else {
140            $("#btn-collapse-func").attr("data-toggle", "collapse");
141        }
142    });
143
144    sectionCartBlock.on("blur", "input.variant_quantity", function () {
145        delayTimer(function () {
146            $("#btn-collapse-func").attr("data-toggle", "collapse");
147        }, 500);
148    });
149
150    // Scroll section
151    const $categoryMenuMobile = $(".category-menu-mobile");
152    let $menuMobile = $categoryMenuMobile.find("li.menu-mobile-item");
153    let isClick = false;
154    const menuMobileList = initScrollItems($menuMobile);
155    let listIdsLength = 0;
156    const $menuFloating = $('#idMenuLeft .item-menu-floating');
157    var $headerSlide = $('#main-slide [data-slider="home-slider"]');
158    const navwidth = $menuFloating.width() + 6;
159    var initialMenuFloating = false;
160
161    var menuMobileMaxHeight = 0;
162    for (let i = 0; i < $menuMobile.length; i++) {
163        menuMobileMaxHeight += $($menuMobile[i]).innerHeight();
164    }
165
166    initMenuFloating();
167
168    // Bind click handler to menu items
169    $menuMobile.on("click", function (e) {
170        const $tag = $(this);
171        const targetId = $tag.attr("data-href");
172        if ($(targetId).length === 0) {
173            return;
174        }
175        e.preventDefault;
176        e.stopPropagation()
177        $menuMobile.removeClass("active");
178        $tag.addClass("active");
179        isClick = true;
180
181        const topMenuHeight = $(window).width() < 992 ? $("#header .header__navbar").innerHeight() : $("#header .inner").innerHeight();
182
183        if (typeof isMerchantOS !== 'undefined' && isMerchantOS == true) {
184            initMenuFloating();
185            scrollCategoriesForMerchantOS(targetId);
186        }
187        else {
188            for (let replayNumber = 0; replayNumber < 2; replayNumber++) {
189                setTimeout(async function () {
190                    await animateAndWait($(targetId).offset().top - topMenuHeight);
191                }, replayNumber == 0 ? 0 : 500);
192                scrollHorizontal();
193                isClick = false;
194            }
195        }
196    });
197
198    function updateDataNewBlock(fieldName, newItemQuantity = 1) {
199        sectionCartBlock.find(`#item-${fieldName}`).find(`#quantity_of_variant_${fieldName}`).val(newItemQuantity);
200
201        var priceOfVariant = sectionCartBlock.find(`#item-${fieldName}`).find(`#price_of_variant_${fieldName}`).attr('data-price');
202        sectionCartBlock.find(`#item-${fieldName}`).find(`#price_of_variant_${fieldName}`).text(currency + " " + (priceOfVariant * newItemQuantity).toFixed(2));
203
204        sectionCartBlock.find(`.item-modifier-quantity-${fieldName}`).each(function (i, obj) {
205            let dataQuantity = $(obj).find('.quantity-modifier').attr('data-quantity');
206            $(obj).find('.quantity-modifier').text(dataQuantity * newItemQuantity);
207
208            let dataPrice = $(obj).find('.price-modifier').attr('data-price');
209            $(obj).find('.price-modifier').text(currency + " " + (dataPrice * dataQuantity * newItemQuantity).toFixed(2));
210        });
211    }
212
213    function checkCurrentDataItemExistModifier(currentDataItem) {
214        if (currentDataItem.arrayItemModifier == null) {
215            currentDataItem.arrayItemModifier = [];
216        }
217
218        if (currentDataItem.arrayOldItemModifier == null) {
219            currentDataItem.arrayOldItemModifier = [];
220        }
221
222        let isModifierNotChanged = true;
223
224        if (currentDataItem.arrayItemModifier.length == currentDataItem.arrayOldItemModifier.length) {
225            if (currentDataItem.arrayItemModifier.length != 0) {
226                currentDataItem.arrayItemModifier.forEach(function (modifier) {
227                    var modifierItem = currentDataItem.arrayOldItemModifier.find(m => m.docId == modifier.docId);
228
229                    if (modifierItem == null || modifierItem.quantity != modifier.quantity) {
230                        isModifierNotChanged = false;
231                        return false;
232                    }
233                });
234            }
235        }
236        else {
237            isModifierNotChanged = false;
238        }
239
240        return isModifierNotChanged;
241    }
242
243    function checkCurrentDataItemChanged(currentDataItem) {
244        var isVariantNotChanged = (currentDataItem.variantItem == null && currentDataItem.oldVariantItem == null)
245            || (currentDataItem.variantItem != null && currentDataItem.oldVariantItem != null && currentDataItem.variantItem.sku == currentDataItem.oldVariantItem.sku);
246
247        if (isVariantNotChanged == false) {
248            return true;
249        }
250
251        var isModifierNotChanged = (currentDataItem.arrayItemModifier == null && currentDataItem.arrayOldItemModifier == null)
252            || checkCurrentDataItemExistModifier(currentDataItem);
253
254        if (isModifierNotChanged == false) {
255            return true;
256        }
257
258        return false;
259    }
260
261    function updateCurrentDataItemChanged(currentDataItem, fieldName, newItemQuantity) {
262        currentDataItem.quantity = newItemQuantity;
263
264        sectionCartBlock.find(`#item-${fieldName}`).attr('data-item', JSON.stringify(currentDataItem));
265    }
266
267    function checkExistDataNewBlock(currentDataItem) {
268        let variantItemId = null;
269        sectionCartBlock.find('.item-merchant-os').each(function (i, obj) {
270            if ($(obj).hasClass("item-serving")) {
271                return;
272            }
273            else if ($(obj).parents('.item-line__main-categories').length > 0 && $(obj).parents('.item-line__main-categories').hasClass("item-line-promotion item-serving")) {
274                return;
275            }
276            else {
277                let dataItemStr = $(obj).attr('data-item');
278
279                if (dataItemStr != null && dataItemStr != "") {
280                    let dataItem = JSON.parse(dataItemStr);
281
282                    if (currentDataItem.productID != dataItem.productID) {
283                        return;
284                    }
285
286                    var isVariantExisted = (dataItem.variantItem == null && currentDataItem.variantItem == null)
287                        || (dataItem.variantItem != null && currentDataItem.variantItem != null && dataItem.variantItem.sku == currentDataItem.variantItem.sku);
288
289                    if (isVariantExisted == false) {
290                        return;
291                    }
292
293                    var isExistModifier = (dataItem.arrayItemModifier == null && currentDataItem.arrayItemModifier == null)
294                        || CheckExistModifier(currentDataItem, dataItem);
295
296                    if (isExistModifier == false) {
297                        return;
298                    }
299
300                    variantItemId = dataItem.variantId;
301                    return false;
302                }
303            }
304        });
305
306        return variantItemId;
307    }
308
309    function GetCurrentDataItem(fieldName) {
310        let currentDataItemStr = sectionCartBlock.find(`#item-${fieldName}`).attr('data-item');
311
312        if (currentDataItemStr != null && currentDataItemStr != "") {
313            return JSON.parse(currentDataItemStr);
314        }
315
316        return null;
317    }
318
319    function CheckExistModifier(currentDataItem, dataItem) {
320        if (currentDataItem.arrayItemModifier == null) {
321            currentDataItem.arrayItemModifier = [];
322        }
323
324        if (dataItem.arrayItemModifier == null) {
325            dataItem.arrayItemModifier = [];
326        }
327
328        let isExistModifier = true;
329        if (dataItem.arrayItemModifier.length == currentDataItem.arrayItemModifier.length) {
330            if (dataItem.arrayItemModifier.length != 0) {
331                currentDataItem.arrayItemModifier.forEach(function (modifier) {
332                    var modifierItem = dataItem.arrayItemModifier.find(m => m.docId == modifier.docId);
333                    if (modifierItem == null || modifierItem.originalQuantity != modifier.originalQuantity) {
334                        isExistModifier = false;
335                        return false;
336                    }
337                });
338            }
339        }
340        else {
341            isExistModifier = false;
342        }
343
344        return isExistModifier;
345    }
346
347    function changeQuantityMerchantOS(fieldName, currentDataItem) {
348
349        if (currentDataItem == null) {
350            currentDataItem = GetCurrentDataItem(fieldName);
351
352            if (currentDataItem == null) {
353                return false;
354            }
355        }
356
357        if (currentVariantId != null && currentVariantId != '' && currentVariantId != currentDataItem.variantId) {
358            currentVariantId = '';
359        }
360
361        let newItemQuantity = 1;
362        let fieldNameNew = `${fieldName}-new`;
363        let variantItemId = null;
364
365        isCurrentItem = false;
366
367        if (currentDataItem.quantity < currentDataItem.oldQuantity) {
368            isCurrentItem = true;
369            variantItemId = currentDataItem.variantId;
370            currentVariantId = currentDataItem.variantId;
371        }
372        else {
373            variantItemId = checkExistDataNewBlock(currentDataItem);
374        }
375
376        if (variantItemId != null && variantItemId != '' && currentDataItem.isOpenPrice == false) {
377            fieldNameNew = variantItemId;
378        }
379
380        if (sectionCartBlock.find(`#item-${fieldNameNew}`).length > 0 && currentDataItem.isOpenPrice == false) {
381            newItemQuantity = +sectionCartBlock.find(`#item-${fieldNameNew}`).find(`#quantity_of_variant_${fieldNameNew}`).val();
382            newItemQuantity += 1;
383
384            if (newItemQuantity > 1) {
385                sectionCartBlock.find(`#item-${fieldNameNew}`).find('.btn.btn-number.btn-minus').removeAttr('disabled');
386            }
387        }
388        else {
389            let cloneBlock = $('<div>').append(sectionCartBlock.find(`#item-${fieldName}`).clone()).html();
390            cloneBlock = cloneBlock.replaceAll('item-serving ', 'item-disabled ')
391                .replaceAll(fieldName, `${fieldNameNew}`);
392
393            //sectionCartBlock.find(`#item-${fieldName}`).after(cloneBlock);
394            sectionCartBlock.find(`#item-${fieldName}`).parent().append(cloneBlock);
395
396            if (currentDataItem.isOpenPrice) {
397                quantityOpenPrice += newItemQuantity;
398                currentVariantId = '';
399            }
400        }
401
402        if (isCurrentItem) {
403            updateCurrentDataItemChanged(currentDataItem, fieldNameNew, newItemQuantity);
404        }
405        else {
406            sectionCartBlock.find(`#item-${fieldNameNew}`).addClass('item-disabled');
407            sectionCartBlock.find(`#item-${fieldNameNew}`).find('.note-edited').hide();
408            document.getElementById(`item-${fieldNameNew}`).scrollIntoView({ block: 'nearest', behavior: 'smooth', inline: '
408nearest' });
409
410            sectionCartBlock.find(`#btn-minus-${fieldNameNew}`).attr('disabled', true);
411            sectionCartBlock.find(`#btn-plus-${fieldNameNew}`).attr('disabled', true);
412        }
413
414        updateDataNewBlock(fieldNameNew, newItemQuantity);
415
416        $("#btn-minus-" + currentDataItem.variantId).attr('disabled', true);
417
418        delayTimer(function () {
419            let disabledVariantId = currentDataItem.variantId;
420            if (currentDataItem.isOpenPrice && quantityOpenPrice > 0) {
421                changeQuantityServingItemMerchantOS(fieldNameNew, currentDataItem.docId, currentDataItem.productID, currentDataItem.isTrackQuantity, quantityOpenPrice, disabledVariantId);
422            }
423            else {
424                changeQuantityServingItemMerchantOS(fieldNameNew, currentDataItem.docId, currentDataItem.productID, currentDataItem.isTrackQuantity, newItemQuantity, disabledVariantId, currentVariantId);
425            }
426        }, 1000);
427    }
428
429    function checkCartOfMerchantOS(fieldName, currentDataItem, valueChange) {
430        if (currentDataItem == null) {
431            currentDataItem = GetCurrentDataItem(fieldName);
432
433            if (currentDataItem == null) {
434                return false;
435            }
436        }
437
438        let newItemQuantity = currentDataItem.quantity + valueChange;
439
440        if (newItemQuantity < 1) {
441            newItemQuantity = 1;
442        }
443
444        if (newItemQuantity > currentDataItem.oldQuantity
445            && (sectionCartBlock.find(`#item-${fieldName}`).hasClass('item-serving') || currentDataItem.isOpenPrice == true)) {
446
447            let fieldNameNew = `${fieldName}_new`;
448            let variantItemId = checkExistDataNewBlock(currentDataItem);
449
450            if (variantItemId != null && variantItemId != '' && currentDataItem.isOpenPrice == false) {
451                fieldNameNew = variantItemId;
452
453                newItemQuantity = +sectionCartBlock.find(`#item-${fieldNameNew}`).find(`#quantity_of_variant_${fieldNameNew}`).val();
454                newItemQuantity += valueChange;
455            }
456            else {
457                newItemQuantity = 1;
458
459                let cloneBlock = $('<div>').append(sectionCartBlock.find(`#item-${fieldName}`).clone()).html();
460                cloneBlock = cloneBlock.replaceAll('item-serving ', 'item-disabled ')
461                    .replaceAll(fieldName, `${fieldNameNew}`);
462
463                sectionCartBlock.find(`#item-${fieldName}`).parent().append(cloneBlock);
464
465            }
466
467            sectionCartBlock.find(`#item-${fieldNameNew}`).addClass('item-disabled');
468            sectionCartBlock.find(`#item-${fieldNameNew}`).find('.note-edited').hide();
469
470            document.getElementById(`item-${fieldNameNew}`).scrollIntoView({ block: 'nearest', behavior: 'smooth', inline: 'nearest' });
471
472            sectionCartBlock.find(`#btn-minus-${fieldNameNew}`).attr('disabled', true);
473            sectionCartBlock.find(`#btn-plus-${fieldNameNew}`).attr('disabled', true);
474
475            updateCartOfMerchantOS(fieldNameNew, currentDataItem, newItemQuantity);
476        }
477        else {
478            let $itemMinusField = sectionCartBlock.find(`#item-${fieldName}`).find('.btn.btn-number.btn-minus');
479            if (newItemQuantity > 1) {
480                $itemMinusField.removeAttr('disabled');
481            }
482            else {
483                $itemMinusField.attr('disabled', 'disabled');
484            }
485
486            updateCartOfMerchantOS(fieldName, currentDataItem, newItemQuantity); // -1 remove, 0 change, 1 add
487            updateCurrentDataItemChanged(currentDataItem, fieldName, newItemQuantity);
488        }
489
490        return false;
491    }
492
493    function updateCartOfMerchantOS(fieldName, currentDataItem, quantity, isRemove = false) {
494        console.log(fieldName, currentDataItem.quantity, quantity);
495        let isNotExistInList = true;
496        if (myCartProductItems.length > 0) {
497            if (isRemove === true) {
498                let myCartProductItemRemove = myCartProductItems.find(i => i.VariantId == fieldName);
499
500                if (myCartProductItemRemove != null) {
501                    myCartProductItemRemove.Quantity = 0;
502                    myCartProductItemRemove.IsRemove = isRemove;
503
504                    isNotExistInList = false;
505                }
506            }
507            else {
508                let myCartProductItemAdd = myCartProductItems.find(i => i.VariantId == fieldName && i.IsRemove == false);
509
510                if (myCartProductItemAdd != null) {
511                    //if (currentDataItem.quantity == quantity) {
512                    //    let indexToRemove = myCartProductItems.findIndex(i => i.VariantId == fieldName && i.IsRemove == false);
513
514                    //    if (indexToRemove > -1) {
515                    //        myCartProductItems.splice(indexToRemove, 1);
516                    //    }
517                    //}
518                    //else {
519                    //    myCartProductItemAdd.Quantity = quantity;
520                    //}
521
522                    if (currentDataItem.isOpenPrice == true) {
523                        myCartProductItemAdd.Quantity += 1;
524                    }
525                    else {
526                        myCartProductItemAdd.Quantity = quantity;
527                    }
528
529                    isNotExistInList = false;
530                }
531            }
532        }
533
534        if (isNotExistInList) {
535            let variantItemCart = {
536                VariantId: fieldName,
537                Quantity: quantity,
538                IsRemove: isRemove,
539                Id: currentDataItem.docId,
540                ProductId: currentDataItem.productID,
541                IsTrackQuantity: currentDataItem.isTrackQuantity
542            };
543
544            myCartProductItems.push(variantItemCart);
545        }
546
547        updateDataNewBlock(fieldName, quantity);
548
549        delayTimer(function () {
550            console.log('myCartProductItems', myCartProductItems);
551            if (myCartProductItems.length > 0) {
552                changeItemInCartMerchantOS(myCartProductItems);
553            }
554
555        }, 1000);
556    }
557
558    function animateAndWait(positionScrollTo) {
559        return new Promise((resolve) => {
560            const animation = $('body, html').animate(
561                { scrollTop: positionScrollTo },
562                { duration: 200, iterations: 1 }
563            );
564            resolve(animation);
565        });
566    }
567
568    function scrollHorizontal() {
569        let lengthScrollLeft = 0;
570        $menuMobile.each(function () {
571            const currentPosition = $(this).outerWidth() + 10;
572            if ($(this).hasClass("active")) {
573                lengthScrollLeft -= ($(window).outerWidth() - currentPosition) / 2;
574
575                if (lengthScrollLeft < 0) {
576                    lengthScrollLeft = 0;
577                }
578
579                $('#menu-tiles-mobile').animate({ scrollLeft: lengthScrollLeft }, { duration: 100, iterations: 1 });
580                return false;
581            }
582            lengthScrollLeft += currentPosition;
583        });
584    }
585
586    function scrollCategoriesForMerchantOS(targetId) {
587        let scrollPosition = $('#product-grid').find(targetId).offset();
588
589        if (scrollPosition == null) {
590            scrollPosition = $('#product-grid').find(targetId).position();
591        }
592        let productGridScrollTop = $('#product-grid').scrollTop() + scrollPosition.top - 3;
593        $('#product-grid').animate(
594            {
595                scrollTop: productGridScrollTop
596            }, 0, function () {
597                setTimeout(function () {
598                    $('#product-grid').animate({ scrollTop: productGridScrollTop }, 0);
599                }, 50);
600
601                setTimeout(function () {
602
603                    isClick = false;
604                }, 500);
605            }
606        );
607    }
608
609    function initMenuFloating(windowHeight = '') {
610        if (initialMenuFloating === false) {
611            if (windowHeight == '') {
612                windowHeight = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0
612);
613
614                if (windowHeight < 1) {
615                    windowHeight = $(window).height();
616                }
617            }
618
619            let maxHeightCategory = windowHeight - Math.abs(window.innerHeight - document.documentElement.clientHeight);
620            let navMenuLeft = $('#idMenuLeft').width();
621            let productGridWidth = $('#product-grid').width();
622
623            $menuFloating.addClass("position-fixed");
624            $menuFloating.attr("style", `width: ${navMenuLeft + 6}px; max-height: ${maxHeightCategory - 18}px; padding-right: 0;`);
625
626            if ($('body.merchant-os').hasClass('home')) {
627                $('#product-grid').addClass("position-fixed");
628                $('#product-grid').attr("style", `width: ${productGridWidth - 15}px; max-height: ${maxHeightCategory - 18}px;left: -5px;`);
629            }
630
631            initialMenuFloating = true;
632        }
633    }
634
635    function resizeCategoriesForMerchantOS() {
636        let windowHeight = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
637        if (windowHeight < 1) {
638            windowHeight = $(window).height();
639        }
640
641        initMenuFloating(windowHeight);
642
643        let liMenuHeight = 0;
644
645        for (let i = $menuMobile.length; i >= 0; i--) {
646            let $liMenu = $($menuMobile[i]);
647            let targetId = $liMenu.attr('data-href');
648
649            liMenuHeight += $liMenu.innerHeight();
650
651            if ($(targetId).length > 0 && $(targetId).offset().top > 0 && $(targetId).offset().top < windowHeight / 2) {
652                if ($liMenu.hasClass("active")) {
653
654                }
655                else {
656                    $menuMobile.removeClass("active");
657
658                    $liMenu.addClass("active");
659
660                    let scrollPositionTop = menuMobileMaxHeight - liMenuHeight - windowHeight / 2;
661
662                    if (scrollPositionTop < 0) {
663                        scrollPositionTop = 0;
664                    }
665
666                    if ($liMenu.offset().top < 0 || $liMenu.offset().top > (windowHeight + 1) / 4) {
667                        $menuFloating.animate({ scrollTop: scrollPositionTop }, 0);
668                    }
669                }
670
671                return false;
672            }
673        }
674    }
675
676    let oldCurrentNumber = 0;
677    function scrollFloatCategory(heightCategory) {
678        let activeMenuPosition = 0;
679        let currentPosition = 0;
680        for (let i = 0; i < $menuMobile.length; i++) {
681            currentPosition = $menuMobile[i].offsetHeight + 2;
682            activeMenuPosition += currentPosition;
683            if ($menuMobile[i].hasClass("active")) {
684                break;
685            }
686        }
687        const currentNumber = Math.floor(activeMenuPosition / (0.8 * heightCategory));
688        if (oldCurrentNumber !== currentNumber) {
689            oldCurrentNumber = currentNumber;
690            let scrollTop = currentNumber * (0.7 * heightCategory);
691            $menuFloating.animate({ scrollTop }, { duration: 100, iterations: 1 });
692        }
693    }
694
695    $('#product-grid').on("scroll", function () {
696        if (!isClick && typeof isMerchantOS !== 'undefined' && isMerchantOS == true) {
697            resizeCategoriesForMerchantOS();
698        }
699    });
700
701    // Bind to scroll
702    $(window).on("scroll", function () {
703        if (!isClick && typeof isMerchantOS !== 'undefined' && isMerchantOS == true) {
704            //resizeCategoriesForMerchantOS();
705        }
706        else if (!isClick) {
707            if (window.scrollY > 0 && !!templateType && templateType != 4) {
708                $('.menu-iconic-mobile').find('.slide__img').hide();
709                $('.mobile-services').addClass('mobile-services-scroll').css({
710                    'display': 'none'
711                });
712                if (!isBuffet && !isGroupOrdering) {
713                    $('.mobile-menu .branch-name').css('display', 'none');
714                    $('.dropdown-service').addClass('show-dropdown').css({
715                        'display': 'flex'
716                    });
717                }
718            } else {
719                $('.mobile-services').removeClass('mobile-services-scroll').removeAttr('style');
720                $('.menu-iconic-mobile').find('.slide__img').css({
721                    'display': 'flex'
722                });
723                if (!isBuffet && !isGroupOrdering) {
724                    $('.mobile-menu .branch__text.branch-name').removeAttr('style');
725                    $('.mobile-menu .branch-name').css('display', 'flex');
726                    $('.dropdown-service').removeClass('show-dropdown').removeAttr('style');
727                }
728
729                $menuFloating.removeClass("position-fixed");
730                $menuFloating.removeAttr("style");
731            }
732
733
734            if ($(window).width() < 991) {
735                $('#header').height($("#header .header__navbar").height() - 3);
736                document.documentElement.style.setProperty('--scroll-y', `${window.scrollY}px`);
737            }
738            else {
739                $('#header').height($("#header .inner").height() - 3);
740            }
741
742            const headerHeight = $(window).width() < 991 ? $("#header .header__navbar").innerHeight() : $("#header .inner").innerHeight();
743            const windowScroll = $(this).scrollTop();
744
745            if ($headerSlide == null || $headerSlide.length == 0) {
746                $headerSlide = $('#main-slide [data-slider="home-slider"]');
747            }
748
749            const slideHeaderHeight = $headerSlide ? $headerSlide.innerHeight() : 0;
750            const menuItemPosition = !!templateType && templateType == 2 ? slideHeaderHeight : 0;
751            const listIds = menuMobileList.map(function () {
752                if ($(this).position().top + menuItemPosition <= windowScroll + headerHeight + 5)
753                    return this;
754            });
755
756            const currentId = !listIds?.length ? listIds[0] : listIds[listIds.length - 1];
757
758            if (!currentId) return;
759
760            if (listIds.length !== listIdsLength) {
761                listIdsLength = listIds.length;
762                $menuMobile.removeClass("active");
763                $(`[data-href="#${currentId[0].id}"]`).addClass('active');
764                if (!!templateType && templateType !== 2) {
765                    scrollHorizontal();
766                }
767            }
768            if (!!templateType && templateType === 2) {
769                if ($menuFloating.length > 0) {
770                    if (slideHeaderHeight < windowScroll - 40) {
771                        let heightFooter = 0;
772                        const positonFooter = $('#footer').position().top;
773                        if ($(window).scrollTop() + $(window).height() > positonFooter) {
774                            heightFooter = $(window).scrollTop() + $(window).height() - positonFooter;
775                        }
776
777                        let windowHeight = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
778                        if (windowHeight < 1) {
779                            windowHeight = $(window).height();
780                        }
781                        let maxHeightCategory = (windowHeight - headerHeight - heightFooter - Math.abs(window.innerHeight - document.documentElement.clientHeight) - $(".homepage-cart-button-display").innerHeight());
782                        if (maxHeightCategory > 0) {
783                            $menuFloating.addClass("position-fixed");
784                            $menuFloating.attr("style", `top: ${headerHeight + 5}px; width: ${navwidth}px; max-height: ${maxHeightCategory}px;`);
785                        } else {
786                            $menuFloating.removeClass("position-fixed");
787                            $menuFloating.removeAttr("style");
788                        }
789                        scrollFloatCategory(windowHeight - headerHeight - Math.abs(window.innerHeight - document.documentElement.clientHeight) - $(".homepage-cart-button-display").innerHeight());
790                    } else {
791                        $menuFloating.removeClass("position-fixed");
792                        $menuFloating.removeAttr("style");
793                    }
794                }
795            }
796        }
797    });
798});
799
800var slickPromo = {
801    slidesToShow: 1,
802    slidesToScroll: 1,
803    accessibility: false,
804    arrows: true,
805    dots: true,
806    autoplay: true,
807    autoplaySpeed: 5000
808};
809
810function runSlick() {
811    let sliderPromotion = $('.slider-promotion');
812    if ($(window).width() > 767) {
813        if (sliderPromotion.hasClass("slick-initialized slick-slider")) { }
814        else {
815            sliderPromotion.slick(slickPromo);
816        }
817    }
818    else {
819        if (sliderPromotion.hasClass("slick-initialized slick-slider")) {
820            sliderPromotion.slick('unslick');
821            $("#all-item-promotion").html(rowPromotionHtml);
822
823            $("#all-item-promotion").find(".tmp-floating").each(function (i) {
824                $(this).removeAttr("style");
825                if (i > 2) {
826                    $(this).css("display", "none");
827                }
828            })
829        }
830    }
831};
832
833var scrTop = 0;
834$(document).on("click", "#my-cart-count", function () {
835    $("#show-progress-bar-when-add-item").hide().html("");
836    $("#scroll-top").removeAttr("style");
837});
838
839var heightCIB = $(".block-4.cart-info-block.bg-pink").height();
840$(document).on("click", ".collapse-my-cart", function () {
841    let CIB = $(".block-4.cart-info-block.bg-pink");
842    let heightCurrentCIB = CIB.height();
843    if (heightCurrentCIB > 0 && heightCurrentCIB != heightCIB) {
844        heightCIB = heightCurrentCIB;
845    }
846    let OLUS = $(".block-3.order-list.list-unstyled");
847    let heightAPI = $(".all-product-item").height();
848    let heightOL = OLUS.height();
849
850    if (CIB.hasClass("hidden-important")) {
851        CIB.removeClass("hidden-important");
852        $(this).removeClass("fa-expand").addClass("fa-compress");
853        $(".all-product-item").css("height", heightAPI - heightCIB);
854        OLUS.css("height", heightOL - heightCIB);
855    }
856    else {
857        CIB.addClass("hidden-important");
858        $(this).removeClass("fa-compress").addClass("fa-expand");
859        $(".all-product-item").css("height", heightAPI + heightCIB);
860        OLUS.css("height", heightOL + heightCIB);
861    }
862});
863
864var delayTimer = (function () {
865    let timer = 0;
866    return function (callback, ms) {
867        clearTimeout(timer);
868        timer = setTimeout(callback, ms);
869    };
870})();
871
872function initScrollItems(menu) {
873    return menu.map(function () {
874        const item = $($(this).attr("data-href"));
875        if (item.length) { return item; }
876    });
877}

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.