|
|
@ -2,9 +2,8 @@ import emojify from 'mastodon/emoji';
|
|
|
|
import { length } from 'stringz';
|
|
|
|
import { length } from 'stringz';
|
|
|
|
import { default as dateFormat } from 'date-fns/format';
|
|
|
|
import { default as dateFormat } from 'date-fns/format';
|
|
|
|
import distanceInWordsStrict from 'date-fns/distance_in_words_strict';
|
|
|
|
import distanceInWordsStrict from 'date-fns/distance_in_words_strict';
|
|
|
|
|
|
|
|
import { delegate } from 'rails-ujs';
|
|
|
|
|
|
|
|
|
|
|
|
window.jQuery = window.$ = require('jquery');
|
|
|
|
|
|
|
|
require('jquery-ujs');
|
|
|
|
|
|
|
|
require.context('../images/', true);
|
|
|
|
require.context('../images/', true);
|
|
|
|
|
|
|
|
|
|
|
|
const parseFormat = (format) => format.replace(/%(\w)/g, (_, modifier) => {
|
|
|
|
const parseFormat = (format) => format.replace(/%(\w)/g, (_, modifier) => {
|
|
|
@ -46,62 +45,63 @@ const parseFormat = (format) => format.replace(/%(\w)/g, (_, modifier) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$(() => {
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
$.each($('.emojify'), (_, content) => {
|
|
|
|
for (const content of document.getElementsByClassName('emojify')) {
|
|
|
|
const $content = $(content);
|
|
|
|
content.innerHTML = emojify(content.innerHTML);
|
|
|
|
$content.html(emojify($content.html()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('time[data-format]').each((_, content) => {
|
|
|
|
for (const content of document.querySelectorAll('time[data-format]')) {
|
|
|
|
const $content = $(content);
|
|
|
|
const format = parseFormat(content.dataset.format);
|
|
|
|
const format = parseFormat($content.data('format'));
|
|
|
|
const formattedDate = dateFormat(content.getAttribute('datetime'), format);
|
|
|
|
const formattedDate = dateFormat($content.attr('datetime'), format);
|
|
|
|
content.textContent = formattedDate;
|
|
|
|
$content.text(formattedDate);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('time.time-ago').each((_, content) => {
|
|
|
|
for (const content of document.querySelectorAll('time.time-ago')) {
|
|
|
|
const $content = $(content);
|
|
|
|
const timeAgo = distanceInWordsStrict(new Date(), content.getAttribute('datetime'), {
|
|
|
|
const timeAgo = distanceInWordsStrict(new Date(), $content.attr('datetime'), { addSuffix: true });
|
|
|
|
addSuffix: true,
|
|
|
|
$content.text(timeAgo);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
content.textContent = timeAgo;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$('.video-player video').on('click', e => {
|
|
|
|
delegate(document, '.video-player video', 'click', ({ target }) => {
|
|
|
|
if (e.target.paused) {
|
|
|
|
if (target.paused) {
|
|
|
|
e.target.play();
|
|
|
|
target.play();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
e.target.pause();
|
|
|
|
target.pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('.media-spoiler').on('click', e => {
|
|
|
|
delegate(document, '.media-spoiler', 'click', ({ target }) => {
|
|
|
|
$(e.target).hide();
|
|
|
|
target.style.display = 'none';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('.webapp-btn').on('click', e => {
|
|
|
|
delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
|
|
|
|
if (e.button === 0) {
|
|
|
|
if (button !== 0) {
|
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
window.location.href = $(e.target).attr('href');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.location.href = target.href;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('.status__content__spoiler-link').on('click', e => {
|
|
|
|
delegate(document, '.status__content__spoiler-link', 'click', ({ target }) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const contentEl = target.parentNode.parentNode.querySelector('.e-content');
|
|
|
|
const contentEl = $(e.target).parent().parent().find('div');
|
|
|
|
if (contentEl.style.display === 'block') {
|
|
|
|
|
|
|
|
contentEl.style.display = 'none';
|
|
|
|
if (contentEl.is(':visible')) {
|
|
|
|
target.parentNode.style.marginBottom = 0;
|
|
|
|
contentEl.hide();
|
|
|
|
|
|
|
|
$(e.target).parent().attr('style', 'margin-bottom: 0');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
contentEl.show();
|
|
|
|
contentEl.style.display = 'block';
|
|
|
|
$(e.target).parent().attr('style', null);
|
|
|
|
target.parentNode.style.marginBottom = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('.account_display_name').on('input', e => {
|
|
|
|
delegate(document, '.account_display_name', 'input', ({ target }) => {
|
|
|
|
$('.name-counter').text(30 - length($(e.target).val()));
|
|
|
|
const [nameCounter, ] = document.getElementsByClassName('name-counter');
|
|
|
|
|
|
|
|
nameCounter.textContent = 30 - length(target.value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('.account_note').on('input', e => {
|
|
|
|
delegate(document, '.account_note', 'input', ({ target }) => {
|
|
|
|
$('.note-counter').text(160 - length($(e.target).val()));
|
|
|
|
const [noteCounter, ] = document.getElementsByClassName('.note-counter');
|
|
|
|
|
|
|
|
noteCounter.textContent = 160 - length(target.value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|