]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/packs/public.js
1 import loadPolyfills
from '../mastodon/load_polyfills';
2 import ready
from '../mastodon/ready';
3 import { start
} from '../mastodon/common';
7 window
.addEventListener('message', e
=> {
8 const data
= e
.data
|| {};
10 if (!window
.parent
|| data
.type
!== 'setHeight') {
15 window
.parent
.postMessage({
18 height: document
.getElementsByTagName('html')[0].scrollHeight
,
24 const IntlMessageFormat
= require('intl-messageformat').default;
25 const { timeAgoString
} = require('../mastodon/components/relative_timestamp');
26 const { delegate
} = require('rails-ujs');
27 const emojify
= require('../mastodon/features/emoji/emoji').default;
28 const { getLocale
} = require('../mastodon/locales');
29 const { messages
} = getLocale();
30 const React
= require('react');
31 const ReactDOM
= require('react-dom');
32 const Rellax
= require('rellax');
33 const createHistory
= require('history').createBrowserHistory
;
36 const locale
= document
.documentElement
.lang
;
38 const dateTimeFormat
= new Intl
.DateTimeFormat(locale
, {
46 [].forEach
.call(document
.querySelectorAll('.emojify'), (content
) => {
47 content
.innerHTML
= emojify(content
.innerHTML
);
50 [].forEach
.call(document
.querySelectorAll('time.formatted'), (content
) => {
51 const datetime
= new Date(content
.getAttribute('datetime'));
52 const formattedDate
= dateTimeFormat
.format(datetime
);
54 content
.title
= formattedDate
;
55 content
.textContent
= formattedDate
;
58 [].forEach
.call(document
.querySelectorAll('time.time-ago'), (content
) => {
59 const datetime
= new Date(content
.getAttribute('datetime'));
60 const now
= new Date();
62 content
.title
= dateTimeFormat
.format(datetime
);
63 content
.textContent
= timeAgoString({
64 formatMessage: ({ id
, defaultMessage
}, values
) => (new IntlMessageFormat(messages
[id
] || defaultMessage
, locale
)).format(values
),
65 formatDate: (date
, options
) => (new Intl
.DateTimeFormat(locale
, options
)).format(date
),
66 }, datetime
, now
, datetime
.getFullYear());
69 const reactComponents
= document
.querySelectorAll('[data-component]');
71 if (reactComponents
.length
> 0) {
72 import(/* webpackChunkName: "containers/media_container" */ '../mastodon/containers/media_container')
73 .then(({ default: MediaContainer
}) => {
74 const content
= document
.createElement('div');
76 ReactDOM
.render(<MediaContainer locale
={locale
} components
={reactComponents
} />, content
);
77 document
.body
.appendChild(content
);
79 .catch(error
=> console
.error(error
));
82 const parallaxComponents
= document
.querySelectorAll('.parallax');
84 if (parallaxComponents
.length
> 0 ) {
85 new Rellax('.parallax', { speed: -1 });
88 const history
= createHistory();
89 const detailedStatuses
= document
.querySelectorAll('.public-layout .detailed-status');
90 const location
= history
.location
;
92 if (detailedStatuses
.length
=== 1 && (!location
.state
|| !location
.state
.scrolledToDetailedStatus
)) {
93 detailedStatuses
[0].scrollIntoView();
94 history
.replace(location
.pathname
, { ...location
.state
, scrolledToDetailedStatus: true });
98 delegate(document
, '.webapp-btn', 'click', ({ target
, button
}) => {
102 window
.location
.href
= target
.href
;
106 delegate(document
, '.status__content__spoiler-link', 'click', ({ target
}) => {
107 const contentEl
= target
.parentNode
.parentNode
.querySelector('.e-content');
109 if (contentEl
.style
.display
=== 'block') {
110 contentEl
.style
.display
= 'none';
111 target
.parentNode
.style
.marginBottom
= 0;
113 contentEl
.style
.display
= 'block';
114 target
.parentNode
.style
.marginBottom
= null;
120 delegate(document
, '.modal-button', 'click', e
=> {
125 if (e
.target
.nodeName
!== 'A') {
126 href
= e
.target
.parentNode
.href
;
128 href
= e
.target
.href
;
131 window
.open(href
, 'mastodon-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes');
134 delegate(document
, '#account_display_name', 'input', ({ target
}) => {
135 const name
= document
.querySelector('.card .display-name strong');
138 name
.innerHTML
= emojify(target
.value
);
142 delegate(document
, '#account_avatar', 'change', ({ target
}) => {
143 const avatar
= document
.querySelector('.card .avatar img');
144 const [file
] = target
.files
|| [];
145 const url
= file
? URL
.createObjectURL(file
) : avatar
.dataset
.originalSrc
;
150 delegate(document
, '#account_header', 'change', ({ target
}) => {
151 const header
= document
.querySelector('.card .card__img img');
152 const [file
] = target
.files
|| [];
153 const url
= file
? URL
.createObjectURL(file
) : header
.dataset
.originalSrc
;
158 delegate(document
, '#account_locked', 'change', ({ target
}) => {
159 const lock
= document
.querySelector('.card .display-name i');
161 if (target
.checked
) {
162 lock
.style
.display
= 'inline';
164 lock
.style
.display
= 'none';
168 delegate(document
, '.input-copy input', 'click', ({ target
}) => {
172 delegate(document
, '.input-copy button', 'click', ({ target
}) => {
173 const input
= target
.parentNode
.querySelector('.input-copy__wrapper input');
179 if (document
.execCommand('copy')) {
181 target
.parentNode
.classList
.add('copied');
184 target
.parentNode
.classList
.remove('copied');
193 loadPolyfills().then(main
).catch(error
=> {
194 console
.error(error
);
This page took 0.123757 seconds and 4 git commands to generate.