fix: 恢复外部库文件
This commit is contained in:
73
assets/vendor/external/resource-loader.js
vendored
73
assets/vendor/external/resource-loader.js
vendored
@@ -34,14 +34,17 @@
|
|||||||
|
|
||||||
// 加载备用系统
|
// 加载备用系统
|
||||||
loadFallbackSystems: function() {
|
loadFallbackSystems: function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (this.config.enableFallbackCSS) {
|
if (this.config.enableFallbackCSS) {
|
||||||
this.loadCSS('/wp-content/themes/argon/assets/vendor/external/css-fallback.css');
|
// 使用 silent 模式加载,失败时不抛出错误
|
||||||
this.loadCSS('/wp-content/themes/argon/assets/vendor/external/fonts/font-fallback.css');
|
this.loadCSS('/wp-content/themes/argon/assets/vendor/external/css-fallback.css', null, true);
|
||||||
|
this.loadCSS('/wp-content/themes/argon/assets/vendor/external/fonts/font-fallback.css', null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.enableFallbackJS) {
|
if (this.config.enableFallbackJS) {
|
||||||
this.loadJS('/wp-content/themes/argon/assets/vendor/external/js-fallback.js');
|
this.loadJS('/wp-content/themes/argon/assets/vendor/external/js-fallback.js', null, true);
|
||||||
this.loadJS('/wp-content/themes/argon/assets/vendor/external/resource-monitor.js');
|
this.loadJS('/wp-content/themes/argon/assets/vendor/external/resource-monitor.js', null, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -94,25 +97,32 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 加载CSS资源
|
// 加载CSS资源
|
||||||
loadCSS: function(url, fallbackUrl) {
|
loadCSS: function(url, fallbackUrl, silent) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var link = document.createElement('link');
|
var link = document.createElement('link');
|
||||||
link.rel = 'stylesheet';
|
link.rel = 'stylesheet';
|
||||||
link.href = url;
|
link.href = url;
|
||||||
|
|
||||||
var timeout = setTimeout(function() {
|
var handleFailure = function(reason) {
|
||||||
self.log('CSS资源加载超时: ' + url);
|
self.log('CSS资源加载' + reason + ': ' + url);
|
||||||
if (fallbackUrl) {
|
if (fallbackUrl) {
|
||||||
self.loadCSS(fallbackUrl).then(resolve).catch(reject);
|
self.loadCSS(fallbackUrl, null, silent).then(resolve).catch(reject);
|
||||||
} else {
|
} else {
|
||||||
var autoFallback = self.getFallbackUrl(url);
|
var autoFallback = self.getFallbackUrl(url);
|
||||||
if (autoFallback) {
|
if (autoFallback) {
|
||||||
self.loadCSS(autoFallback).then(resolve).catch(reject);
|
self.loadCSS(autoFallback, null, silent).then(resolve).catch(reject);
|
||||||
|
} else if (silent) {
|
||||||
|
// 静默模式下不抛出错误
|
||||||
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
reject(new Error('CSS加载失败且无备用资源'));
|
reject(new Error('CSS加载失败且无备用资源: ' + url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var timeout = setTimeout(function() {
|
||||||
|
handleFailure('超时');
|
||||||
}, self.config.timeout);
|
}, self.config.timeout);
|
||||||
|
|
||||||
link.onload = function() {
|
link.onload = function() {
|
||||||
@@ -123,17 +133,7 @@
|
|||||||
|
|
||||||
link.onerror = function() {
|
link.onerror = function() {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
self.log('CSS资源加载失败: ' + url);
|
handleFailure('失败');
|
||||||
if (fallbackUrl) {
|
|
||||||
self.loadCSS(fallbackUrl).then(resolve).catch(reject);
|
|
||||||
} else {
|
|
||||||
var autoFallback = self.getFallbackUrl(url);
|
|
||||||
if (autoFallback) {
|
|
||||||
self.loadCSS(autoFallback).then(resolve).catch(reject);
|
|
||||||
} else {
|
|
||||||
reject(new Error('CSS加载失败且无备用资源'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
document.head.appendChild(link);
|
document.head.appendChild(link);
|
||||||
@@ -141,25 +141,32 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 加载JS资源
|
// 加载JS资源
|
||||||
loadJS: function(url, fallbackUrl) {
|
loadJS: function(url, fallbackUrl, silent) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var script = document.createElement('script');
|
var script = document.createElement('script');
|
||||||
script.src = url;
|
script.src = url;
|
||||||
script.async = true;
|
script.async = true;
|
||||||
|
|
||||||
var timeout = setTimeout(function() {
|
var handleFailure = function(reason) {
|
||||||
self.log('JS资源加载超时: ' + url);
|
self.log('JS资源加载' + reason + ': ' + url);
|
||||||
if (fallbackUrl) {
|
if (fallbackUrl) {
|
||||||
self.loadJS(fallbackUrl).then(resolve).catch(reject);
|
self.loadJS(fallbackUrl, null, silent).then(resolve).catch(reject);
|
||||||
} else {
|
} else {
|
||||||
var autoFallback = self.getFallbackUrl(url);
|
var autoFallback = self.getFallbackUrl(url);
|
||||||
if (autoFallback) {
|
if (autoFallback) {
|
||||||
self.loadJS(autoFallback).then(resolve).catch(reject);
|
self.loadJS(autoFallback, null, silent).then(resolve).catch(reject);
|
||||||
|
} else if (silent) {
|
||||||
|
// 静默模式下不抛出错误
|
||||||
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
reject(new Error('JS加载失败且无备用资源'));
|
reject(new Error('JS加载失败且无备用资源: ' + url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var timeout = setTimeout(function() {
|
||||||
|
handleFailure('超时');
|
||||||
}, self.config.timeout);
|
}, self.config.timeout);
|
||||||
|
|
||||||
script.onload = function() {
|
script.onload = function() {
|
||||||
@@ -170,17 +177,7 @@
|
|||||||
|
|
||||||
script.onerror = function() {
|
script.onerror = function() {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
self.log('JS资源加载失败: ' + url);
|
handleFailure('失败');
|
||||||
if (fallbackUrl) {
|
|
||||||
self.loadJS(fallbackUrl).then(resolve).catch(reject);
|
|
||||||
} else {
|
|
||||||
var autoFallback = self.getFallbackUrl(url);
|
|
||||||
if (autoFallback) {
|
|
||||||
self.loadJS(autoFallback).then(resolve).catch(reject);
|
|
||||||
} else {
|
|
||||||
reject(new Error('JS加载失败且无备用资源'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
|
|||||||
14
assets/vendor/smoothscroll/smoothscroll1.js
vendored
14
assets/vendor/smoothscroll/smoothscroll1.js
vendored
@@ -123,8 +123,20 @@ function init() {
|
|||||||
if (pendingRefresh) return; // could also be: clearTimeout(pendingRefresh);
|
if (pendingRefresh) return; // could also be: clearTimeout(pendingRefresh);
|
||||||
pendingRefresh = setTimeout(function () {
|
pendingRefresh = setTimeout(function () {
|
||||||
if (isExcluded) return; // could be running after cleanup
|
if (isExcluded) return; // could be running after cleanup
|
||||||
|
// 先重置高度,强制重新计算
|
||||||
fullPageElem.style.height = '0';
|
fullPageElem.style.height = '0';
|
||||||
fullPageElem.style.height = root.scrollHeight + 'px';
|
// 使用 requestAnimationFrame 确保在下一帧更新,避免高度计算错误
|
||||||
|
requestAnimationFrame(function() {
|
||||||
|
// 获取实际内容高度,取 body 和 html 的最大值
|
||||||
|
var actualHeight = Math.max(
|
||||||
|
body.scrollHeight,
|
||||||
|
body.offsetHeight,
|
||||||
|
html.clientHeight,
|
||||||
|
html.scrollHeight,
|
||||||
|
html.offsetHeight
|
||||||
|
);
|
||||||
|
fullPageElem.style.height = actualHeight + 'px';
|
||||||
|
});
|
||||||
pendingRefresh = null;
|
pendingRefresh = null;
|
||||||
}, 500); // act rarely to stay fast
|
}, 500); // act rarely to stay fast
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -123,8 +123,20 @@ function init() {
|
|||||||
if (pendingRefresh) return; // could also be: clearTimeout(pendingRefresh);
|
if (pendingRefresh) return; // could also be: clearTimeout(pendingRefresh);
|
||||||
pendingRefresh = setTimeout(function () {
|
pendingRefresh = setTimeout(function () {
|
||||||
if (isExcluded) return; // could be running after cleanup
|
if (isExcluded) return; // could be running after cleanup
|
||||||
|
// 先重置高度,强制重新计算
|
||||||
fullPageElem.style.height = '0';
|
fullPageElem.style.height = '0';
|
||||||
fullPageElem.style.height = root.scrollHeight + 'px';
|
// 使用 requestAnimationFrame 确保在下一帧更新,避免高度计算错误
|
||||||
|
requestAnimationFrame(function() {
|
||||||
|
// 获取实际内容高度,取 body 和 html 的最大值
|
||||||
|
var actualHeight = Math.max(
|
||||||
|
body.scrollHeight,
|
||||||
|
body.offsetHeight,
|
||||||
|
html.clientHeight,
|
||||||
|
html.scrollHeight,
|
||||||
|
html.offsetHeight
|
||||||
|
);
|
||||||
|
fullPageElem.style.height = actualHeight + 'px';
|
||||||
|
});
|
||||||
pendingRefresh = null;
|
pendingRefresh = null;
|
||||||
}, 500); // act rarely to stay fast
|
}, 500); // act rarely to stay fast
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user