]> cat aescling's git repositories - mastodon.git/commitdiff
Merge branch 'master' into glitch-soc/merge-upstream
authorThibaut Girka <thib@sitedethib.com>
Sun, 5 Apr 2020 16:32:06 +0000 (18:32 +0200)
committerThibaut Girka <thib@sitedethib.com>
Sun, 5 Apr 2020 16:32:06 +0000 (18:32 +0200)
Conflicts:
- `app/javascript/packs/public.js`:
  Upstream modified code that we split between multiple files due
  to glitch-soc's theming system.
  Ported those changes.

13 files changed:
1  2 
Gemfile
Gemfile.lock
app/javascript/core/public.js
app/javascript/flavours/glitch/packs/public.js
app/javascript/packs/public.js
app/models/status.rb
config/locales/ja.yml
config/locales/pl.yml
config/locales/simple_form.pl.yml
db/schema.rb
lib/mastodon/version.rb
package.json
yarn.lock

diff --cc Gemfile
Simple merge
diff --cc Gemfile.lock
Simple merge
index 344c051819f417bd88559afc7c51f0db6d06f11e,0000000000000000000000000000000000000000..39f198fe7214d52e1e1dd515653e2e259f62af40
mode 100644,000000..100644
--- /dev/null
@@@ -1,66 -1,0 +1,52 @@@
- delegate(document, '.status__content__spoiler-link', 'click', function() {
-   const contentEl = this.parentNode.parentNode.querySelector('.e-content');
-   if (contentEl.style.display === 'block') {
-     contentEl.style.display = 'none';
-     this.parentNode.style.marginBottom = 0;
-   } else {
-     contentEl.style.display = 'block';
-     this.parentNode.style.marginBottom = null;
-   }
-   return false;
- });
 +//  This file will be loaded on public pages, regardless of theme.
 +
 +import createHistory from 'history/createBrowserHistory';
 +import ready from '../mastodon/ready';
 +
 +const { delegate } = require('@rails/ujs');
 +const { length } = require('stringz');
 +
 +delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
 +  if (button !== 0) {
 +    return true;
 +  }
 +  window.location.href = target.href;
 +  return false;
 +});
 +
 +delegate(document, '.modal-button', 'click', e => {
 +  e.preventDefault();
 +
 +  let href;
 +
 +  if (e.target.nodeName !== 'A') {
 +    href = e.target.parentNode.href;
 +  } else {
 +    href = e.target.href;
 +  }
 +
 +  window.open(href, 'mastodon-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes');
 +});
 +
 +const getProfileAvatarAnimationHandler = (swapTo) => {
 +  //animate avatar gifs on the profile page when moused over
 +  return ({ target }) => {
 +    const swapSrc = target.getAttribute(swapTo);
 +    //only change the img source if autoplay is off and the image src is actually different
 +    if(target.getAttribute('data-autoplay') !== 'true' && target.src !== swapSrc) {
 +      target.src = swapSrc;
 +    }
 +  };
 +};
 +
 +delegate(document, 'img#profile_page_avatar', 'mouseover', getProfileAvatarAnimationHandler('data-original'));
 +
 +delegate(document, 'img#profile_page_avatar', 'mouseout', getProfileAvatarAnimationHandler('data-static'));
 +
 +delegate(document, '#account_header', 'change', ({ target }) => {
 +  const header = document.querySelector('.card .card__img img');
 +  const [file] = target.files || [];
 +  const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
 +
 +  header.src = url;
 +});
index 066479fa67a302872a7eaf42b32b26f8578bfa1e,0000000000000000000000000000000000000000..e5a567205d64486f3e47bf744c69206e2f6b9c01
mode 100644,000000..100644
--- /dev/null
@@@ -1,118 -1,0 +1,140 @@@
 +import loadPolyfills from 'flavours/glitch/util/load_polyfills';
 +import ready from 'flavours/glitch/util/ready';
 +import loadKeyboardExtensions from 'flavours/glitch/util/load_keyboard_extensions';
 +
 +function main() {
 +  const IntlMessageFormat = require('intl-messageformat').default;
 +  const { timeAgoString } = require('flavours/glitch/components/relative_timestamp');
 +  const { delegate } = require('@rails/ujs');
 +  const emojify = require('flavours/glitch/util/emoji').default;
 +  const { getLocale } = require('locales');
 +  const { messages } = getLocale();
 +  const React = require('react');
 +  const ReactDOM = require('react-dom');
 +  const Rellax = require('rellax');
 +  const { createBrowserHistory } = require('history');
 +
 +  const scrollToDetailedStatus = () => {
 +    const history = createBrowserHistory();
 +    const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
 +    const location = history.location;
 +
 +    if (detailedStatuses.length === 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
 +      detailedStatuses[0].scrollIntoView();
 +      history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true });
 +    }
 +  };
 +
 +  const getEmojiAnimationHandler = (swapTo) => {
 +    return ({ target }) => {
 +      target.src = target.getAttribute(swapTo);
 +    };
 +  };
 +
 +  ready(() => {
 +    const locale = document.documentElement.lang;
 +
 +    const dateTimeFormat = new Intl.DateTimeFormat(locale, {
 +      year: 'numeric',
 +      month: 'long',
 +      day: 'numeric',
 +      hour: 'numeric',
 +      minute: 'numeric',
 +    });
 +
 +    [].forEach.call(document.querySelectorAll('.emojify'), (content) => {
 +      content.innerHTML = emojify(content.innerHTML);
 +    });
 +
 +    [].forEach.call(document.querySelectorAll('time.formatted'), (content) => {
 +      const datetime = new Date(content.getAttribute('datetime'));
 +      const formattedDate = dateTimeFormat.format(datetime);
 +
 +      content.title = formattedDate;
 +      content.textContent = formattedDate;
 +    });
 +
 +    [].forEach.call(document.querySelectorAll('time.time-ago'), (content) => {
 +      const datetime = new Date(content.getAttribute('datetime'));
 +      const now      = new Date();
 +
 +      content.title = dateTimeFormat.format(datetime);
 +      content.textContent = timeAgoString({
 +        formatMessage: ({ id, defaultMessage }, values) => (new IntlMessageFormat(messages[id] || defaultMessage, locale)).format(values),
 +        formatDate: (date, options) => (new Intl.DateTimeFormat(locale, options)).format(date),
 +      }, datetime, now, now.getFullYear(), content.getAttribute('datetime').includes('T'));
 +    });
 +
 +    const reactComponents = document.querySelectorAll('[data-component]');
 +    if (reactComponents.length > 0) {
 +      import(/* webpackChunkName: "containers/media_container" */ 'flavours/glitch/containers/media_container')
 +        .then(({ default: MediaContainer }) => {
 +          [].forEach.call(reactComponents, (component) => {
 +            [].forEach.call(component.children, (child) => {
 +              component.removeChild(child);
 +            });
 +          });
 +
 +          const content = document.createElement('div');
 +
 +          ReactDOM.render(<MediaContainer locale={locale} components={reactComponents} />, content);
 +          document.body.appendChild(content);
 +          scrollToDetailedStatus();
 +        })
 +        .catch(error => {
 +          console.error(error);
 +          scrollToDetailedStatus();
 +        });
 +    } else {
 +      scrollToDetailedStatus();
 +    }
 +
 +    const parallaxComponents = document.querySelectorAll('.parallax');
 +
 +    if (parallaxComponents.length > 0 ) {
 +      new Rellax('.parallax', { speed: -1 });
 +    }
 +
 +    delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original'));
 +    delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static'));
++
++    delegate(document, '.status__content__spoiler-link', 'click', function() {
++      const contentEl = this.parentNode.parentNode.querySelector('.e-content');
++
++      if (contentEl.style.display === 'block') {
++        contentEl.style.display = 'none';
++        this.parentNode.style.marginBottom = 0;
++        this.textContent = (new IntlMessageFormat(messages['status.show_more'] || 'Show more', locale)).format();
++      } else {
++        contentEl.style.display = 'block';
++        this.parentNode.style.marginBottom = null;
++        this.textContent = (new IntlMessageFormat(messages['status.show_less'] || 'Show less', locale)).format();
++      }
++
++      return false;
++    });
++
++    [].forEach.call(document.querySelectorAll('.status__content__spoiler-link'), (spoilerLink) => {
++      const contentEl = spoilerLink.parentNode.parentNode.querySelector('.e-content');
++      const message = (contentEl.style.display === 'block') ? (messages['status.show_less'] || 'Show less') : (messages['status.show_more'] || 'Show more');
++      spoilerLink.textContent = (new IntlMessageFormat(message, locale)).format();
++    });
 +  });
 +
 +  delegate(document, '.sidebar__toggle__icon', 'click', () => {
 +    const target = document.querySelector('.sidebar ul');
 +
 +    if (target.style.display === 'block') {
 +      target.style.display = 'none';
 +    } else {
 +      target.style.display = 'block';
 +    }
 +  });
 +}
 +
 +loadPolyfills()
 +  .then(main)
 +  .then(loadKeyboardExtensions)
 +  .catch(error => {
 +    console.error(error);
 +  });
index dc85164d0a6331d9508fd824549035adc8bcfd8c,85789c8aafe82182f3942e87cf88ad648de7f13d..5b699e76766f556166c8becb1a60f5bda96c3010
@@@ -101,8 -118,136 +101,30 @@@ function main() 
  
      delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original'));
      delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static'));
+     delegate(document, '.status__content__spoiler-link', 'click', function() {
+       const contentEl = this.parentNode.parentNode.querySelector('.e-content');
+       if (contentEl.style.display === 'block') {
+         contentEl.style.display = 'none';
+         this.parentNode.style.marginBottom = 0;
+         this.textContent = (new IntlMessageFormat(messages['status.show_more'] || 'Show more', locale)).format();
+       } else {
+         contentEl.style.display = 'block';
+         this.parentNode.style.marginBottom = null;
+         this.textContent = (new IntlMessageFormat(messages['status.show_less'] || 'Show less', locale)).format();
+       }
+       return false;
+     });
+     [].forEach.call(document.querySelectorAll('.status__content__spoiler-link'), (spoilerLink) => {
+       const contentEl = spoilerLink.parentNode.parentNode.querySelector('.e-content');
+       const message = (contentEl.style.display === 'block') ? (messages['status.show_less'] || 'Show less') : (messages['status.show_more'] || 'Show more');
+       spoilerLink.textContent = (new IntlMessageFormat(message, locale)).format();
+     });
    });
  
 -  delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
 -    if (button !== 0) {
 -      return true;
 -    }
 -    window.location.href = target.href;
 -    return false;
 -  });
 -
 -  delegate(document, '.modal-button', 'click', e => {
 -    e.preventDefault();
 -
 -    let href;
 -
 -    if (e.target.nodeName !== 'A') {
 -      href = e.target.parentNode.href;
 -    } else {
 -      href = e.target.href;
 -    }
 -
 -    window.open(href, 'mastodon-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes');
 -  });
 -
 -  delegate(document, '#account_display_name', 'input', ({ target }) => {
 -    const name = document.querySelector('.card .display-name strong');
 -    if (name) {
 -      if (target.value) {
 -        name.innerHTML = emojify(escapeTextContentForBrowser(target.value));
 -      } else {
 -        name.textContent = document.querySelector('#default_account_display_name').textContent;
 -      }
 -    }
 -  });
 -
 -  delegate(document, '#account_avatar', 'change', ({ target }) => {
 -    const avatar = document.querySelector('.card .avatar img');
 -    const [file] = target.files || [];
 -    const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
 -
 -    avatar.src = url;
 -  });
 -
 -  const getProfileAvatarAnimationHandler = (swapTo) => {
 -    //animate avatar gifs on the profile page when moused over
 -    return ({ target }) => {
 -      const swapSrc = target.getAttribute(swapTo);
 -      //only change the img source if autoplay is off and the image src is actually different
 -      if(target.getAttribute('data-autoplay') !== 'true' && target.src !== swapSrc) {
 -        target.src = swapSrc;
 -      }
 -    };
 -  };
 -
 -  delegate(document, 'img#profile_page_avatar', 'mouseover', getProfileAvatarAnimationHandler('data-original'));
 -
 -  delegate(document, 'img#profile_page_avatar', 'mouseout', getProfileAvatarAnimationHandler('data-static'));
 -
 -  delegate(document, '#account_header', 'change', ({ target }) => {
 -    const header = document.querySelector('.card .card__img img');
 -    const [file] = target.files || [];
 -    const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
 -
 -    header.src = url;
 -  });
 -
 -  delegate(document, '#account_locked', 'change', ({ target }) => {
 -    const lock = document.querySelector('.card .display-name i');
 -
 -    if (target.checked) {
 -      lock.style.display = 'inline';
 -    } else {
 -      lock.style.display = 'none';
 -    }
 -  });
 -
 -  delegate(document, '.input-copy input', 'click', ({ target }) => {
 -    target.focus();
 -    target.select();
 -    target.setSelectionRange(0, target.value.length);
 -  });
 -
 -  delegate(document, '.input-copy button', 'click', ({ target }) => {
 -    const input = target.parentNode.querySelector('.input-copy__wrapper input');
 -
 -    const oldReadOnly = input.readonly;
 -
 -    input.readonly = false;
 -    input.focus();
 -    input.select();
 -    input.setSelectionRange(0, input.value.length);
 -
 -    try {
 -      if (document.execCommand('copy')) {
 -        input.blur();
 -        target.parentNode.classList.add('copied');
 -
 -        setTimeout(() => {
 -          target.parentNode.classList.remove('copied');
 -        }, 700);
 -      }
 -    } catch (err) {
 -      console.error(err);
 -    }
 -
 -    input.readonly = oldReadOnly;
 -  });
 -
    delegate(document, '.sidebar__toggle__icon', 'click', () => {
      const target = document.querySelector('.sidebar ul');
  
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc db/schema.rb
Simple merge
Simple merge
diff --cc package.json
index 0edb4a2fae34c938e104b518ab5ab656e0dd1799,c9927bb47bb645a1046ad190bd25d0b5f567b6b5..82f918456de5ce500e20418f6099752c6af43785
      "@babel/runtime": "^7.8.4",
      "@clusterws/cws": "^0.17.3",
      "@gamestdio/websocket": "^0.3.2",
+     "@rails/ujs": "^6.0.2",
      "array-includes": "^3.1.1",
      "arrow-key-navigation": "^1.1.0",
 +    "atrament": "0.2.4",
      "autoprefixer": "^9.7.5",
      "axios": "^0.19.2",
      "babel-loader": "^8.1.0",
diff --cc yarn.lock
Simple merge