From c624dc1bb95cb455c7b010db7b1860b8927e1273 Mon Sep 17 00:00:00 2001 From: new-sankaku Date: Mon, 29 Jul 2024 23:09:16 +0900 Subject: [PATCH] =?UTF-8?q?=E9=A0=86=E5=BA=8F=E4=BF=9D=E9=9A=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SP-MangaEditer/index.html | 164 +++++++++++++++---------------- SP-MangaEditer/js/html-loader.js | 66 +++++++------ 2 files changed, 120 insertions(+), 110 deletions(-) diff --git a/SP-MangaEditer/index.html b/SP-MangaEditer/index.html index 366036d..a3ea189 100644 --- a/SP-MangaEditer/index.html +++ b/SP-MangaEditer/index.html @@ -67,23 +67,23 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -118,77 +118,77 @@
- - - - - - - + + + + + + + - - - - - + + + + + - - - - - - - - + + + + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SP-MangaEditer/js/html-loader.js b/SP-MangaEditer/js/html-loader.js index fd849ee..b05905a 100644 --- a/SP-MangaEditer/js/html-loader.js +++ b/SP-MangaEditer/js/html-loader.js @@ -5,41 +5,44 @@ function log(message, type = 'info') { } function loadContent(scriptId, targetId) { - const script = document.createElement('script'); - script.src = 'js/html-component/' + scriptId + '.js'; - - script.onload = function() { - if (typeof window.html === 'function') { - const content = window.html(); - if( targetId ){ - document.getElementById(targetId).innerHTML = content; - }else{ - document.getElementById("head-id").innerHTML = document.getElementById("head-id").innerHTML + content; + return new Promise((resolve, reject) => { + const script = document.createElement('script'); + script.src = 'js/html-component/' + scriptId + '.js'; + script.onload = function () { + if (typeof window.html === 'function') { + const content = window.html(); + if (targetId) { + document.getElementById(targetId).innerHTML = content; + } else { + document.getElementById("head-id").innerHTML += content; + } + delete window.html; + resolve(); + } else { + document.getElementById("head-id").innerHTML = `

Error: Content for ${scriptId} could not be loaded.

`; + reject(new Error(`Content for ${scriptId} could not be loaded.`)); } - delete window.html; - // console.log( "innerHTML:", document.getElementById("head-id").innerHTML ); - } else { - document.getElementById("head-id").innerHTML = `

Error: Content for ${scriptId} could not be loaded.

`; - } - }; + }; + script.onerror = function () { + document.getElementById("head-id").innerHTML = `

Error: Script ${scriptId}.js could not be loaded.

`; + reject(new Error(`Script ${scriptId}.js could not be loaded.`)); + }; + document.head.appendChild(script); + }); +} - script.onerror = function() { - document.getElementById("head-id").innerHTML = `

Error: Script ${scriptId}.js could not be loaded.

`; - }; - document.head.appendChild(script); -} function loadCSS(href) { const link = document.createElement('link'); link.rel = 'stylesheet'; link.href = href; - link.onload = function() { + link.onload = function () { log(`CSS ${href} loaded successfully`); }; - link.onerror = function() { + link.onerror = function () { log(`Failed to load CSS: ${href}`, 'error'); }; @@ -48,8 +51,15 @@ function loadCSS(href) { log('app.js executed'); -loadContent('menu-html', 'desu-nav'); -loadContent('sidebar-html'); -loadContent('canvas-html'); -loadContent('layer-html'); -loadContent('controle-html'); +// 使用例 +Promise.all([ + loadContent('menu-html', 'desu-nav'), + loadContent('sidebar-html'), + loadContent('canvas-html'), + loadContent('layer-html'), + loadContent('controle-html') + ]).then(() => { + console.log('All content loaded'); + }).catch((error) => { + console.error('Error loading content:', error); + });