Loading...

` ); } const merchantDiv = (merchant, next = false) => { var mc_logo = merchant.logo || ""; var mc_main_image = merchant['logo-2'] || merchant.image; if(mc_logo=="" && merchant['logo-1']){ mc_logo = merchant['logo-1']; } if(mc_logo=="" && merchant['logo-2']){ mc_logo = merchant['logo-2']; } if( merchant.id!="MC39IPAIQM" && merchant.id!="MC2M2FVINA" && merchant.id!="MCAQDLUV1Z" && merchant.id!="MC2RB1GB13" && merchant.id!="MCYZBDHPSB" && merchant.id!="MCGC1ZUBF7" && merchant.id!="MCEI6VQXIC"){ // encryp merchant id to base64 string var mcid = btoa(merchant.id); var same = false; // find duplicate attribute mc in brand-card-outer then remove it if(next){ $(".brand-card-outer").each(function(){ if($(this).attr('mc')==mcid){ same = true; } }); } if(same){ return ''; } //check every class brand-card-outer have attribute mc return ( `
${merchant.name}
${merchant.name}
VIEW MORE
` ); }else{ return ''; } } const layout2 = (items, label)=>{ // draw layout2 var html_result = ''; if(items.length == 0){ html_result += '

We\'re sorry. We cannot find any gift matches with your search criteria.

Click here to clear your search filter.

You may also like:

'; items = products.splice(0,6); } // loop products item var products_html = '
'; if($("#txtKeyword").val()){ products_html += ``; } tempItemsNotLoaded = []; var itemsToShow = [...items]; if(showBy === 'brand'){ let arrMerchantId = []; let arrMerchant = []; for(let ii of items){ if(!arrMerchantId.includes(ii.merchant.id)){ arrMerchant.push(ii.merchant); arrMerchantId.push(ii.merchant.id); } } // console.log('merchant', arrMerchant) items = arrMerchant; } // if(items.length >= 24){ // tempItemsNotLoaded = items.slice(24); // itemsToShow = items.slice(0,24); // }else{ tempItemsNotLoaded = []; itemsToShow = items; // } itemsToShow.forEach(item => { products_html += (showBy === 'brand' ? merchantDiv(item) : productDiv(item)); }); products_html += '
'; let btnLoadAll = `

`; if(products.length === items.length){ btnLoadAll = ''; } var type_layout = `
${ products_html } ${ btnLoadAll }
`; html_result += type_layout; $("#search_result").html(html_result); $(window).lazyLoadXT(); } const clearFilter = ()=>{ $("#txtKeyword").val(''); $('[type=checkbox]').prop('checked', false); counterModal(); sliderBudget.slider('setValue',[productsMinPrice, productsMaxPrice]); sliderBudgetModal.slider('setValue',[productsMinPrice, productsMaxPrice]); selected_url = 'https://giftano.com/search-gifts'; $("#scTopPage").slideUp(); render(); } const showTag = (tag, custom_url = null) => { $('[type=checkbox]').prop('checked', false); $('[value='+ tag +']').prop('checked', true); counterModal(); if(custom_url){ selected_url = custom_url; }else{ selected_url = 'https://giftano.com/search-gifts'; } $("#scTopPage").slideUp(); render(); } window.onpopstate = function(event){ if(event.state && event.state.type){ $('[type=checkbox]').prop('checked', false); let arr_tag = ['type','category','occasion','to_whom']; arr_tag.forEach(tName => { if(event.state[tName]){ event.state[tName].forEach(tVal => { $('.checkbox-'+ tName +'[value=' + tVal + ']').prop('checked', true); $('.checkbox-'+ tName +'-modal[value=' + tVal + ']').prop('checked', true); }); } }); counterModal(); if(event.state.budget){ sliderBudget.slider('setValue', event.state.budget); sliderBudgetModal.slider('setValue', event.state.budget); } render(false); } } let loadingOnScroll = false; let scrollTimeout; window.addEventListener('scroll', async () => { // clearTimeout(scrollTimeout); // scrollTimeout = setTimeout(() => { const { scrollTop, scrollHeight, clientHeight } = document.documentElement; const footerTop = $("#footer").offset().top; const productBoxHeight = $(".product-box").height(); const footerBottom = footerTop - clientHeight; let qrString = $("#scFilter").attr('qry'); let from = parseInt($("#scFilter").attr('from')); let size = parseInt($("#scFilter").attr('size')); let total = parseInt($("#scFilter").attr('total')); if ((scrollTop >= footerBottom - (2*productBoxHeight)) && products.length > 0 && !loadingOnScroll && qrString !== undefined && (from + size) < total) { // let scrollId = $("#scFilter").attr('scrollId'); // $("#loading-data").removeClass('hide'); loadingOnScroll = true; let qsJson; if(qrString === undefined || qrString === ''){ qrString = '{}'; } qsJson = JSON.parse(qrString); qsJson.from = from + size; let resElastic = await callElasticSearch(qsJson); $("#scFilter").attr('from', from + size); $("#scFilter").attr('qry', JSON.stringify(qsJson)); loadingOnScroll = false; //add class hide $("#loading-data").addClass('hide'); if(resElastic && resElastic.hits && resElastic.hits.hits){ if(resElastic.hits.total && resElastic.hits.total.value){ $("#scFilter").attr('total', resElastic.hits.total.value); } result = resElastic.hits.hits.map(h => { if(h._source.data) { return h._source.data}; return h._source; }); if (result.length > 0) { products.push(...result); let wkey = $("#scFilter").attr('withKeyword') let containsSoldOut = result.filter(function (el) { return el.sold_out == '1'; }); if(wkey && wkey == 0 && containsSoldOut.length < 1){ fy(result); } adddatatolayout(result); } } } // else { // console.log('scroll not working =>qrString: '+qrString+" - from: "+from+"- Size: "+size+" -Total: "+total, loadingOnScroll); // } }, { passive: true }); const adddatatolayout = (items)=>{ // loop products item var products_html = ''; if($("#txtKeyword").val()){ products_html += ``; } tempItemsNotLoaded = []; var itemsToShow = [...items]; if(showBy === 'brand'){ let arrMerchantId = []; let arrMerchant = []; for(let ii of items){ if(!arrMerchantId.includes(ii.merchant.id)){ arrMerchant.push(ii.merchant); arrMerchantId.push(ii.merchant.id); } } // console.log('merchant', arrMerchant) items = arrMerchant; } // if(items.length >= 24){ // tempItemsNotLoaded = items.slice(24); // itemsToShow = items.slice(0,24); // }else{ tempItemsNotLoaded = []; itemsToShow = items; // } itemsToShow.forEach(item => { products_html += (showBy === 'brand' ? merchantDiv(item, true) : productDiv(item)); }); //append layout_2 with child class search-result-box $("#layout_2 > .search-result-box > .row").append(products_html); $(window).lazyLoadXT(); } const moveBack = () => { if(appHistory.length>1){ appHistory.pop(); let curr_state = appHistory[appHistory.length-1].state; $('[type=checkbox]').prop('checked', false); let arr_tag = ['type','category','occasion','to_whom']; arr_tag.forEach(tName => { if(curr_state[tName]){ curr_state[tName].forEach(tVal => { $('.checkbox-'+ tName +'[value=' + tVal + ']').prop('checked', true); $('.checkbox-'+ tName +'-modal[value=' + tVal + ']').prop('checked', true); }); } }); counterModal(); if(curr_state.budget){ sliderBudget.slider('setValue', curr_state.budget); sliderBudgetModal.slider('setValue', curr_state.budget); } render(false); } } // add to fix hiw modal $('a[data-target="#mdlHIW"]').click(function(){ $("#mdlHIW").modal('show'); }); function delay(callback, ms) { var timer = 0; return function() { var context = this, args = arguments; clearTimeout(timer); timer = setTimeout(function () { callback.apply(context, args); }, ms || 0); }; } $("#txtKeyword").keyup(function(){ selected_url = 'https://giftano.com/search-gifts'; $("#scTopPage").slideUp(); render(); }); $("#btnClearCategory").click(function(){ $('.checkbox-category, .checkbox-category-modal').prop('checked', false); $('.checkbox-occasion, .checkbox-occasion-modal').prop('checked', false); $('[value=]').prop('checked', true); counterModal(); render(); $("#modalFilterCategory").modal('hide'); }); $("#btnClearToWhom").click(function(){ $(".checkbox-to_whom, .checkbox-to_whom-modal").prop('checked', false); $('[value=]').prop('checked', true); counterModal(); render(); $(this).closest('.dropdown-menu').parent().toggleClass('open'); }); $("#btnClearType").click(function(){ $(".checkbox-type, .checkbox-type-modal").prop('checked', false); $('[value=]').prop('checked', true); counterModal(); render(); $(this).closest('.dropdown-menu').parent().toggleClass('open'); }); $("#btnApplyToWhom, #btnApplyType, #btnApplyPrice").click(function(){ $(this).closest('.dropdown-menu').parent().toggleClass('open'); }); $("#btnApplyPrice").click(function(){ render(); }); $("#btnClearPrice").click(function(){ sliderBudget.slider('setValue',[productsMinPrice, productsMaxPrice]); sliderBudgetModal.slider('setValue',[productsMinPrice, productsMaxPrice]); $("#inputBudgetMin, #inputBudgetMinModal").val(productsMinPrice); $("#inputBudgetMax, #inputBudgetMaxModal").val(productsMaxPrice); render(); }); $("#btnKeyword").click(function(){ if($("#txtKeyword").val()){ $("#txtKeyword").val(''); selected_url = 'https://giftano.com/search-gifts'; render(); } }); // $(window).scroll(function(){ // let scrollY = window.scrollY; // let layoutEl = $('#layout_2'); // let needToLoadMorePos = (layoutEl.offset().top + layoutEl.outerHeight()) - window.outerHeight - 500; // if(scrollY >= needToLoadMorePos && tempItemsNotLoaded.length > 0){ // // load next 12 // let nextItems = tempItemsNotLoaded.slice(0, 12); // tempItemsNotLoaded = tempItemsNotLoaded.slice(12); // nextItems.forEach(item => { // $('#layout_2 > .search-result-box > .row').append(showBy === 'brand' ? merchantDiv(item) : productDiv(item)); // }); // $(window).lazyLoadXT(); // } // }) -->