function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; } $(function() { //フィルター $("#ncat_bt_area a").attr("href", "javascript:void(0)"); $("#ncat_bt_area a").on("click", function() { filterNews($(this).parent().attr("id").replace("ncbt_", "")); return false; }); //ニュース一覧クリック時 $("#news_all_block dl a").on("click", function() { $("#news_all_block dt").removeClass("news_active"); $("#news_all_block dd").removeClass("news_active"); $(this).parentsUntil("#news_all_block", "dd").addClass("news_active"); $(this).parentsUntil("#news_all_block", "dd").prev("dt").addClass("news_active"); document.getElementById("news_body").src = $(this).attr("href"); return false; }); //ニュース一覧フィルター用クラス付加 var classList = {"nc_info":"info","nc_oa":"onair","nc_story":"story","nc_event":"event","nc_goods":"goods","nc_sp":"special"}; $("#news_all_block dd").each(function(index) { for(var key in classList) { if($("span", this).hasClass(key)) { $(this).addClass("news_type_"+classList[key]); $(this).prev("dt").addClass("news_type_"+classList[key]); break; } } }); $(window).on("load", function() { var urlVars = getUrlVars(); if(urlVars["key"] && urlVars["key"].length > 0) { receiveKey = decodeURIComponent(urlVars["key"]); $("#news_all_block dl a").each(function() { var aHref = $(this).attr("href"); var fileParam = aHref; var index = fileParam.lastIndexOf("/"); if(index >= 0) { fileParam = fileParam.substring(index); } if(fileParam == receiveKey) { $(this).parentsUntil("#news_all_block", "dd").addClass("news_active"); $(this).parentsUntil("#news_all_block", "dd").prev("dt").addClass("news_active"); document.getElementById("news_body").src = aHref; return false; } }); } else { var targetObj = $("#news_all_block dl a:first"); var nextHref = targetObj.attr("href"); document.getElementById("news_body").src = nextHref; targetObj.parentsUntil("#news_all_block", "dd").addClass("news_active"); targetObj.parentsUntil("#news_all_block", "dd").prev("dt").addClass("news_active"); } }); }); function filterNews(type) { $("#news_all_block dt").stop().fadeOut(200); $("#news_all_block dd").stop().fadeOut(200); $("#news_all_block").stop().delay(200).fadeIn(0, function() { if(!type || type == "" || type == "all") { $("#news_all_block dt").fadeIn(200); $("#news_all_block dd").fadeIn(200); } else { $("#news_all_block .news_type_"+type).fadeIn(200); } }); }