about summary refs log tree commit diff
path: root/app/javascript/core/settings.js
diff options
context:
space:
mode:
authorbeatrix <beatrix.bitrot@gmail.com>2017-12-06 17:44:07 -0500
committerGitHub <noreply@github.com>2017-12-06 17:44:07 -0500
commit81b01457598459c42a7b14d9aa14f91ba60dcae1 (patch)
tree7d3e6dadb75f3be95e5a5ed8b7ecfe90e7711831 /app/javascript/core/settings.js
parentf1cbea77a4a52929244198dcbde26d63d837489a (diff)
parent017fc81caf8f265e5c5543186877437485625795 (diff)
Merge pull request #229 from glitch-soc/glitch-theme
Advanced Next-Level Flavours And Skins For Mastodon™
Diffstat (limited to 'app/javascript/core/settings.js')
-rw-r--r--app/javascript/core/settings.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/javascript/core/settings.js b/app/javascript/core/settings.js
new file mode 100644
index 000000000..ada5fba2b
--- /dev/null
+++ b/app/javascript/core/settings.js
@@ -0,0 +1,43 @@
+//  This file will be loaded on settings pages, regardless of theme.
+
+const { length } = require('stringz');
+const { delegate } = require('rails-ujs');
+
+import { processBio } from 'flavours/glitch/util/bio_metadata';
+
+delegate(document, '.account_display_name', 'input', ({ target }) => {
+  const nameCounter = document.querySelector('.name-counter');
+
+  if (nameCounter) {
+    nameCounter.textContent = 30 - length(target.value);
+  }
+});
+
+delegate(document, '.account_note', 'input', ({ target }) => {
+  const noteCounter = document.querySelector('.note-counter');
+
+  if (noteCounter) {
+    const noteWithoutMetadata = processBio(target.value).text;
+    noteCounter.textContent = 500 - length(noteWithoutMetadata);
+  }
+});
+
+delegate(document, '#account_avatar', 'change', ({ target }) => {
+  const avatar = document.querySelector('.card.compact .avatar img');
+  const [file] = target.files || [];
+  const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
+
+  avatar.src = url;
+});
+
+delegate(document, '#account_header', 'change', ({ target }) => {
+  const header = document.querySelector('.card.compact');
+  const [file] = target.files || [];
+  const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
+
+  header.style.backgroundImage = `url(${url})`;
+});
+
+delegate(document, '#user_setting_flavour, #user_setting_skin', 'change', ({ target }) => {
+  target.form.submit();
+});