The URI of TUHH Docker Registry changed from "docker.rz.tu-harburg.de:5000" to "docker.rz.tu-harburg.de". Please update your gitlab-ci.yml files if you use images from this registry.

Commit c599a1d5 authored by Tobias Zeumer's avatar Tobias Zeumer

Use generic function to post load scripts when required; #4 (+ #28)

parent 7927a0fb
......@@ -349,18 +349,22 @@ $( document ).ready(function() {
// Load saveSvgAsPng.js only on click, then execute download_png()
$("#savePng").on('click', function(event) {
postload_js(pathJsSavePng, false, download_png);
/*
if (typeof saveSvgAsPng === "function") {
download_png();
} else { /* myFunction exists in myscript */
} else { // myFunction exists in myscript
var js_script = document.createElement('script');
js_script.type = "text/javascript";
js_script.src = pathJsSavePng;
js_script.async = true;
js_script.async = false;
document.getElementsByTagName('head')[0].appendChild(js_script);
js_script.onload = function(loadEvent) {
download_png();
}
}
*/
});
......@@ -435,6 +439,35 @@ $( document ).ready(function() {
# Custom functions - Short
############################################################################# */
/**
* Load script only when required
*
* @param {string} src Script source
* @param {bool} async Defaults to false, because most likely you need it afterwards
* @param {obj} callback What to do after successfully loading script?
*/
function postload_js(src, async, callback) {
var async = (typeof async == 'undefined') ? false : true;
var js_script = document.querySelectorAll('[src="'+src+'"]');
// Already loaded?
if (js_script.length > 0) {
callback();
}
// Not? Create script element
else {
var js_script = document.createElement('script');
js_script.type = "text/javascript";
js_script.src = src;
js_script.async = async;
document.getElementsByTagName('head')[0].appendChild(js_script);
js_script.onload = function(loadEvent) {
callback();
}
}
}
/**
* Get count of elements for all levels by css selector(s) of element
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment