mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 03:53:30 +08:00
refactor(script): remove loadScript & loadStyle
This commit is contained in:
parent
619998b2f3
commit
69cd9343a0
@ -1,5 +1,3 @@
|
|||||||
import { loadScript, loadStyle } from 'ts/utils';
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
PhotoSwipe: any;
|
PhotoSwipe: any;
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user