$(function () {
const plan_index_buttons = $('#plan-index-buttons');
const plan_index_main = $('#plan-index-main');
// ãƒã‚§ãƒƒã‚¯æ¸ˆã¿ã®å€¤ã‚’パラメーターåˆã¯cookieã‹ã‚‰å–å¾—ã—ã¦ãƒ—ランã®è¡¨ç¤º
(function() {
let checked_values = [];
// getã§ãƒ‘ラメーターå–å¾—
var parameter = new Object;
url = location.search.substring(1).split('&');
for (i=0; url[i]; i++) {
var k = url[i].split('=');
parameter[k[0]] = k[1];
}
if (parameter.cate) {
switch (parameter.cate) {
case "wedding":
checked_values = ['plan-0'];
break;
case "photo":
checked_values = ['plan-1'];
break;
default:
break;
}
} else if ($.cookie('checked_values')) {
checked_values = $.cookie('checked_values').split(',');
}
// ãƒã‚§ãƒƒã‚¯ãƒœãƒƒã‚¯ã‚¹ã®ãƒã‚§ãƒƒã‚¯çŠ¶æ…‹ã‚’å†ç¾
if (checked_values.length > 0) {
plan_index_buttons.find('input[type="checkbox"]').each(function () {
let value = $(this).val();
if (checked_values.indexOf(value) !== -1) {
$(this).prop('checked', true);
}
});
}
// プランã®è¡¨ç¤º
render(checked_values);
})();
// ãƒã‚§ãƒƒã‚¯ãƒœãƒƒã‚¯ã‚¹ã‚’é¸æŠžã—ãŸæ™‚
plan_index_buttons.find('input[type="checkbox"]').on('change', function () {
let name = $(this).attr('name');
let value = $(this).val();
let checked = $(this).prop('checked');
let checked_values = [];
if (checked) {
if (value === 'all') {
plan_index_buttons.find('input[type="checkbox"][value!="all"]').prop('checked', false);
} else {
plan_index_buttons.find('input[type="checkbox"][value="all"]').prop('checked', false);
}
if (name === 'plan-0') {
if (value === 'plan-0') {
plan_index_buttons.find('input[type="checkbox"][name="plan-0"][value!="plan-0"]').prop('checked', false);
} else {
plan_index_buttons.find('input[type="checkbox"][name="plan-0"][value="plan-0"]').prop('checked', false);
}
}
if (name === 'plan-1') {
if (value === 'plan-1') {
plan_index_buttons.find('input[type="checkbox"][name="plan-1"][value!="plan-1"]').prop('checked', false);
} else {
plan_index_buttons.find('input[type="checkbox"][name="plan-1"][value="plan-1"]').prop('checked', false);
}
}
}
plan_index_buttons.find('input[type="checkbox"]:checked').each(function () {
checked_values.push($(this).val());
});
// プランã®è¡¨ç¤º
render(checked_values);
// ãƒã‚§ãƒƒã‚¯æ¸ˆã¿ã®å€¤ã‚’cookieã«ä¿å˜
$.cookie('checked_values', checked_values.join(','), {
expires: 365
});
history.replaceState('','','/plan/');
});
// プランã®è¡¨ç¤º
function render(checked_values) {
plan_index_main.children().hide();
if (checked_values.length === 0 || checked_values.indexOf('all') !== -1) {
plan_index_main.children().show();
return;
}
$.each(checked_values, function (i, value) {
let target_class = '.' + value;
let found = value.match(/^plan([0-9])+\-cat[0-9]+$/);
if (found) {
target_class = '.plan-' + found[1] + target_class;
}
plan_index_main.find(target_class).show();
});
}
});
// アコーディオンメニュー
$(function(){
$('.accordion').on('click', function() {//タイトルè¦ç´ をクリックã—ãŸã‚‰
var findElm = $(this).next(".accordion-section");//直後ã®ã‚¢ã‚³ãƒ¼ãƒ‡ã‚£ã‚ªãƒ³ã‚’行ã†ã‚¨ãƒªã‚¢ã‚’å–å¾—ã—
$(findElm).slideToggle();//アコーディオンã®ä¸Šä¸‹å‹•作
if($(this).hasClass('close')){//タイトルè¦ç´ ã«ã‚¯ãƒ©ã‚¹åcloseãŒã‚れã°
$(this).removeClass('close');//クラスåを除去ã—
}else{//ãれ以外ã¯
$(this).addClass('close');//クラスåcloseを付与
}
});
});
// //ページãŒèªã¿è¾¼ã¾ã‚ŒãŸéš›ã«openクラスをã¤ã‘ã€openãŒã¤ã„ã¦ã„ãŸã‚‰é–‹ã動作※ä¸å¿…è¦ãªã‚‰ä¸‹è¨˜å…¨ã¦å‰Šé™¤
// $(window).on('load', function(){
// $('.accordion-section').addClass("open"); //accordion-areaã®ã¯ã˜ã‚ã®liã«ã‚ã‚‹sectionã«openクラスを追åŠ
// $(".open").each(function(index, element){ //openクラスをå–å¾—
// var Title =$(element).children('.accordion'); //openクラスã®åè¦ç´ ã®titleクラスをå–å¾—
// $(Title).addClass('close'); //タイトルã«ã‚¯ãƒ©ã‚¹åcloseを付与ã—
// var Box =$(element).children('.accordion-section'); //openクラスã®åè¦ç´ boxクラスをå–å¾—
// $(Box).slideDown(500); //アコーディオンを開ã
// });
// });