1/** 2 * data-include屿§ãæã¤è¦ç´ ã«ãæå®ããHTMLãã¡ã¤ã«ãèªã¿è¾¼ãã§å·®ãè¾¼ã¿ã¾ãã 3 * ã¤ã³ã¯ã«ã¼ãã®ãã¹ããå¯ã 4 */ 5async function loadHtmlIncludes(root = document) { 6 // data-include ããããã¾ã å¦çãã¦ããªãè¦ç´ ï¼data-include-loaded="true"ï¼ä»¥å¤ã対象ã«ãã 7 const targets = Array.from( 8 root.querySelectorAll('.js-include[data-include]:not([data-include-loaded="true"])') 9 ) 10 11 // 対象ããªããã°ä½ãããçµäº 12 if (targets.length === 0) return; 13 14 // å ¨ã¿ã¼ã²ããã並åã§å¦çãã 15 await Promise.all( 16 targets.map(async (el) => { 17 const url = el.dataset.include; 18 if (!url) return; 19 20 // ãã©ã¦ã¶æ¨æºã®HTTPãã£ãã·ã¥ã«å¾ã 21 let cacheMode = 'default'; 22 23 try { 24 const response = await fetch(url, { cache: cacheMode }); 25 26 if (!response.ok) { 27 throw new Error(`Failed to fetch ${url}: ${response.status}`); 28 } 29 30 el.innerHTML = await response.text(); 31 32 // 2åç®ä»¥éã«åå¦çããªããããã©ã°ãä»ä¸ 33 el.dataset.includeLoaded = 'true'; 34 35 // ãã®è¦ç´ ã®ä¸ã«ãããã«data-includeãããã°å¦çãè¡ã 36 await loadHtmlIncludes(el); 37 } catch (error) { 38 console.error('[loadHtmlIncludes] include failed:', url, error); 39 } 40 }) 41 ); 42} 43 44// ãã¼ã¸èªã¿è¾¼ã¿å®äºæã«ã¤ã³ã¯ã«ã¼ããå®è¡ãå®äºå¾ã«ã«ã¹ã¿ã ã¤ãã³ããçºç« 45document.addEventListener('DOMContentLoaded', () => { 46 // ååã®ã¤ã³ã¯ã«ã¼ãå¦çã®å®è¡ 47 loadHtmlIncludes() 48 .catch((error) => { 49 // loadHtmlIncludesèªä½ãrejectããå ´å 50 console.error('[loadHtmlIncludes] top-level error:', error); 51 }) 52 .finally(() => { 53 // ã«ã¹ã¿ã ã¤ãã³ãï¼ãã¹ã¦ã®ã¤ã³ã¯ã«ã¼ãå¦çï¼å¯¾è±¡ããªãå ´åãå«ãï¼ãçµãã£ããã¨ãéç¥ 54 window.dispatchEvent(new Event('js-includes-loaded')); 55 }); 56});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.