forked from cybrespace/mastodon
Check ready state of document in public pages (#3652)
* Check ready state of document in public pages * add check interactive
This commit is contained in:
parent
e3fae6f52c
commit
140e73bc82
|
@ -10,7 +10,7 @@ require.context('../images/', true);
|
||||||
const { localeData } = getLocale();
|
const { localeData } = getLocale();
|
||||||
localeData.forEach(IntlRelativeFormat.__addLocaleData);
|
localeData.forEach(IntlRelativeFormat.__addLocaleData);
|
||||||
|
|
||||||
function main() {
|
function loaded() {
|
||||||
const locale = document.documentElement.lang;
|
const locale = document.documentElement.lang;
|
||||||
const dateTimeFormat = new Intl.DateTimeFormat(locale, {
|
const dateTimeFormat = new Intl.DateTimeFormat(locale, {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
|
@ -21,24 +21,30 @@ function main() {
|
||||||
});
|
});
|
||||||
const relativeFormat = new IntlRelativeFormat(locale);
|
const relativeFormat = new IntlRelativeFormat(locale);
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
[].forEach.call(document.querySelectorAll('.emojify'), (content) => {
|
||||||
[].forEach.call(document.querySelectorAll('.emojify'), (content) => {
|
content.innerHTML = emojify(content.innerHTML);
|
||||||
content.innerHTML = emojify(content.innerHTML);
|
|
||||||
});
|
|
||||||
|
|
||||||
[].forEach.call(document.querySelectorAll('time.formatted'), (content) => {
|
|
||||||
const datetime = new Date(content.getAttribute('datetime'));
|
|
||||||
const formattedDate = dateTimeFormat.format(datetime);
|
|
||||||
content.title = formattedDate;
|
|
||||||
content.textContent = formattedDate;
|
|
||||||
});
|
|
||||||
|
|
||||||
[].forEach.call(document.querySelectorAll('time.time-ago'), (content) => {
|
|
||||||
const datetime = new Date(content.getAttribute('datetime'));
|
|
||||||
content.textContent = relativeFormat.format(datetime);;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[].forEach.call(document.querySelectorAll('time.formatted'), (content) => {
|
||||||
|
const datetime = new Date(content.getAttribute('datetime'));
|
||||||
|
const formattedDate = dateTimeFormat.format(datetime);
|
||||||
|
content.title = formattedDate;
|
||||||
|
content.textContent = formattedDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
[].forEach.call(document.querySelectorAll('time.time-ago'), (content) => {
|
||||||
|
const datetime = new Date(content.getAttribute('datetime'));
|
||||||
|
content.textContent = relativeFormat.format(datetime);;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
||||||
|
loaded();
|
||||||
|
} else {
|
||||||
|
document.addEventListener('DOMContentLoaded', loaded);
|
||||||
|
}
|
||||||
|
|
||||||
delegate(document, '.video-player video', 'click', ({ target }) => {
|
delegate(document, '.video-player video', 'click', ({ target }) => {
|
||||||
if (target.paused) {
|
if (target.paused) {
|
||||||
target.play();
|
target.play();
|
||||||
|
|
Loading…
Reference in New Issue