Remove jquery-ujs (#2939)

* Remove jquery-ujs

* fix for eslint
signup-info-prompt
Yamagishi Kazutoshi 2017-05-09 21:50:43 +09:00 committed by Eugen Rochko
parent 584b45530c
commit 42eb841dc2
5 changed files with 53 additions and 56 deletions

View File

@ -1,7 +1,7 @@
import api, { getLinks } from '../api' import api, { getLinks } from '../api'
import Immutable from 'immutable'; import Immutable from 'immutable';
import IntlMessageFormat from 'intl-messageformat'; import IntlMessageFormat from 'intl-messageformat';
import { unescape } from 'lodash';
import { fetchRelationships } from './accounts'; import { fetchRelationships } from './accounts';
export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE'; export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE';
@ -25,6 +25,8 @@ const fetchRelatedRelationships = (dispatch, notifications) => {
} }
}; };
const unescapeHTML = (html) => unescape(html).replace(/<\/?\w+(?:\s[^>]*)?>/g, '');
export function updateNotifications(notification, intlMessages, intlLocale) { export function updateNotifications(notification, intlMessages, intlLocale) {
return (dispatch, getState) => { return (dispatch, getState) => {
const showAlert = getState().getIn(['settings', 'notifications', 'alerts', notification.type], true); const showAlert = getState().getIn(['settings', 'notifications', 'alerts', notification.type], true);
@ -43,7 +45,7 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
// Desktop notifications // Desktop notifications
if (typeof window.Notification !== 'undefined' && showAlert) { if (typeof window.Notification !== 'undefined' && showAlert) {
const title = new IntlMessageFormat(intlMessages[`notification.${notification.type}`], intlLocale).format({ name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username }); const title = new IntlMessageFormat(intlMessages[`notification.${notification.type}`], intlLocale).format({ name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username });
const body = (notification.status && notification.status.spoiler_text.length > 0) ? notification.status.spoiler_text : $('<p>').html(notification.status ? notification.status.content : '').text(); const body = (notification.status && notification.status.spoiler_text.length > 0) ? notification.status.spoiler_text : unescapeHTML(notification.status ? notification.status.content : '');
new Notification(title, { body, icon: notification.account.avatar, tag: notification.id }); new Notification(title, { body, icon: notification.account.avatar, tag: notification.id });
} }

View File

@ -1,6 +1,7 @@
import Mastodon from 'mastodon/containers/mastodon'; import Mastodon from 'mastodon/containers/mastodon';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import Rails from 'rails-ujs';
import 'font-awesome/css/font-awesome.css'; import 'font-awesome/css/font-awesome.css';
import '../styles/application.scss'; import '../styles/application.scss';
@ -9,10 +10,10 @@ if (!window.Intl) {
require('intl/locale-data/jsonp/en.js'); require('intl/locale-data/jsonp/en.js');
} }
window.jQuery = window.$ = require('jquery');
window.Perf = require('react-addons-perf'); window.Perf = require('react-addons-perf');
require('jquery-ujs'); Rails.start();
require.context('../images/', true); require.context('../images/', true);
const customContext = require.context('../../assets/stylesheets/', false); const customContext = require.context('../../assets/stylesheets/', false);

View File

@ -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);
}); });
}); });

View File

@ -57,7 +57,6 @@
"http-link-header": "^0.8.0", "http-link-header": "^0.8.0",
"immutable": "^3.8.1", "immutable": "^3.8.1",
"intl": "^1.2.5", "intl": "^1.2.5",
"jquery-ujs": "^1.2.2",
"js-yaml": "^3.8.3", "js-yaml": "^3.8.3",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"node-sass": "^4.5.2", "node-sass": "^4.5.2",
@ -70,6 +69,7 @@
"prop-types": "^15.5.8", "prop-types": "^15.5.8",
"punycode": "^2.1.0", "punycode": "^2.1.0",
"rails-erb-loader": "^5.0.0", "rails-erb-loader": "^5.0.0",
"rails-ujs": "^5.1.0",
"react": "^15.5.4", "react": "^15.5.4",
"react-addons-perf": "^15.4.2", "react-addons-perf": "^15.4.2",
"react-addons-shallow-compare": "^15.5.2", "react-addons-shallow-compare": "^15.5.2",

View File

@ -3639,16 +3639,6 @@ jodid25519@^1.0.0:
dependencies: dependencies:
jsbn "~0.1.0" jsbn "~0.1.0"
jquery-ujs@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/jquery-ujs/-/jquery-ujs-1.2.2.tgz#6a8ef1020e6b6dda385b90a4bddc128c21c56397"
dependencies:
jquery ">=1.8.0"
jquery@>=1.8.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.2.1.tgz#5c4d9de652af6cd0a770154a631bba12b015c787"
js-base64@^2.1.9: js-base64@^2.1.9:
version "2.1.9" version "2.1.9"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.1.9.tgz#f0e80ae039a4bd654b5f281fc93f04a914a7fcce" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.1.9.tgz#f0e80ae039a4bd654b5f281fc93f04a914a7fcce"
@ -5404,6 +5394,10 @@ rails-erb-loader@^5.0.0:
loader-utils "^1.1.0" loader-utils "^1.1.0"
lodash.defaults "^4.2.0" lodash.defaults "^4.2.0"
rails-ujs@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/rails-ujs/-/rails-ujs-5.1.0.tgz#23ff5ce4bf21e09b33c4d6d7f8d1a51af05edde7"
randomatic@^1.1.3: randomatic@^1.1.3:
version "1.1.5" version "1.1.5"
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.5.tgz#5e9ef5f2d573c67bd2b8124ae90b5156e457840b" resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.5.tgz#5e9ef5f2d573c67bd2b8124ae90b5156e457840b"