Hugo-theme-stack/assets/ts/utils.ts

43 lines
802 B
TypeScript
Raw Normal View History

2020-08-22 07:20:08 -04:00
/**
* Load script asynchronous
* @return {Promise}
* @param url
*/
const loadScript = function (url) {
return new Promise(resolve => {
var scriptTag = document.createElement('script');
scriptTag.src = url;
scriptTag.onload = () => {
resolve();
};
document.head.appendChild(scriptTag);
})
};
/**
* Load style asynchronous
* @return {Promise}
* @param url
*/
const loadStyle = function (url) {
return new Promise(resolve => {
var link = document.createElement('link');
link.href = url;
link.type = "text/css";
link.rel = "stylesheet";
link.onload = () => {
resolve();
};
document.head.appendChild(link);
});
};
export {
loadScript,
loadStyle
}