jQuery(document).ready(function($){ $('a').bind('focus',function(){if(this.blur)this.blur();}); // header search select $('.header_search_inputs select').chosen({width:'100%', disable_search:true}); $('.header_search_inputs select').on('chosen:showing_dropdown', function(event, obj){ obj.chosen.dropdown.stop().css({opacity:0, height:'auto', clip:'auto'}) var h = obj.chosen.dropdown.outerHeight(); obj.chosen.dropdown.css({height:0}).animate({opacity:1, height:h}, 300); }); $('.header_search_inputs select').on('chosen:hiding_dropdown', function(event, obj){ obj.chosen.dropdown.stop().animate({opacity:0, height:0}, 300, function(){ obj.chosen.dropdown.find('.chosen-results').html(''); }); }); // header search and/or $('.header_search_keywords ul.search_keywords_operator').show(); $('.header_search_keywords ul.search_keywords_operator li').click(function(){ $(this).blur(); var operator = $(this).text(); if (operator != 'and' && operator != 'or') return; $(this).siblings('li').removeClass('active'); $(this).addClass('active'); $(this).closest('.header_search_keywords').find('input[name=search_keywords_operator]').val(operator); }); // toggle tags for search results if ($('.archive_filter.is-open, .archive_filter.is-close').length) { if ($('.archive_filter').hasClass('is-open')) { document.cookie = 'gensen_archive_filter_toggle=open; path=/'; } else { document.cookie = 'gensen_archive_filter_toggle=close; path=/'; } $('.archive_filter .archive_filter_headline').click(function(){ var $closest = $(this).closest('.archive_filter'); if ($closest.hasClass('is-open')) { $closest.removeClass('is-open').addClass('is-close'); $closest.find('.archive_filter_toggle').slideUp('fast'); $closest.find('[name="filter_toggle"]').val('close'); document.cookie = 'gensen_archive_filter_toggle=close; path=/'; } else { $closest.removeClass('is-close').addClass('is-open'); $closest.find('.archive_filter_toggle').slideDown('fast'); $closest.find('[name="filter_toggle"]').val('open'); document.cookie = 'gensen_archive_filter_toggle=open; path=/'; } }); } // click return top $('#return_top a').click(function() { $('html,body').animate({scrollTop : 0}, 1000, 'easeOutExpo'); return false; }); // show return top button var topBtn = $('#return_top'); $(window).scroll(function () { var scrTop = $(this).scrollTop(); if (scrTop > 100) { topBtn.stop().fadeIn('slow'); } else { topBtn.stop().fadeOut(); } }); // mobile toggle global nav $('.menu_button').on('click', function(){ if($('#header_search').is(':visible')) { $('#header_search').hide(); } if($(this).hasClass('active')) { $(this).removeClass('active'); $('#header').removeClass('active'); $('#global_menu').hide(); return false; } else { $(this).addClass('active'); $('#header').addClass('active'); $('#global_menu').show(); return false; } }); // mobile global nav toggle children $('#global_menu li > ul').parent().prepend(''); $('#global_menu .child_menu_button').on('click', function() { if($(this).parent().hasClass('open')) { $(this).parent().removeClass('open'); $(this).siblings('.sub-menu').slideUp(300); return false; } else { $(this).parent().addClass('open'); $(this).siblings('.sub-menu').slideDown(300); return false; } }); // mobile toggle header search $('#header_top .search_button').on('click', function(){ if($('.menu_button').hasClass('active')) { $('.menu_button').removeClass('active'); $('#global_menu').hide(); } if($('#header_search').is(':visible')) { $('#header').removeClass('active'); $('#header_search').hide(); } else { $('#header').addClass('active'); $('#header_search').show(); } return false; }); // blog archive category hover $(document).on({ 'mouseenter':function(){ var $a = $(this).closest('a'); $a.attr('data-href', $a.attr('href')); if ($(this).attr('data-href')) { $a.attr('href', $(this).attr('data-href')); } }, 'mouseleave':function () { var $a = $(this).closest('a'); $a.attr('href', $a.attr('data-href')); } },'a span[data-href]'); init_introduce_list_col(true); $(window).resize(init_introduce_list_col); // introduce archive hover $(document).on('mouseenter', '.introduce_list_row .introduce_list_col', function() { if ($(this).hasClass('show_info') || $('body').width() <= 767) return; var $row = $(this).closest('.introduce_list_row'); $row.find('.introduce_list_col.show_info').removeClass('show_info'); $(this).addClass('show_info'); } ); // category widget $('.collapse_category_list li').hover( function(){ $('>ul:not(:animated)',this).slideDown('fast'); $(this).addClass('active'); }, function(){ $('>ul',this).slideUp('fast'); $(this).removeClass('active'); } ); // comment tab $('#trackback_switch').click(function(){ $('#comment_switch').removeClass('comment_switch_active'); $(this).addClass('comment_switch_active'); $('#comment_area').animate({opacity: 'hide'}, 0); $('#trackback_area').animate({opacity: 'show'}, 1000); return false; }); $('#comment_switch').click(function(){ $('#trackback_switch').removeClass('comment_switch_active'); $(this).addClass('comment_switch_active'); $('#trackback_area').animate({opacity: 'hide'}, 0); $('#comment_area').animate({opacity: 'show'}, 1000); return false; }); }); // introduce archive col set width and height function init_introduce_list_col(init){ var $cols = jQuery('.introduce_list_row .introduce_list_col'); // remove added css $cols.find('a, .image, .image img, .info').removeAttr('style'); // box size if (jQuery('body').width() > 767) { if (init === true) { $cols.find('.image').addClass('disable-transition'); } var row_width = $cols.first().closest('.introduce_list_row').width(); var w1 = Math.floor(row_width * 23.3333) / 100; var w2 = Math.floor(row_width * 48.8888) / 100; $cols.find('.image').width(w1).css('paddingTop', w1); $cols.find('.image img').height(w1); $cols.find('.info').width(w1).height(w1).css('display', 'block'); $cols.find('a').height(w1).width(w2); if (init === true) { setTimeout(function(){ $cols.find('.image').removeClass('disable-transition'); }, 66); } } // text max height $cols.each(function(){ jQuery(this).find('.title, .excerpt').removeAttr('style'); var remain_height = jQuery(this).height() - jQuery(this).find('.meta').outerHeight(true) - jQuery(this).find('.more').outerHeight(true); var $title = jQuery(this).find('.title'); var $excerpt = jQuery(this).find('.excerpt'); if ($title.innerHeight() > remain_height) { $excerpt.hide(); var title_font_size = parseFloat($title.css('fontSize')); var title_line_height = parseFloat($title.css('lineHeight')); for (var i=2; i<=10; i++) { if (i * title_line_height > remain_height || i == 10) { $title.css({ maxHeight: (i-1) * title_line_height + 'px', overflow: 'hidden', }); break; } } } else { remain_height -= $title.outerHeight(true); var excerpt_font_size = parseFloat($excerpt.css('fontSize')); var excerpt_line_height = parseFloat($excerpt.css('lineHeight')); var excerpt_line_height_offset = 0; if (excerpt_line_height > excerpt_font_size) { excerpt_line_height_offset = (excerpt_line_height - excerpt_font_size) / 2; } for (var i=1; i<=10; i++) { if (i * excerpt_line_height - excerpt_line_height_offset > remain_height || i == 10) { $excerpt.css({ maxHeight: (i-1) * excerpt_line_height + 'px', overflow: 'hidden', }); break; } } } }); }; jQuery(function($){ $('.hover-img').each(function(){ var src = $(this).attr('src'); $(this).data('offimg',src); var onImg = src.replace('.png','_on.png'); $(this).data('onimg',onImg); }) $('.hover-img').parents('a').on('mouseover',function(e){ var $img = $(this).find('.hover-img'); $img.attr('src',$img.data('onimg')); } ) $('.hover-img').parents('a').on('mouseout',function(e){ var $img = $(this).find('.hover-img'); $img.attr('src',$img.data('offimg')); } ); console.log("$('#main_col > #cb_3 .cb_headline').length",$('#cb_3 .cb_headline').length) if(!$('#main_col > #cb_3 .cb_headline').length){ $('#main_col > #cb_3').remove(); } }); jQuery(document).on('click','[data-toggle="favorite"]',function(){ var $ = jQuery; var $this = $(this); var data = $this.data(); $this.addClass('isRunning'); fetch('/business/trc/gearbox/wp-json/gearbox_favorites/regist/', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ // ここに送りたいデータを書く makeshop_id:data.makeshopid, post_id:Number(data.postid), flg:Number(data.flg) }) }) .then(response => response.json()) .then(function(res){ $this.removeClass('isRunning'); var json = JSON.parse(res); if(json.status){ console.log(data.flg); if(data.flg < 0){ $this.text('お気に入りに追加'); $this.removeClass('wp-button-favorite-remove').addClass('wp-button-favorite-add') $this.data('flg',1); }else{ $this.text('お気に入りから削除'); $this.data('flg',-1); $this.removeClass('wp-button-favorite-add').addClass('wp-button-favorite-remove') } } }); return false; });