$(function(){ window.addEventListener('popstate', function(e) { console.log(location.pathname); var pathname = location.pathname; var regexp = /waitingforyou\/(.*)\//g; var result = regexp.exec(pathname); var homen = ''; if ( result !== null ){ homen = result[1]; } $('#homen_select').val(homen); callAPI(); }); $('#homen_select').on('change',function(){ var hisPath = ''; if ( $('#homen_select').val() ){ hisPath = $('#homen_select').val()+'/'; } history.pushState('','','/feature/waitingforyou/'+hisPath); callAPI(); }); var callAPI = function(){ $.ajax({ type: "POST", url:"/news/local_news_api.html", data: { homen:$('#homen_select').val(), api_mode:1 }, dataType:'json', success: function (j_Data){ console.log('j_data'); console.log(j_Data); var tabName; var cate_4,cate_6,cate_99 = false; $.each(j_Data,function(idx,val){ if ( idx == 4 ){ tabName = "TAB01"; cate_4 = true; } if ( idx == 6 ){ tabName = "TAB02"; cate_6 = true; } if ( idx == 99 ){ tabName = "TAB03"; cate_99 = true; } if ( idx == 4 || idx == 6 ){ $('[id^='+tabName+']').next('label').next('div').children('.tab-content_wrap').html(''); } if ( idx == 99 ){ $('#info03').find('.tab-content_wrap').html(''); } createTabs(idx,val,tabName); }); var homen_link = ""; if ( $('#homen_select').val() ){ homen_link = '&homen='+$('#homen_select').val(); } if ( cate_4 === true ){ $('#info01').show(); $('#info01_link').attr('href',"/news/?n_or_i=l&category=4"+homen_link); }else{ $('#info01').hide(); } if ( cate_6 === true ){ $('#info02').show(); $('#info02_link').attr('href',"/news/?n_or_i=l&category=6"+homen_link); }else{ $('#info02').hide(); } if ( cate_99 === true ){ $('#info03').show(); //$('#info03_link').attr('href',local_news_link); }else{ $('#info03').hide(); } } }); } var createTabs = function(cate,val,tabName){ console.log('create tabs'); console.log('cateno:'+cate); console.log(val); var subcates = []; if ( cate == 4 ){ subcates = [1,2,3,4,9]; } if ( cate == 6 ){ subcates = [1,2,3]; } if ( cate == 99 ){ subcates = [0]; } var visibled = false; for ( var s = 0; s < subcates.length; s++ ){ var subcate = subcates[s]; console.log('chk_subcate:'+subcate); $('#'+tabName+'-0'+subcate).prop('checked',false); if ( val[subcate] ){ console.log(val[subcate]); $('#'+tabName+'-0'+subcate).next('label').show(); if ( visibled === false ){ $('#'+tabName+'-0'+subcate).next('label').click(); visibled = true; } createNewsList(tabName,cate,subcate,val[subcate]); }else{ $('#'+tabName+'-0'+subcate).next('label').hide(); } } } var createNewsList = function(tabName,cate,subcate,ndata){ var news_list = ''; var subcate_list = {}; if ( cate == 4 || cate == 99 ){ subcate_list = { 1:'入国情報(行動制限など)', 2:'航空会社', 3:'観光地', 4:'ホテル', 9:'その他' }; } if ( cate == 6 ){ subcate_list = { 1:'出発前の注意点', 2:'現地での注意点', 3:'帰国後の注意点' }; } console.log(subcate_list); $.each(ndata,function(idx,val){ if ( idx < 5 ){ news_list += ''; news_list += '
'; news_list += ''; news_list += '
'; news_list += '

'+val.postdate+'

'; news_list += '

'+val.homenname+'


'; if ( cate != 99 ){ news_list += '

'+subcate_list[val.subcategory]+'

'; } news_list += '
'; news_list += '
'; news_list += '

'+val.title+'

'; news_list += '
'; } }); if ( cate != 99 ){ $('#'+tabName+'-0'+subcate).next('label').next('div').children('.tab-content_wrap').html(news_list); }else{ $('#info03').find('.tab-content_wrap').html(news_list); } } callAPI(); });