mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
shuffle template fixed
This commit is contained in:
parent
e82c02c768
commit
51f8824659
@ -215,7 +215,7 @@ Object.defineProperty(window, 'l10n', {
|
|||||||
if (localized !== undefined) {
|
if (localized !== undefined) {
|
||||||
$el.innerText = localized;
|
$el.innerText = localized;
|
||||||
} else {
|
} else {
|
||||||
console.debug(`Unsupported l10n token detected: "${token}"`, $el);
|
console.debug(`Unsupported l10n token detected: "${token}" (locale "${activeLocale}")`, $el);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
<!--
|
||||||
|
Error {{ code }}: {{ message }}
|
||||||
|
Description: {{ description }}
|
||||||
|
-->
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
@ -259,4 +263,8 @@
|
|||||||
})(document.createElement('script'), document.body);
|
})(document.createElement('script'), document.body);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<!--
|
||||||
|
Error {{ code }}: {{ message }}
|
||||||
|
Description: {{ description }}
|
||||||
|
-->
|
||||||
</html>
|
</html>
|
||||||
|
@ -72,7 +72,10 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="flex-center full-height">
|
<div class="flex-center full-height">
|
||||||
<div>
|
<div>
|
||||||
<span id="error_text">{{ code }}: <span data-l10n>{{ message }}</span></span>
|
<div id="error_text">
|
||||||
|
<span class="source">{{ code }}: <span data-l10n>{{ message }}</span></span>
|
||||||
|
<span class="target"></span>
|
||||||
|
</div>
|
||||||
{{ if show_details }}
|
{{ if show_details }}
|
||||||
<div class="hidden" id="details">
|
<div class="hidden" id="details">
|
||||||
<table>
|
<table>
|
||||||
@ -137,23 +140,74 @@
|
|||||||
<script>
|
<script>
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const $errorText = document.getElementById('error_text'),
|
/**
|
||||||
characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=+<>,./?[{()}]!@#$%^&*~`\|'.split('');
|
* @param {HTMLElement} $el
|
||||||
let text = $errorText.innerText, progress = 0;
|
*/
|
||||||
|
const Shuffle = function ($el) {
|
||||||
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=+<>,./?[{()}]!@#$%^&*~`\|'.split(''),
|
||||||
|
$source = $el.querySelector('.source'), $target = $el.querySelector('.target');
|
||||||
|
|
||||||
const scrambleInterval = window.setInterval(function () {
|
let cursor = 0, scrambleInterval = undefined, cursorDelayInterval = undefined, cursorInterval = undefined;
|
||||||
let newText = text;
|
|
||||||
|
|
||||||
for (let i = 0; i < text.length; i++) {
|
/**
|
||||||
if (i >= progress) {
|
* @param {Number} len
|
||||||
newText = newText.substr(0, i) +
|
* @return {string}
|
||||||
characters[Math.round(Math.random() * (characters.length - 1))] +
|
*/
|
||||||
newText.substr(i + 1);
|
const getRandomizedString = function (len) {
|
||||||
|
let s = '';
|
||||||
|
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
s += chars[Math.floor(Math.random() * chars.length)];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$errorText.innerText = newText;
|
return s;
|
||||||
}, 450 / 60);
|
};
|
||||||
|
|
||||||
|
this.start = function () {
|
||||||
|
$source.style.display = 'none';
|
||||||
|
$target.style.display = 'block';
|
||||||
|
|
||||||
|
scrambleInterval = window.setInterval(() => {
|
||||||
|
if (cursor <= $source.innerText.length) {
|
||||||
|
$target.innerText = $source.innerText.substring(0, cursor) + getRandomizedString($source.innerText.length - cursor);
|
||||||
|
}
|
||||||
|
}, 450 / 30);
|
||||||
|
|
||||||
|
cursorDelayInterval = window.setTimeout(() => {
|
||||||
|
cursorInterval = window.setInterval(() => {
|
||||||
|
if (cursor > $source.innerText.length - 1) {
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor++;
|
||||||
|
}, 70);
|
||||||
|
}, 350);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.stop = function () {
|
||||||
|
$source.style.display = 'block';
|
||||||
|
$target.style.display = 'none';
|
||||||
|
$target.innerText = '';
|
||||||
|
cursor = 0;
|
||||||
|
|
||||||
|
if (scrambleInterval !== undefined) {
|
||||||
|
window.clearInterval(scrambleInterval);
|
||||||
|
scrambleInterval = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursorInterval !== undefined) {
|
||||||
|
window.clearInterval(cursorInterval);
|
||||||
|
cursorInterval = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursorDelayInterval !== undefined) {
|
||||||
|
window.clearInterval(cursorDelayInterval);
|
||||||
|
cursorDelayInterval = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
(new Shuffle(document.getElementById('error_text'))).start();
|
||||||
|
|
||||||
// {{ if show_details }}
|
// {{ if show_details }}
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
@ -161,22 +215,11 @@
|
|||||||
}, 550);
|
}, 550);
|
||||||
// {{ end }}
|
// {{ end }}
|
||||||
|
|
||||||
window.setTimeout(function () {
|
|
||||||
let revealInterval = window.setInterval(function () {
|
|
||||||
if (progress < text.length) {
|
|
||||||
progress++;
|
|
||||||
} else {
|
|
||||||
window.clearInterval(revealInterval);
|
|
||||||
window.clearInterval(scrambleInterval);
|
|
||||||
}
|
|
||||||
}, 70);
|
|
||||||
}, 350);
|
|
||||||
|
|
||||||
if (navigator.language.substring(0, 2).toLowerCase() !== 'en') {
|
if (navigator.language.substring(0, 2).toLowerCase() !== 'en') {
|
||||||
((s, p) => { // localize the page (details here - https://github.com/tarampampam/error-pages/tree/master/l10n)
|
((s, p) => { // localize the page (details here - https://github.com/tarampampam/error-pages/tree/master/l10n)
|
||||||
s.src = 'https://cdn.jsdelivr.net/gh/tarampampam/error-pages@2/l10n/l10n.min.js'; // '../l10n/l10n.js';
|
s.src = 'https://cdn.jsdelivr.net/gh/tarampampam/error-pages@2/l10n/l10n.min.js'; // '../l10n/l10n.js';
|
||||||
s.async = s.defer = true;
|
s.async = s.defer = true;
|
||||||
s.addEventListener('load', () => {p.removeChild(s); text = $errorText.innerText});
|
s.addEventListener('load', () => p.removeChild(s));
|
||||||
p.appendChild(s);
|
p.appendChild(s);
|
||||||
})(document.createElement('script'), document.body);
|
})(document.createElement('script'), document.body);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user