Port a few public.js changes from upstream, move some code around
glitch-soc's public.js was a bit out of date, and code was put inappropriately to the common public.js
This commit is contained in:
parent
e8ae77236b
commit
d1da0a1086
|
@ -6,16 +6,6 @@ import ready from '../mastodon/ready';
|
||||||
const { delegate } = require('rails-ujs');
|
const { delegate } = require('rails-ujs');
|
||||||
const { length } = require('stringz');
|
const { length } = require('stringz');
|
||||||
|
|
||||||
ready(() => {
|
|
||||||
const history = createHistory();
|
|
||||||
const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
|
|
||||||
const location = history.location;
|
|
||||||
if (detailedStatuses.length == 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
|
|
||||||
detailedStatuses[0].scrollIntoView();
|
|
||||||
history.replace(location.pathname, {...location.state, scrolledToDetailedStatus: true});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
|
delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
|
||||||
if (button !== 0) {
|
if (button !== 0) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2,14 +2,15 @@ import loadPolyfills from 'flavours/glitch/util/load_polyfills';
|
||||||
import ready from 'flavours/glitch/util/ready';
|
import ready from 'flavours/glitch/util/ready';
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
const IntlRelativeFormat = require('intl-relativeformat').default;
|
const IntlMessageFormat = require('intl-messageformat').default;
|
||||||
|
const { timeAgoString } = require('flavours/glitch/components/relative_timestamp');
|
||||||
const emojify = require('flavours/glitch/util/emoji').default;
|
const emojify = require('flavours/glitch/util/emoji').default;
|
||||||
const { getLocale } = require('locales');
|
const { getLocale } = require('locales');
|
||||||
const { localeData } = getLocale();
|
const { messages } = getLocale();
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const ReactDOM = require('react-dom');
|
const ReactDOM = require('react-dom');
|
||||||
|
const Rellax = require('rellax');
|
||||||
localeData.forEach(IntlRelativeFormat.__addLocaleData);
|
const createHistory = require('history').createBrowserHistory;
|
||||||
|
|
||||||
ready(() => {
|
ready(() => {
|
||||||
const locale = document.documentElement.lang;
|
const locale = document.documentElement.lang;
|
||||||
|
@ -22,8 +23,6 @@ function main() {
|
||||||
minute: 'numeric',
|
minute: 'numeric',
|
||||||
});
|
});
|
||||||
|
|
||||||
const relativeFormat = new IntlRelativeFormat(locale);
|
|
||||||
|
|
||||||
[].forEach.call(document.querySelectorAll('.emojify'), (content) => {
|
[].forEach.call(document.querySelectorAll('.emojify'), (content) => {
|
||||||
content.innerHTML = emojify(content.innerHTML);
|
content.innerHTML = emojify(content.innerHTML);
|
||||||
});
|
});
|
||||||
|
@ -38,16 +37,13 @@ function main() {
|
||||||
|
|
||||||
[].forEach.call(document.querySelectorAll('time.time-ago'), (content) => {
|
[].forEach.call(document.querySelectorAll('time.time-ago'), (content) => {
|
||||||
const datetime = new Date(content.getAttribute('datetime'));
|
const datetime = new Date(content.getAttribute('datetime'));
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
content.title = dateTimeFormat.format(datetime);
|
content.title = dateTimeFormat.format(datetime);
|
||||||
content.textContent = relativeFormat.format(datetime);
|
content.textContent = timeAgoString({
|
||||||
});
|
formatMessage: ({ id, defaultMessage }, values) => (new IntlMessageFormat(messages[id] || defaultMessage, locale)).format(values),
|
||||||
|
formatDate: (date, options) => (new Intl.DateTimeFormat(locale, options)).format(date),
|
||||||
[].forEach.call(document.querySelectorAll('.logo-button'), (content) => {
|
}, datetime, now, now.getFullYear());
|
||||||
content.addEventListener('click', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
window.open(e.target.href, 'mastodon-intent', 'width=400,height=400,resizable=no,menubar=no,status=no,scrollbars=yes');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const reactComponents = document.querySelectorAll('[data-component]');
|
const reactComponents = document.querySelectorAll('[data-component]');
|
||||||
|
@ -55,11 +51,27 @@ function main() {
|
||||||
import(/* webpackChunkName: "containers/media_container" */ 'flavours/glitch/containers/media_container')
|
import(/* webpackChunkName: "containers/media_container" */ 'flavours/glitch/containers/media_container')
|
||||||
.then(({ default: MediaContainer }) => {
|
.then(({ default: MediaContainer }) => {
|
||||||
const content = document.createElement('div');
|
const content = document.createElement('div');
|
||||||
|
|
||||||
ReactDOM.render(<MediaContainer locale={locale} components={reactComponents} />, content);
|
ReactDOM.render(<MediaContainer locale={locale} components={reactComponents} />, content);
|
||||||
document.body.appendChild(content);
|
document.body.appendChild(content);
|
||||||
})
|
})
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parallaxComponents = document.querySelectorAll('.parallax');
|
||||||
|
|
||||||
|
if (parallaxComponents.length > 0 ) {
|
||||||
|
new Rellax('.parallax', { speed: -1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const history = createHistory();
|
||||||
|
const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
|
||||||
|
const location = history.location;
|
||||||
|
|
||||||
|
if (detailedStatuses.length === 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
|
||||||
|
detailedStatuses[0].scrollIntoView();
|
||||||
|
history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue