Newer
Older
newweb / js / jdinit.js
/*
 * include id-specified html into corresponding div
 */
window.addEventListener(
"DOMContentLoaded",
function () {
    function includeIdFiles() {
	/*header.html, footer.html, news.html, activities.htmlを呼び出す*/
	for (let id of ["header", "footer", "news", "activities"]) {
	    let e   = document.getElementById(id);
	    if (!e) continue;
	    let dir = (e.getAttribute("dir") || ".."),
		/*html_initディレクトリから該当するhtmlファイルを用意*/
		fn  = dir + "/html_init/" + e.id + ".html";
	    fetch(fn).then((resp) => {
		resp.text().then((text) => {
		    let newmenu = e.insertAdjacentHTML("afterend", text);
		    e.remove();
		    newmenu.id = id;
		});
	    });
	    
	}
    }
    function init() {
	includeIdFiles();
    }
    init();
});

window.addEventListener("scroll", function(){
    var header = document.querySelector("header");
header.classList.toggle("scroll-nav", window.scrollY > 0)
});

window.addEventListener("DOMContentLoaded", function(){
	const faqs = document.querySelectorAll("div.faq-list dl");
	console.log(faqs);
	faqs.forEach(faqs => {
		faqs.addEventListener("click",()=> {
			faqs.classList.toggle("act");
			faqs.children[0].classList.toggle("question");
			faqs.children[1].classList.toggle("faq-show");
		});
	});
});

function loadFiletoIDElement(file, id) {
    fetch(file).then(resp=>{
	return resp.text()
    }).then(text=>{
	let elm = document.getElementById(id);
	if (elm)
	    elm.innerHTML = text;
    });
}