]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/packs/public.js
1 import emojify
from 'mastodon/emoji';
2 import { length
} from 'stringz';
3 import { default as dateFormat
} from 'date-fns/format';
4 import distanceInWordsStrict
from 'date-fns/distance_in_words_strict';
5 import { delegate
} from 'rails-ujs';
7 require
.context('../images/', true);
9 const parseFormat
= (format
) => format
.replace(/%(\w)/g, (_
, modifier
) => {
44 return `%${modifier}`;
48 document
.addEventListener('DOMContentLoaded', () => {
49 for (const content
of document
.querySelectorAll('.emojify')) {
50 content
.innerHTML
= emojify(content
.innerHTML
);
53 for (const content
of document
.querySelectorAll('time[data-format]')) {
54 const format
= parseFormat(content
.dataset
.format
);
55 const formattedDate
= dateFormat(content
.getAttribute('datetime'), format
);
56 content
.textContent
= formattedDate
;
59 for (const content
of document
.querySelectorAll('time.time-ago')) {
60 const timeAgo
= distanceInWordsStrict(new Date(), content
.getAttribute('datetime'), {
63 content
.textContent
= timeAgo
;
66 delegate(document
, '.video-player video', 'click', ({ target
}) => {
74 delegate(document
, '.media-spoiler', 'click', ({ target
}) => {
75 target
.style
.display
= 'none';
78 delegate(document
, '.webapp-btn', 'click', ({ target
, button
}) => {
82 window
.location
.href
= target
.href
;
86 delegate(document
, '.status__content__spoiler-link', 'click', ({ target
}) => {
87 const contentEl
= target
.parentNode
.parentNode
.querySelector('.e-content');
88 if (contentEl
.style
.display
=== 'block') {
89 contentEl
.style
.display
= 'none';
90 target
.parentNode
.style
.marginBottom
= 0;
92 contentEl
.style
.display
= 'block';
93 target
.parentNode
.style
.marginBottom
= null;
98 delegate(document
, '.account_display_name', 'input', ({ target
}) => {
99 const [nameCounter
] = document
.getElementsByClassName('name-counter');
100 nameCounter
.textContent
= 30 - length(target
.value
);
103 delegate(document
, '.account_note', 'input', ({ target
}) => {
104 const [noteCounter
] = document
.getElementsByClassName('note-counter');
105 noteCounter
.textContent
= 160 - length(target
.value
);
This page took 0.158935 seconds and 5 git commands to generate.