From d1da0a1086fa25f22739277fbf32ba1b3745317d Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Thu, 10 Jan 2019 12:24:02 +0100 Subject: 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 --- app/javascript/flavours/glitch/packs/public.js | 40 +++++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'app/javascript/flavours/glitch/packs') diff --git a/app/javascript/flavours/glitch/packs/public.js b/app/javascript/flavours/glitch/packs/public.js index 78e8f1053..996f8f3d1 100644 --- a/app/javascript/flavours/glitch/packs/public.js +++ b/app/javascript/flavours/glitch/packs/public.js @@ -2,14 +2,15 @@ import loadPolyfills from 'flavours/glitch/util/load_polyfills'; import ready from 'flavours/glitch/util/ready'; 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 { getLocale } = require('locales'); - const { localeData } = getLocale(); + const { messages } = getLocale(); const React = require('react'); const ReactDOM = require('react-dom'); - - localeData.forEach(IntlRelativeFormat.__addLocaleData); + const Rellax = require('rellax'); + const createHistory = require('history').createBrowserHistory; ready(() => { const locale = document.documentElement.lang; @@ -22,8 +23,6 @@ function main() { minute: 'numeric', }); - const relativeFormat = new IntlRelativeFormat(locale); - [].forEach.call(document.querySelectorAll('.emojify'), (content) => { content.innerHTML = emojify(content.innerHTML); }); @@ -38,16 +37,13 @@ function main() { [].forEach.call(document.querySelectorAll('time.time-ago'), (content) => { const datetime = new Date(content.getAttribute('datetime')); + const now = new Date(); content.title = dateTimeFormat.format(datetime); - content.textContent = relativeFormat.format(datetime); - }); - - [].forEach.call(document.querySelectorAll('.logo-button'), (content) => { - 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'); - }); + 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), + }, datetime, now, now.getFullYear()); }); const reactComponents = document.querySelectorAll('[data-component]'); @@ -55,11 +51,27 @@ function main() { import(/* webpackChunkName: "containers/media_container" */ 'flavours/glitch/containers/media_container') .then(({ default: MediaContainer }) => { const content = document.createElement('div'); + ReactDOM.render(, content); document.body.appendChild(content); }) .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 }); + } }); } -- cgit From 394525e32994e605093c87d3a9fad2a4202f3401 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Thu, 10 Jan 2019 20:28:24 +0100 Subject: [Glitch] Postpone scroll-to-detailed status after react components are loaded Port 70801b850c78d7879182eeba4eae509af42fafeb to glitch-soc --- app/javascript/flavours/glitch/packs/public.js | 28 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'app/javascript/flavours/glitch/packs') diff --git a/app/javascript/flavours/glitch/packs/public.js b/app/javascript/flavours/glitch/packs/public.js index 996f8f3d1..342c5265e 100644 --- a/app/javascript/flavours/glitch/packs/public.js +++ b/app/javascript/flavours/glitch/packs/public.js @@ -12,6 +12,17 @@ function main() { const Rellax = require('rellax'); const createHistory = require('history').createBrowserHistory; + const scrollToDetailedStatus = () => { + 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 }); + } + }; + ready(() => { const locale = document.documentElement.lang; @@ -54,8 +65,14 @@ function main() { ReactDOM.render(, content); document.body.appendChild(content); + scrollToDetailedStatus(); }) - .catch(error => console.error(error)); + .catch(error => { + console.error(error); + scrollToDetailedStatus(); + }); + } else { + scrollToDetailedStatus(); } const parallaxComponents = document.querySelectorAll('.parallax'); @@ -63,15 +80,6 @@ function main() { 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 }); - } }); } -- cgit