if(!jQuery('body').hasClass('generate_index')){ jQuery('body').addClass('generate_index'); jQuery('document').ready(function(){ jQuery('.index_area').each(function(){ jQuery(this).append("目次
"); jQuery(this).append(""); var $article_id = jQuery(this).parents('article').attr('id'); var $content_box = jQuery(this).parents('.entry-content'); var $innerbox = jQuery(this).children('.index_inner_area'); $content_box.find('h2,h3').each(function(idx){ var anchor = "anchor_" + $article_id + "_" + idx; var anchor_src = jQuery(this).attr('id'); // 元のIDがある場合はそのまま流用 if(anchor_src!="undefined" && anchor_src!=null){ anchor = anchor_src; } jQuery(this).attr('id', anchor); var tag = jQuery(this).prop("tagName"); var indent_class = ""; if(tag=="h2" || tag=="H2"){ indent_class = "indent_h2"; }else{ indent_class = "indent_h3"; } var str = "
  • " + jQuery(this).text() + "
  • " jQuery($innerbox).append(str); }); }); }); // jump to anchor jQuery(document).on('click', '.indent_h2>a,.indent_h3>a', function(e){ e.preventDefault(); var dist_id = jQuery(this).attr('href'); if( jQuery(dist_id).length ){ // if here's at the toppage, make window scroll var pos_y = jQuery(dist_id).offset().top - 200; jQuery("html,body").animate({scrollTop:pos_y}, 400, "swing"); } }); }