- npm: Update devDeps

- Fix: Enforce stylesheet ordering sequence
- Fix: Ensure SVG-edit hidden until stylesheets loaded
- Fix: Avoid abandoning stylesheet loading if one load fails
This commit is contained in:
Brett Zamir
2018-05-29 13:47:32 +08:00
parent 83e3e66ddc
commit a353d6fc89
6 changed files with 61 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
function loadStylesheets(stylesheets, {
before: beforeDefault, after: afterDefault, favicon: faviconDefault,
canvas: canvasDefault, image: imageDefault = true
canvas: canvasDefault, image: imageDefault = true,
acceptErrors
} = {}) {
stylesheets = Array.isArray(stylesheets) ? stylesheets : [stylesheets];
@@ -28,6 +29,11 @@ function loadStylesheets(stylesheets, {
const link = document.createElement('link');
return new Promise((resolve, reject) => {
if (acceptErrors) {
reject = typeof acceptErrors === 'function' ? error => {
acceptErrors({ error, stylesheetURL, options, resolve, reject });
} : resolve;
}
if (stylesheetURL.endsWith('.css')) {
favicon = false;
} else if (stylesheetURL.endsWith('.ico')) {

View File

@@ -38,6 +38,8 @@
<title>SVG-edit</title>
</head>
<body>
<div id="svg_container" style="visibility: hidden;">
<div id="svg_editor">
<div id="rulers">
<div id="ruler_corner"></div>
@@ -762,5 +764,7 @@
<li><a href="#merge_down">Merge Down</a></li>
<li><a href="#merge_all">Merge All</a></li>
</ul>
</div>
</body>
</html>

View File

@@ -39,6 +39,8 @@
<title>SVG-edit</title>
</head>
<body>
<div id="svg_container" style="visibility: hidden;">
<div id="svg_editor">
<div id="rulers">
<div id="ruler_corner"></div>
@@ -763,5 +765,7 @@
<li><a href="#merge_down">Merge Down</a></li>
<li><a href="#merge_all">Merge All</a></li>
</ul>
</div>
</body>
</html>

View File

@@ -1013,7 +1013,28 @@ editor.init = function () {
}
});
let stylesheets = $.loadingStylesheets;
function getStylesheetPriority (stylesheet) {
switch (stylesheet) {
case 'jgraduate/css/jPicker.css':
return 1;
case 'jgraduate/css/jgraduate.css':
return 2;
case 'svg-editor.css':
return 3;
case 'spinbtn/JQuerySpinBtn.css':
return 4;
default:
return Infinity;
}
}
let stylesheets = $.loadingStylesheets.sort((a, b) => {
const priorityA = getStylesheetPriority(a);
const priorityB = getStylesheetPriority(b);
if (priorityA === priorityB) {
return 0;
}
return priorityA > priorityB;
});
if (curConfig.stylesheets.length) {
// Ensure a copy with unique items
stylesheets = [...new Set(curConfig.stylesheets)];
@@ -1022,7 +1043,14 @@ editor.init = function () {
stylesheets.splice(idx, 1, ...$.loadingStylesheets);
}
}
loadStylesheets(stylesheets).then(() => {
loadStylesheets(stylesheets, {acceptErrors: ({stylesheetURL, reject, resolve}) => {
if ($.loadingStylesheets.includes(stylesheetURL)) {
reject(new Error(`Missing expected stylesheet: ${stylesheetURL}`));
return;
}
resolve();
}}).then(() => {
$('#svg_container')[0].style.visibility = 'visible';
editor.runCallbacks();
setTimeout(function () {