; var Zutsu = Zutsu || {}; $(function() { Zutsu.init = function() { $.cookie.json = true; Zutsu.deviceCheck(); Zutsu.sns(); Zutsu.spMenu(); Zutsu.nav(); Zutsu.contentNav(); Zutsu.qaList(); Zutsu.modal(); Zutsu.migrageQA(); Zutsu.clusterQA(); Zutsu.impactTest(); Zutsu.searchClinic(); Zutsu.youtube(); Zutsu.resize(); Zutsu.nospPages(); }; Zutsu.nospPages = function() { // console.log(Zutsu.device); if(Zutsu.device == 'sp') { if((location.href).indexOf('/wallpaper') != -1 || (location.href).indexOf('/link') != -1 || (location.href).indexOf('/sitemap') != -1) location.href = '/'; if((location.href).indexOf('404') != -1) $('#contents #footer-content').hide(); } }; Zutsu.impactTest = function() { countRender = function() { var count = [0, 0, 0, 0, 0]; var index = []; index[0] = $(':checkbox[name="impact-q1"]').index($(':checkbox[name="impact-q1"]:checked')); index[1] = $(':checkbox[name="impact-q2"]').index($(':checkbox[name="impact-q2"]:checked')); index[2] = $(':checkbox[name="impact-q3"]').index($(':checkbox[name="impact-q3"]:checked')); index[3] = $(':checkbox[name="impact-q4"]').index($(':checkbox[name="impact-q4"]:checked')); index[4] = $(':checkbox[name="impact-q5"]').index($(':checkbox[name="impact-q5"]:checked')); index[5] = $(':checkbox[name="impact-q6"]').index($(':checkbox[name="impact-q6"]:checked')); for (var i = 0, length = index.length; i < length; i++) { if (index[i] != -1) { count[index[i]] += calcScore(index[i]); } } for (var i = 0, length = index.length; i < length; i++) { $($('.score-count .count')[i]).text(count[i]); } }; calcScore = function(num) { if (num == -1) return 0; if (num == 0) return 6; if (num == 1) return 8; if (num == 2) return 10; if (num == 3) return 11; if (num == 4) return 13; } countRender(); $('.check-button.impact').addClass('disabled'); $(':checkbox[name="impact-q1"]').on('click', function(evt) { if (!$(this).prop('checked')) { $(':checkbox[name="impact-q1"]').prop('checked', false); } else { $(':checkbox[name="impact-q1"]').prop('checked', false); $(this).prop('checked', true); countRender(); } }); $(':checkbox[name="impact-q2"]').on('click', function() { if (!$(this).prop('checked')) { $(':checkbox[name="impact-q2"]').prop('checked', false); } else { $(':checkbox[name="impact-q2"]').prop('checked', false); $(this).prop('checked', true); countRender(); } }); $(':checkbox[name="impact-q3"]').on('click', function() { if (!$(this).prop('checked')) { $(':checkbox[name="impact-q3"]').prop('checked', false); } else { $(':checkbox[name="impact-q3"]').prop('checked', false); $(this).prop('checked', true); countRender(); } }); $(':checkbox[name="impact-q4"]').on('click', function() { if (!$(this).prop('checked')) { $(':checkbox[name="impact-q4"]').prop('checked', false); } else { $(':checkbox[name="impact-q4"]').prop('checked', false); $(this).prop('checked', true); countRender(); } }); $(':checkbox[name="impact-q5"]').on('click', function() { if (!$(this).prop('checked')) { $(':checkbox[name="impact-q5"]').prop('checked', false); } else { $(':checkbox[name="impact-q5"]').prop('checked', false); $(this).prop('checked', true); countRender(); } }); $(':checkbox[name="impact-q6"]').on('click', function() { if (!$(this).prop('checked')) { $(':checkbox[name="impact-q6"]').prop('checked', false); } else { $(':checkbox[name="impact-q6"]').prop('checked', false); $(this).prop('checked', true); countRender(); } }); $(':checkbox').on('click', function() { var length = $(':checkbox:checked').length; if (length == 6) { $('.alert-text').css('opacity', '.05'); $('.impact .check-button').removeClass('disabled'); } else { $('.alert-text').css('opacity', '1'); $('.impact .check-button').addClass('disabled'); $('.score-box').hide(); $('.search-intro').hide(); } }); $('.impact .check-button').on('click', function() { if ($(':checkbox:checked').length != 6) return; $('.score-box').show(); $('.search-intro').show(); var score = 0; for (var i = 0, length = $(':checkbox:checked').length; i < length; i++) { score += +$($(':checkbox:checked')[i]).val(); }; $('.score-box .value').text(score); $('.low, .middle, .high').hide(); if (score < 50) { $('.low').show(); } else if (score < 56) { $('.middle').show(); } else if (56 <= score) { $('.high').show(); } }); $('.impact .clear-button').on('click', function() { $(':checkbox').prop('checked', false); $('.alert-text').css('opacity', '1'); $('.impact .check-button').addClass('disabled'); $('.score-box').hide(); $('.search-intro').hide(); countRender(); }); }; Zutsu.migrageQA = function() { $('.q1 .yes-button').on('click', function() { $.cookie('migrageQ1', true, { expires: 7, path: '/' }); }); $('.q2 .yes-button').on('click', function() { if ($.cookie('migrageQ1')) { location.href = '/healthcare/check_test/migrage/check03.html'; } }); $('.q3 .check-button').on('click', function() { var q3 = [false, false, false, false, false, false]; $(':checkbox[name="migrane"]').each(function(index) { if ($(this).prop('checked')) q3[index] = true; }); $.cookie('q3', q3, { expires: 7, path: '/' }); }); $('.q3 .clear-button').on('click', function() { $(':checkbox[name="migrane"]').prop('checked', false); $.cookie('q3', [false, false, false, false, false, false], { expires: 7, path: '/' }); }); if ($('.q3-result').length) { var q3 = $.cookie('q3'); for (var i = 0, length = q3.length; i < length; i++) { if (q3[i]) $($('label')[i]).addClass('checked'); }; $('.checked').prepend(''); }; }; Zutsu.clusterQA = function() { $('.cluster .check-button').on('click', function() { var cluster = [false, false, false, false, false, false, false]; $(':checkbox[name="cluster"]').each(function(index) { if ($(this).prop('checked')) cluster[index] = true; }); $.cookie('cluster', cluster, { expires: 7, path: '/' }); }); $('.cluster .clear-button').on('click', function() { $(':checkbox[name="cluster"]').prop('checked', false); $.cookie('cluster', [false, false, false, false, false, false, false], { expires: 7, path: '/' }); }); if ($('.cluster-result').length) { var cluster = $.cookie('cluster'); for (var i = 0, length = cluster.length; i < length; i++) { if (cluster[i]) $($('label')[i]).addClass('checked'); }; $('.checked').prepend(''); }; }; Zutsu.modal = function() { $('.modal-bg').hide(); $('.modal-button').on('click', function() { if (Zutsu.device == 'pc') $('.modal-bg').show(); if (Zutsu.device == 'sp') location.href = $(this).attr('data-url'); // if(Zutsu.device == 'sp') location.href = '/healthcare/headache_type/sp/'; }); $('.modal-bg, .modal-close').on('click', function() { $('.modal-bg').hide(); }); $('.modal-content').on('click, touchmove, touchend', function(evt) { evt.stopPropagation(); }); }; Zutsu.sns = function() { // twitter ; ! function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https'; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.src = p + '://platform.twitter.com/widgets.js'; fjs.parentNode.insertBefore(js, fjs); } }(document, 'script', 'twitter-wjs'); // google plus ; window.___gcfg = { lang: 'ja' }; (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/platform.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); }; Zutsu.deviceCheck = function() { Zutsu.deviceWidth = $(window).width(); Zutsu.device = (Zutsu.deviceWidth > 680) ? 'pc' : 'sp'; Zutsu.url = location.pathname; }; Zutsu.spMenu = function() { //sp版のヘッダーメニューボタンの切り替え if (Zutsu.device == 'sp') { $('.sp-menu').hide(); $('.header-menu').off('click'); $('.header-menu').on('click', function() { $('.sp-menu').slideToggle(); }); } else { $('.sp-menu').hide(); // console.log($('.footer-list-li05 a[href^="http://www.e-map.ne.jp/"]')); } }; Zutsu.contentNav = function() { //第一階層左ナビ var cat = ['/healthcare/period', '/healthcare/hospital_choice', '/healthcare/go_hospital', '/healthcare/headache_type', '/healthcare/check_test', '/healthcare/migrane', '/healthcare/cluster', '/healthcare/diary']; for (var i = 0; i < cat.length; i++) { if (Zutsu.url.indexOf(cat[i]) != -1) { $($('.main-nav-button')[i]).addClass('active'); if (i == 4) $($('.main-nav-button')[i - 1]).addClass('active'); if (i >= 5) $($('.main-links-link')[i - 5]).addClass('active'); } } var urlList = [ 'period/movie_point', 'period/movie_migrane', 'period/series', 'period/report', 'period/advice', 'check_test/migrage', 'check_test/cluster', 'check_test/cluster/HeadacheImpactTest', 'migrane/symptom', 'migrane/hormone', 'migrane/type', 'migrane/predictor', 'migrane/treatment', 'migrane/pharma1', 'migrane/pharma2', 'migrane/dairy', 'migrane/preventive', 'migrane/complain', 'cluster/property', 'cluster/phama', 'cluster/countermeasure', 'cluster/cautions', 'cluster/complain' ]; for (var i = 0; i < urlList.length; i++) { if (Zutsu.url.indexOf(urlList[i]) != -1) { $($('.main-nav-button li')[i]).addClass('active'); if (i == 7) $($('.main-nav-button li')[6]).removeClass('active'); if (i >= 8) $($('.main-links-link li')[i - 8]).addClass('active'); } } }; Zutsu.qaList = function() { if (Zutsu.device == 'sp') { $('.qa-list').children('dd').hide(); $('.qa-list').children('div').off('click'); $('.qa-list').children('div').removeClass('active'); $('.qa-list').children('div').on('click', function() { var index = $('.qa-list').children('div').index(this); $(this).toggleClass('active'); $($('.qa-list').children('dd')[index]).slideToggle(); }); } else { $('.qa-list').children('dd').show(); } } Zutsu.nav = function() { //フッター、spメニュー部分のナビ if (Zutsu.device == 'sp') { $('.footer-list > li > h3').each(function(index) { var htmlText = $(this).html(); var spanText = htmlText.replace('', ''); $(this).html(spanText); }); $('.footer-list > li > ul').hide(); $('.footer-list > li').off('click'); $('.footer-list > li').on('click', function() { $.cookie('openIndex', $('#footer-content li').index(this)); // keep open if ($(this).hasClass('open')) { $(this).toggleClass('open'); $(this).children('ul').slideToggle(); } else { $('.footer-list > li').removeClass('open'); $(this).toggleClass('open'); $('.footer-list > li').children('ul').slideUp(); $(this).children('ul').slideToggle(); } }); $('.footer-list-li05 a[href^="/healthcare/clinic/"]').attr('href', 'http://www.e-map.ne.jp/smt/gskemap/?p_f6=1'); // keep open if ($.cookie('prevUrl') == location.href) { $($('#footer-content li')[$.cookie('openIndex')]).trigger('click'); } $('.footer-list a').on('click', function() { $.cookie('prevUrl', location.href, { expires: 7, path: '/' }); // console.log($.cookie('openIndex'), $.cookie('prevUrl')); // console.log('test'); }); } else { $('.footer-list > li > h3').each(function(index) { var htmlText = $(this).html(); var spanText = htmlText.replace('', ''); $(this).html(spanText); }); $('.footer-list > li > ul').show(); $('.footer-list > li').off('click'); $('.footer-list-li05 a[href^="http://www.e-map.ne.jp/smt/gskemap/?p_f6=1"]').attr('href', '/healthcare/clinic/'); } }; Zutsu.searchClinic = function() { if (Zutsu.device == 'sp') { $('a[href^="/healthcare/clinic/"]').attr('href', 'http://www.e-map.ne.jp/smt/gskemap/?p_f6=1'); } else { $('a[href^="http://www.e-map.ne.jp/smt/gskemap/?p_f6=1"]').attr('href', '/healthcare/clinic/'); } }; Zutsu.resize = function() { var timer = false; var device = '' + Zutsu.device; $(window).on('resize', function() { if (timer !== false) { clearTimeout(timer); } timer = setTimeout(function() { Zutsu.deviceCheck(); if (Zutsu.device == device) { return; } else {}; Zutsu.init(); }, 1000); }); }; Zutsu.youtube = function() { var $youtube = $('.youtube'); var $iframe = $('.youtube iframe'); var $img = $('.youtube img'); var imgWidth = $img.width() || 310; var imgHeight = $img.height() || 176; // console.log(imgWidth, imgHeight); $img.show(); $iframe.hide(); $youtube.off('click'); $youtube.on('click', function() { $iframe.width(imgWidth); $iframe.height(imgHeight); $(this).children('iframe').attr('src', $(this).children('iframe').attr('src') + '&autoplay=1'); $(this).children('img').hide(); $(this).children('iframe').show(); }); } Zutsu.init(); }); $(function() { $('a[href^=#]').on('click', function() { var speed = 400; var href = $(this).attr("href"); var target = $(href == "#" || href == "" ? 'html' : href); var position = target.offset().top; $('body,html').animate({ scrollTop: position }, speed, 'swing'); return false; }); });