ComunicWeb/assets/js/common/jsFiles.js

37 lines
885 B
JavaScript
Raw Permalink Normal View History

/**
* Operations of Javascript files
*
* @author Pierre HUBERT
*/
/**
* Include a Javascript file
*
* @param {String} fileURL The file URL
* @return {Boolean} False if it fails
*/
2021-01-31 04:53:35 +00:00
async function includeJS(fileURL) {
var fileElem = document.createElement("script");
fileElem.type = "text/javascript";
2021-01-31 04:53:35 +00:00
fileElem.innerHTML = await (await fetch(fileURL)).text();
//Append the new element
2021-01-31 04:53:35 +00:00
document.head.appendChild(fileElem);
//Debug message
ComunicWeb.debug.logMessage("Added JS file " + fileURL);
//Everything is OK
return true;
2017-01-22 17:46:06 +00:00
}
/**
* Execute some source code contained in a variable
*
* @param {String} source The source code to execute
*/
2021-01-31 04:53:35 +00:00
function executeJSsource(source){
2017-01-22 17:46:06 +00:00
var jsSourceContainer = document.createElement("script");
jsSourceContainer.innerHTML = source;
document.body.appendChild(jsSourceContainer);
2021-01-31 04:53:35 +00:00
}