window.addEventListener('DOMContentLoaded', function (){
new ScrollHint('.js-scrollable', {
i18n: {
scrollable: 'スクロールできます',
},
});
var totalPostsEl=document.getElementById('js-total-posts');
if(totalPostsEl&&typeof souken_ajax!=='undefined'){
fetch(souken_ajax.ajaxurl + '?action=souken_get_total_posts')
.then(function (response){
return response.json();
})
.then(function (data){
if(data.success&&data.data.total){
var targetNum=parseInt(data.data.total.replace(/,/g, ''), 10);
animateCountUp(totalPostsEl, 0, targetNum, 1500);
}})
.catch(function (error){
console.error('記事数取得エラー:', error);
});
}
function animateCountUp(element, start, end, duration){
var startTime=null;
var step=function (timestamp){
if(!startTime) startTime=timestamp;
var progress=Math.min((timestamp - startTime) / duration, 1);
var easeProgress=1 - (1 - progress) * (1 - progress);
var current=Math.floor(start + (end - start) * easeProgress);
element.textContent=current.toLocaleString();
if(progress < 1){
requestAnimationFrame(step);
}};
requestAnimationFrame(step);
}
document.querySelectorAll('.p-toc--excerpt').forEach(function (tocElement){
var expandBtn=tocElement.querySelector('.p-toc__expandBtn');
if(!expandBtn) return;
var expandText='もっと見る';
var collapseText='折りたたむ';
expandBtn.innerHTML=expandText;
expandBtn.addEventListener('click', function (e){
e.preventDefault();
if(tocElement.classList.contains('is-expanded')){
tocElement.classList.add('is-omitted');
tocElement.classList.remove('is-expanded');
expandBtn.innerHTML=expandText;
}else{
tocElement.classList.remove('is-omitted');
tocElement.classList.add('is-expanded');
expandBtn.innerHTML=collapseText;
}});
});
var catchcopySlider=document.getElementById('js-catchcopy-slider');
if(catchcopySlider){
var slides=catchcopySlider.querySelectorAll('.l-header__catchcopy-slide');
var currentIndex=0;
var slideCount=slides.length;
if(slideCount > 1){
setInterval(function (){
slides[currentIndex].classList.remove('is-active');
currentIndex=(currentIndex + 1) % slideCount;
slides[currentIndex].classList.add('is-active');
}, 3000);
}}
});
function toggleFeaturedKeywords(){
var tagsElement=document.getElementById('featuredKeywordsTags');
var btnElement=document.getElementById('featuredKeywordsMoreBtn');
var textElement=btnElement.querySelector('.p-featured-keywords__more-text');
if(tagsElement&&btnElement){
var isExpanded=tagsElement.classList.contains('is-expanded');
if(isExpanded){
tagsElement.classList.remove('is-expanded');
btnElement.classList.remove('is-expanded');
textElement.textContent='もっと見る';
}else{
tagsElement.classList.add('is-expanded');
btnElement.classList.add('is-expanded');
textElement.textContent='閉じる';
}}
};