This scripts are needed to create Dialog window with calendar --- html/index.html | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/html/index.html b/html/index.html index 06f8fbf..db039db 100644 --- a/html/index.html +++ b/html/index.html @@ -5,13 +5,26 @@ <title>IID Coffee Terminal</title> <script> function loadServerScript() { - let script = document.createElement('script'); - script.src = "http://localhost:5000/js"; - document.head.append(script); - script.onerror = function() { - this.parentElement.removeChild(this); - setTimeout(loadServerScript, 10000); - }; + <!--name of script, which I need --> + var scriptName= ["js", + "bower_components/moment/min/moment.min.js", + "bower_components/jquery/dist/jquery.min.js", + "bower_components/bootstrap/dist/js/bootstrap.min.js", + "bower_components/bootstrap3-dialog/dist/js/bootstrap-dialog.min.js", + "bower_components/fullcalendar/dist/fullcalendar.min.js"]; + for(var i=0;i<scriptName.length;i++){ + const scriptPromise = new Promise((resolve, reject) => { + const script = document.createElement('script'); + document.head.appendChild(script); + script.onload = resolve; + script.onerror = () => { + setTimeout(loadServerScript, 10000); + reject; + }; + script.async = false; + script.src = "http://localhost:5000/%22+scriptName%5Bi]; + }); + } }
loadServerScript();
On Thu, Sep 06 2018, Tomas Prochazka wrote:
This scripts are needed to create Dialog window with calendar
Když tak o tom přemýšlím, tak načítání těchto skriptů se nemusí dělat z mt-apps, ale stačilo by to z main.js v coffee-flask. V mt-apps zůstane jen načítání main.js (http://localhost:5000/js). Tím se celá funkcionalita kalendáře zjednoduší, protože vše bude jen v jednom repozitáři.
Nech to jako jako samostatný patch, ale v coffee-flask repu.
html/index.html | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/html/index.html b/html/index.html index 06f8fbf..db039db 100644 --- a/html/index.html +++ b/html/index.html @@ -5,13 +5,26 @@
<title>IID Coffee Terminal</title> <script> function loadServerScript() { - let script = document.createElement('script'); - script.src = "http://localhost:5000/js"; - document.head.append(script); - script.onerror = function() { - this.parentElement.removeChild(this); - setTimeout(loadServerScript, 10000); - }; + <!--name of script, which I need --> + var scriptName= ["js", + "bower_components/moment/min/moment.min.js", + "bower_components/jquery/dist/jquery.min.js", + "bower_components/bootstrap/dist/js/bootstrap.min.js", + "bower_components/bootstrap3-dialog/dist/js/bootstrap-dialog.min.js", + "bower_components/fullcalendar/dist/fullcalendar.min.js"]; + for(var i=0;i<scriptName.length;i++){ + const scriptPromise = new Promise((resolve, reject) => { + const script = document.createElement('script'); + document.head.appendChild(script);
Z původního kódy jsi vyhodil removeChild v případě neúspěchu. To tam bylo kvůli tomu, že když server není k dispozici, tak by se pořád přidávaly nové elementy a pokud nebude server dostupný dlouho, může díky tomu třeba dojít paměť, nebo bude výsledná stránka mnohem pomalejší, protože bude obsahovat tisíce elementů "script".
script.onload = resolve;
script.onerror = () => {
setTimeout(loadServerScript, 10000);
reject;
};
script.async = false;
Není to default?
script.src = "http://localhost:5000/"+scriptName[i];
Neměl by se .src nastavit před tím, než se zavolá appendChild? Nevím, jestli je při opačném pořadí garantováno, že se skript načte.
});
}
}
loadServerScript();
-- 2.11.0
Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee
On 6.9.2018 09:55, Michal Sojka wrote:
On Thu, Sep 06 2018, Tomas Prochazka wrote:
This scripts are needed to create Dialog window with calendar
Když tak o tom přemýšlím, tak načítání těchto skriptů se nemusí dělat z mt-apps, ale stačilo by to z main.js v coffee-flask. V mt-apps zůstane jen načítání main.js (http://localhost:5000/js). Tím se celá funkcionalita kalendáře zjednoduší, protože vše bude jen v jednom repozitáři.
Nech to jako jako samostatný patch, ale v coffee-flask repu.
html/index.html | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/html/index.html b/html/index.html index 06f8fbf..db039db 100644 --- a/html/index.html +++ b/html/index.html @@ -5,13 +5,26 @@
<title>IID Coffee Terminal</title> <script> function loadServerScript() { - let script = document.createElement('script'); - script.src = "http://localhost:5000/js"; - document.head.append(script); - script.onerror = function() { - this.parentElement.removeChild(this); - setTimeout(loadServerScript, 10000); - }; + <!--name of script, which I need --> + var scriptName= ["js", + "bower_components/moment/min/moment.min.js", + "bower_components/jquery/dist/jquery.min.js", + "bower_components/bootstrap/dist/js/bootstrap.min.js", + "bower_components/bootstrap3-dialog/dist/js/bootstrap-dialog.min.js", + "bower_components/fullcalendar/dist/fullcalendar.min.js"]; + for(var i=0;i<scriptName.length;i++){ + const scriptPromise = new Promise((resolve, reject) => { + const script = document.createElement('script'); + document.head.appendChild(script);
Z původního kódy jsi vyhodil removeChild v případě neúspěchu. To tam bylo kvůli tomu, že když server není k dispozici, tak by se pořád přidávaly nové elementy a pokud nebude server dostupný dlouho, může díky tomu třeba dojít paměť, nebo bude výsledná stránka mnohem pomalejší, protože bude obsahovat tisíce elementů "script".
doplnim
script.onload = resolve;
script.onerror = () => {
setTimeout(loadServerScript, 10000);
reject;
};
script.async = false;
Není to default?
pokud to neuvedu, tak skripty se neprovedou ve spravnem poradi a nefunguji zavisloti
script.src = "http://localhost:5000/"+scriptName[i];
Neměl by se .src nastavit před tím, než se zavolá appendChild? Nevím, jestli je při opačném pořadí garantováno, že se skript načte.
funguje to ale pro prehlednost kodu to nastavim pred funkci
});
} } loadServerScript();
-- 2.11.0
Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee