2017-05-03 00:04:16 +00:00
|
|
|
import emojify from 'mastodon/emoji';
|
2017-04-25 15:37:51 +00:00
|
|
|
import { length } from 'stringz';
|
2017-05-07 13:22:54 +00:00
|
|
|
import { default as dateFormat } from 'date-fns/format';
|
|
|
|
import distanceInWordsStrict from 'date-fns/distance_in_words_strict';
|
2016-12-18 14:20:39 +00:00
|
|
|
|
2017-05-03 00:04:16 +00:00
|
|
|
window.jQuery = window.$ = require('jquery');
|
|
|
|
require('jquery-ujs');
|
|
|
|
require.context('../images/', true);
|
|
|
|
|
2017-05-07 13:22:54 +00:00
|
|
|
const parseFormat = (format) => format.replace(/%(\w)/g, (_, modifier) => {
|
|
|
|
switch (modifier) {
|
|
|
|
case '%':
|
|
|
|
return '%';
|
|
|
|
case 'a':
|
|
|
|
return 'ddd';
|
|
|
|
case 'A':
|
|
|
|
return 'ddd';
|
|
|
|
case 'b':
|
|
|
|
return 'MMM';
|
|
|
|
case 'B':
|
|
|
|
return 'MMMM';
|
|
|
|
case 'd':
|
|
|
|
return 'DD';
|
|
|
|
case 'H':
|
|
|
|
return 'HH';
|
|
|
|
case 'I':
|
|
|
|
return 'hh';
|
|
|
|
case 'l':
|
|
|
|
return 'H';
|
|
|
|
case 'm':
|
|
|
|
return 'M';
|
|
|
|
case 'M':
|
|
|
|
return 'mm';
|
|
|
|
case 'p':
|
|
|
|
return 'A';
|
|
|
|
case 'S':
|
|
|
|
return 'ss';
|
|
|
|
case 'w':
|
|
|
|
return 'd';
|
|
|
|
case 'y':
|
|
|
|
return 'YY';
|
|
|
|
case 'Y':
|
|
|
|
return 'YYYY';
|
|
|
|
default:
|
|
|
|
return `%${modifier}`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-18 14:20:39 +00:00
|
|
|
$(() => {
|
2017-01-10 03:40:45 +00:00
|
|
|
$.each($('.emojify'), (_, content) => {
|
2016-12-18 14:20:39 +00:00
|
|
|
const $content = $(content);
|
|
|
|
$content.html(emojify($content.html()));
|
|
|
|
});
|
2016-12-18 18:47:11 +00:00
|
|
|
|
2017-05-07 13:22:54 +00:00
|
|
|
$('time[data-format]').each((_, content) => {
|
|
|
|
const $content = $(content);
|
|
|
|
const format = parseFormat($content.data('format'));
|
|
|
|
const formattedDate = dateFormat($content.attr('datetime'), format);
|
|
|
|
$content.text(formattedDate);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('time.time-ago').each((_, content) => {
|
|
|
|
const $content = $(content);
|
|
|
|
const timeAgo = distanceInWordsStrict(new Date(), $content.attr('datetime'), { addSuffix: true });
|
|
|
|
$content.text(timeAgo);
|
|
|
|
});
|
|
|
|
|
2016-12-18 18:47:11 +00:00
|
|
|
$('.video-player video').on('click', e => {
|
|
|
|
if (e.target.paused) {
|
|
|
|
e.target.play();
|
|
|
|
} else {
|
|
|
|
e.target.pause();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.media-spoiler').on('click', e => {
|
|
|
|
$(e.target).hide();
|
|
|
|
});
|
2016-12-20 23:13:13 +00:00
|
|
|
|
|
|
|
$('.webapp-btn').on('click', e => {
|
|
|
|
if (e.button === 0) {
|
|
|
|
e.preventDefault();
|
|
|
|
window.location.href = $(e.target).attr('href');
|
|
|
|
}
|
|
|
|
});
|
2017-03-31 11:54:36 +00:00
|
|
|
|
|
|
|
$('.status__content__spoiler-link').on('click', e => {
|
|
|
|
e.preventDefault();
|
|
|
|
const contentEl = $(e.target).parent().parent().find('div');
|
|
|
|
|
|
|
|
if (contentEl.is(':visible')) {
|
|
|
|
contentEl.hide();
|
|
|
|
$(e.target).parent().attr('style', 'margin-bottom: 0');
|
|
|
|
} else {
|
|
|
|
contentEl.show();
|
|
|
|
$(e.target).parent().attr('style', null);
|
|
|
|
}
|
|
|
|
});
|
2017-04-21 16:17:21 +00:00
|
|
|
|
|
|
|
$('.account_display_name').on('input', e => {
|
2017-04-25 15:37:51 +00:00
|
|
|
$('.name-counter').text(30 - length($(e.target).val()));
|
2017-04-21 16:17:21 +00:00
|
|
|
});
|
2017-05-03 00:04:16 +00:00
|
|
|
|
2017-04-21 16:17:21 +00:00
|
|
|
$('.account_note').on('input', e => {
|
2017-04-25 15:37:51 +00:00
|
|
|
$('.note-counter').text(160 - length($(e.target).val()));
|
2017-04-21 16:17:21 +00:00
|
|
|
});
|
2016-12-18 14:20:39 +00:00
|
|
|
});
|