//全域變數 let areaCount = 0; let areaNoNumber = 0; function escapeRegEx(s) { return s.replace(/[-\/\\^$*+?.()|[\]{}=]/g, '\\$&'); } function setThemeNewBase(){ $('.gs').off().on('click',function(event){ var aHref=escapeRegEx($(this).attr('href')), anchorTarget=$(aHref); if(1<=anchorTarget.length){ event.preventDefault(); var headerH=$('#topBox').height(); $('html, body').stop().animate({ scrollTop: anchorTarget.offset().top-headerH-20 }, 250); } }); } function bannerCheck(){ var bTarger=$('video.bannersact'); if(1<=bTarger.length){ $('.ilightbox').iLightBox({ type:'video', skin:'metro-black', overlay:{ blur:false, opacity:0.9 }, callback: { onShow: function(api) { $('video').attr('controlsList','nodownload'); } } }); } } // 評價 function setEvaluation(){ // 簡述 / 補充說明 $('.themeTxt .morebtn,.replenish .repText .hts .morebtn').on('click',function(event){ event.preventDefault(); $(this).hide(); $(this).parent().animate({'max-height': '100%'}, "slow"); }); if( !!$("#scoreSendForm").length ){ // 評價(瀑布) //第一次載入評分 $("div.tabDatasNo").hide(); // 查無資料 $("form#scoreSendForm #pageNo").val('0'); $("form#scoreSendForm #pageType").val('down'); $("form#scoreSendForm #gotoPageNo").val('0'); $("form#scoreSendForm #showMoreStatus").val('YES'); function getScoreListCon(pageType,gotoPageNo){ $("form#scoreSendForm #pageType").val(pageType); $("form#scoreSendForm #gotoPageNo").val(gotoPageNo); $.ajax({ type: "POST", url: "/ajax/show_theme_score_list.php", data: $("#scoreSendForm").serialize(), dataType: "json", cache: false, success: function(data) { if(data['totalPage'] == "0"){ $("div.aline").hide(); $("div.tabDatasNo").show(); $("div.evaluate").hide(); } if(data['updatePage'] != "YES"){ if( undefined != data['scorelist'] ){ $.each(data['scorelist'],function(idx,ival){ $('.evaluation_box .mores').before('
\
\ '+ival['travelSubject']+'\
'+ival['travelScoreCon']+'
\
\
\
'+ival['userName']+',
\
'+ival['sendDate']+'
\
\
\
'+ival['scoreShow']+'
\
\
\
\
'); }); } $('form#scoreSendForm #pageNo').val(data['pageNo']); $('form#scoreSendForm #showMoreStatus').val(data['showMore']); if(data['showMore'] == "NO"){ $('.evaluation_box .mores .mbox .btns').hide(); //$("div.tables div.moreboxs").hide(); } }else{ $('.evaluation_box .mores .mbox .btns').hide(); //$("div.tables div.moreboxs").hide(); } }, error: function(msg){ alert("系統發生錯誤,請稍後再試!"); } }); } getScoreListCon('down',''); $('.evaluation_box .mores .mbox .btns').on('click',function(event){ event.preventDefault(); getScoreListCon('down',''); }); } } function setMasonryEffect(){ $.each($('[data-target=masonry]'),function(idx,ival){ var dataTarget=$(this); var dataId=dataTarget.attr('data-id'); var dataType=dataTarget.attr('data-type'); var dataForm=$('form[name=sendForm][data-id='+dataId+']'); var moreBtn=$(this).parent().siblings('.textCenter').children('.moreList'); dataTarget.addClass('masonry_type'); dataTarget.siblings('.btnleft').hide(); dataTarget.siblings('.btnright').hide(); dataTarget.prop('data-total',0); // 更多 按鈕 moreBtn.css('display','block'); moreBtn.on('click',function(event){ event.preventDefault(); getListCon(dataTarget,dataForm,dataType,dataId); }); getListCon(dataTarget,dataForm,dataType,dataId,null); }); } var page_divice=''; function setThemeSlick(){ //尺寸判斷 function returnDivice(){ return 768>window.innerWidth?"mobile":"pc"; } page_divice=returnDivice(); $(window).resize(function(){ if(page_divice!=returnDivice()){ // console.log( "更換尺寸了===>"+page_divice ); page_divice=returnDivice(); setSlickEffect(page_divice); } }); // 建立輪播 function setSlickEffect(){ $.each($('[data-target=slick]'),function(idx,ival){ areaCount++; }); console.log("each:::"+areaCount); $.each($('[data-target=slick]'),function(idx,ival){ var dataTarget=$(this); var dataId=dataTarget.attr('data-id'); var dataType=dataTarget.attr('data-type'); var dataForm=$('form[name=sendForm][data-id='+dataId+']'); // 建立左右箭頭(首次) var btnleft=dataTarget.siblings('.btnleft'); var btnright=dataTarget.siblings('.btnright'); if(!btnleft.attr('class').match(/btnComplete/g)){ btnleft.addClass('btnComplete').on('click',function(event){ event.preventDefault(); if(0==dataTarget.find('.slick-active').first().attr('data-slick-index')){ // 第一筆時, 要滾到最後一筆 dataTarget.slick('slickGoTo',dataTarget.find('.slick-slide').last().attr('data-slick-index')); }else if(!$(this).attr('class').match(/slick_lock/g)){ dataTarget.slick('slickPrev'); } }); btnright.addClass('btnComplete').on('click',function(event){ event.preventDefault(); if( dataTarget.find('.slick-active').last().attr('data-slick-index')==dataTarget.find('.slick-slide').last().attr('data-slick-index') ){ // 到底部, 要倒回第一筆 dataTarget.slick('slickGoTo',0); }else{ dataTarget.slick('slickNext'); } }); } // 重置 資訊 if('pc'==page_divice){ // console.log( 'PC建立Slick' ); var slickNum=(1==dataType)?4:5; dataForm.children("[name=data_device]").val('pc'); dataTarget.children().remove(); // 移除內容 dataTarget.slick({ arrows:false, autoplay:false, dots:false, infinite:false, swipe:false, draggable:false, focusOnSelect: false, //多顯示時,點選後滑動至該項目 swipeToSlide: false, //True:滑動 / False:跑馬燈 accessibility: true, //Enables tabbing and arrow key navigation speed:250, autoplaySpeed:5000, slidesToShow: slickNum, slidesToScroll: slickNum }); }else{ // console.log( 'Mobile打掉Slick,重新載入全部資料' ); dataForm.children("[name=data_device]").val('mb'); if(dataTarget.attr('class').match(/slick-initialized/g)){ // 移除Slick dataTarget.slick('unslick'); dataTarget.children().remove(); // 移除內容 } } if( undefined===tempListCon[dataId] ){ // 延遲載入用 tempConTimeInterval[idx]=new Object(); tempConTimeInterval[idx].dataTarget=dataTarget; tempConTimeInterval[idx].dataForm=dataForm; tempConTimeInterval[idx].dataType=dataType; tempConTimeInterval[idx].dataId=dataId; tempConTimeInterval[idx].status=false; if(0==idx){ tempConTimeInterval[idx].status=true; getListCon(dataTarget,dataForm,dataType,dataId); } }else{ getListCon(dataTarget,dataForm,dataType,dataId); } }); } setSlickEffect(); } function checkNextGetListCon(){ for(var i=0;i'+i+' / '+(tempConTimeInterval.length-1) ); // 檢查 延遲載入 動作 是否執行 tempConTimeInterval[i].status=true; getListCon(tempConTimeInterval[i].dataTarget,tempConTimeInterval[i].dataForm,tempConTimeInterval[i].dataType,tempConTimeInterval[i].dataId); return false; } } } var tempListCon=new Array(), // 暫存載入資訊 tempConTimeInterval=new Array(); // 延遲載入 ajax function getListCon(dataTarget,dataForm,dataType,dataId,dataGetAll){ var dataTargetType=dataTarget.attr('data-target'); // 區塊類型 ( 活動 / 攻略) if('slick'==dataTargetType){ if(true==dataGetAll){ dataForm.children('[name=data_getall]').val(dataGetAll); }else{ dataForm.children('[name=data_getall]').val(false); } if( undefined===tempListCon[dataId] ){ // 首次 進入 先讀取 後暫存資料 $.ajax({ type: "POST", //url: "/ajax/show_theme_list.php", url: "/ajax/ajax_theme_new.php", data: dataForm.serialize(), dataType: "json", cache: false, success: function(data){ areaNoNumber++; //計算目前第幾區 if(((4==data['list'].length)&&(1==dataType))|((5==data['list'].length)&&(2==dataType))) dataTarget.siblings('.btnComplete').addClass('btnDisabled').attr("disabled", "disabled").off('click').on('click',function(event){event.preventDefault();}); appendTemplete(dataTarget,dataForm,dataType,dataId,data['list']); // 塞資料 (產生區塊 並 放置資料) tempListCon[dataId]=data['list']; // 暫存 checkNextGetListCon(); if(data['dataLayerGA4Status']){ //產出DataLayer (20230518 ADD) dataLayer = window.dataLayer || []; dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object. dataLayer.push(data['dataLayerGA4']); //console.log("%%dataLayerGA4:::"+JSON.stringify(data['dataLayerGA4'])); } if(areaNoNumber >= areaCount){ //回填AsisYo的金額 getAsiaYoNoPriceByforeach('theme', 'AsiaYoPrice2'); } }, error:function(msg){ alert("系統發生錯誤,請稍後再試!"); } }); }else{ appendTemplete(dataTarget,dataForm,dataType,dataId,tempListCon[dataId]); } }else{ dataForm.children("[name=data_device]").val('pc'); if( undefined===tempListCon[dataId] ){ // 首次 進入 先讀取 後暫存資料 $.ajax({ type: "POST", url: "/ajax/ajax_theme_new.php", data: dataForm.serialize(), dataType: "json", cache: false, success: function(data){ //console.log(data['masonry_nomore']); areaNoNumber++; //計算目前第幾區 if(((4==data['list'].length)&&(1==dataType))|((5==data['list'].length)&&(2==dataType))) dataTarget.siblings('.btnComplete').addClass('btnDisabled').attr("disabled", "disabled").off('click').on('click',function(event){event.preventDefault();}); //if(true==data['masonry_nomore']) if(12>=data['list'].length) dataTarget.parent().siblings('.textCenter').children('.moreList').hide(); appendTemplete(dataTarget,dataForm,dataType,dataId,data['list']); // 塞資料 (產生區塊 並 放置資料) tempListCon[dataId]=data['list']; // 暫存 checkNextGetListCon(); if(data['dataLayerGA4Status']){ //產出DataLayer (20230518 ADD) dataLayer = window.dataLayer || []; dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object. dataLayer.push(data['dataLayerGA4']); //console.log("%%dataLayerGA4:::"+JSON.stringify(data['dataLayerGA4'])); } if(areaNoNumber >= areaCount){ //回填AsisYo的金額 getAsiaYoNoPriceByforeach('theme', 'AsiaYoPrice2'); } }, error:function(msg){ alert("系統發生錯誤,請稍後再試!"); } }); }else{ appendTemplete(dataTarget,dataForm,dataType,dataId,tempListCon[dataId]); } } } function appendTemplete(dataTarget,dataForm,dataType,dataId,dataList){ // 塞資料 (slick / 瀑布 / HTML) var dataTargetType=dataTarget.attr('data-target'); if('slick'==dataTargetType){ var templete=returnTemplete(dataTargetType,dataType,dataList); // 全部新增 if("pc"==page_divice){ $.each(templete,function(idx,ival){ dataTarget.slick('slickAdd','
'+ival+'
'); // 增加 slck 資料 }); }else{ dataTarget.append( templete ); } if(2==dataType){ // 功略, ajax蒐圖後取代預設圖片(v211216) var dataTargetItem=dataTarget.find('.rgs[data-picturesearch=true]'); if(0
'); // setTimeout(function(){clickTarget.addClass('show_loader');},50); // searchPicture(this,$(this).attr('href')); //}); if($(this).attr('data-check') == 'N'){ var clickTarget=$(this); clickTarget.addClass('loader'); clickTarget.children('.imgs').append('
'); setTimeout(function(){clickTarget.addClass('show_loader');},50); searchPicture(this,$(this).attr('href'),$(this).attr('data-orgpic')); } } }); } } }else{ //console.log(templete); // 瀑布 var tempCount=0, tempPathNum=12, tempNowNum=dataTarget.children().length, tempMaxData=dataList.length, tempDataList=new Array(), templete=''; // 計算並整理此次的瀑布 $.each(dataList,function(idx,ival){ if((idx>=tempNowNum) && (tempCount'; }); if(true==ival['onsale']) tempOnSale='
'+ival['coupon_word_slogan']+'
'; var show_type1 = ''; var show_type2 = ''; if(ival['score_average'] <= 0){ show_type1 = 'style="opacity: 0;"'; } if(ival['score_counter'] <= 0){ show_type2 = 'style="opacity: 0;"'; } var show_money_sale = ''; var show_money = ''; var show_money_div = ''; if(true==ival['show_money_sale']){ show_money_sale = '
'+ival['money_sale']+'
'; show_money = '
'+ival['money']+'
'; }else{ show_money = '
'+ival['money']+'
'; } if('AsiaYo'==ival['tp_type']){ show_money_div = '
'+show_money_sale+'
'; // }else{ show_money_div = '
'+show_money_sale+'
TWD
'+show_money+'
'; } tempGrid='
\ '+tempOnSale+'\
\
\

'+ival['title']+'

\
'+tempSorts+'
\
\
\
'+ival['score_average']+'
\
('+ival['score_counter']+')
\
\
\
\
\
'+ival['map_name']+'
\
\ '+show_money_div+'\
\
\
\
'; //console.log(tempGrid); ifSwitch?returnTemp.push(tempGrid):returnTemp+=tempGrid; }); }else{ // 攻略 $.each(tempData,function(idx,ival){ var tempGrid=''; tempGrid='
\ \
\
'+ival['title']+'
\
\
'; ifSwitch?returnTemp.push(tempGrid):returnTemp+=tempGrid; }); } return returnTemp; } bannerCheck(); setThemeSlick(); setMasonryEffect(); setEvaluation(); setThemeNewBase();