share-to-fediverse-jekyll-theme 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f70a7cb2292f13a87fb137d0a64f7def5524287846207ff44f437cf44f814028
4
- data.tar.gz: 0e1b31d2799da74dad71ac45b3a470f112b25abc8781479c91f9c2382e4a1a0e
3
+ metadata.gz: 4d8cb5d855f0cdea583192060b84f4f2c7fa5e6b51bc08feee2b5eeda92aed7d
4
+ data.tar.gz: 853688ddfc62c42859aa5f8f1383e6d69ecbde96975cdf78dc3abc87f9d15592
5
5
  SHA512:
6
- metadata.gz: 7ab7dcb734e0f7f92a445064a4dea419d76862cb146fc7f375da47b2e136087f7821afc07979f98bec0fa3570e37a0d1d55b6003e662949041d7a00c4912521b
7
- data.tar.gz: b03be2b7c6f1eb0895f0070cdbc2020ae30e18981cb142e5eebf4c291cf0f212d20fbb49a4a2b1414d780064db0fe02212a4639dd233726fc2d43cd3200d3e96
6
+ metadata.gz: 8386178a4cde7d29adaa781a17c59736ce003eeec7e708c045b6b7bb0b5e86725a4afe47e043a110f3083e9a6a44bcd3929bf9695d1f61e5f841ea549662ddf1
7
+ data.tar.gz: dbd1065edb4f5281cca6d3260691cff1217ffb5419887ffe4db6f677827c5451c895a81c6d7ee0520cad304462a0a7c3cf819842834a8a76368aa5900f429bc4
@@ -42,3 +42,4 @@ locales:
42
42
  lang: es
43
43
  locale: es
44
44
  instance: 'https://todon.nl/'
45
+ auto_submit_seconds: 3
@@ -11,6 +11,17 @@ instance:
11
11
  help:
12
12
  es: 'Tu servidor de Mastodon, incluyendo https://'
13
13
  en: 'Your Mastodon server, including https://'
14
+ remember:
15
+ type: 'boolean'
16
+ autocomplete: 'on'
17
+ label:
18
+ es: 'Recordar la instancia'
19
+ en: 'Remember instance'
20
+ help:
21
+ es: 'Continuar automáticamente'
22
+ en: 'Auto-forward from now on'
23
+ separator:
24
+ type: 'separator'
14
25
  submit:
15
26
  type: 'submit'
16
27
  label:
@@ -4,7 +4,7 @@
4
4
  {%- assign help = include.field[1].help[site.locale] -%}
5
5
  {%- assign autocomplete = include.field[1].autocomplete -%}
6
6
 
7
- <div class="form-check text-left">
7
+ <div class="custom-control custom-switch">
8
8
  <input
9
9
  {% if help %}
10
10
  aria-describedby="help-{{ id }}"
@@ -18,9 +18,9 @@
18
18
  {% if autocomplete %}
19
19
  autocomplete="{{ autocomplete }}"
20
20
  {% endif %}
21
- class="form-check-input" />
21
+ class="custom-control-input" />
22
22
 
23
- <label class="form-check-label" for="{{ id }}">{{ label }}</label>
23
+ <label class="custom-control-label" for="{{ id }}">{{ label }}</label>
24
24
 
25
25
  {%- if help -%}
26
26
  <small id="help-{{ id }}" class="form-text">
@@ -4,6 +4,7 @@
4
4
 
5
5
  $mastodon: #191b22;
6
6
  $mastodon-grey: #9baec8;
7
+ $primary: $mastodon-grey;
7
8
  $success: $mastodon-grey;
8
9
 
9
10
  $colors: (
@@ -1,7 +1,9 @@
1
1
  ---
2
2
  ---
3
3
 
4
- // https://stackoverflow.com/a/7090123
4
+ // Convert query arguments to object
5
+ // @see {https://stackoverflow.com/a/7090123}
6
+ // @return [Object]
5
7
  const searchToObject = () => {
6
8
  var pairs = window.location.search.substring(1).split("&"),
7
9
  obj = {},
@@ -18,21 +20,64 @@ const searchToObject = () => {
18
20
  return obj;
19
21
  }
20
22
 
23
+ // Compatible with Turbolinks
24
+ const loadEvent = () => window.Turbolinks ? 'turbolinks:load' : 'DOMContentLoaded';
21
25
 
22
- document.addEventListener('{%- if site.turbolinks.enabled -%}turbolinks:load{%- else -%}DOMContentLoaded{%- endif -%}', () => {
26
+ document.addEventListener(loadEvent(), () => {
23
27
  const urlShared = searchToObject();
24
28
 
29
+ // Add the query args to the locale selector
25
30
  document.querySelectorAll('a[lang]').forEach(a => a.href += window.location.search);
26
31
 
32
+ // Recover data from URL only if it's set
27
33
  ['t','d','u'].forEach(field => {
28
34
  if (urlShared[field] === undefined) return;
29
35
 
30
36
  document.querySelector(`#${field}`).innerText = urlShared[field];
31
37
  });
32
38
 
39
+ // Send this field
33
40
  document.querySelector('#text').value = Object.values(urlShared).join("\n\n");
34
41
 
35
- document.querySelector('form').addEventListener('submit', e => {
36
- e.target.action = document.querySelector('#instance').value + '/share';
42
+ // Helpers for data storage
43
+ const isCheckbox = input => input.type == 'checkbox';
44
+ const itemId = (form, input) => form.id + ':' + input.id;
45
+
46
+ const form = document.querySelector('form')
47
+ const formInputs = Array.from(form.elements);
48
+
49
+ form.addEventListener('submit', e => {
50
+ // Change the form action to the actual instance
51
+ form.action = document.querySelector('#instance').value + '/share';
52
+
53
+ const rememberInstance = document.querySelector('#remember').checked;
54
+
55
+ // If user disabled it, forget data.
56
+ if (!rememberInstance) localStorage.clear();
57
+
58
+ // Store the data. Form autocomplete should be helpful
59
+ // here but for some reason it doesn't.
60
+ formInputs.forEach(input => {
61
+ if (input.type == 'submit') return;
62
+
63
+ if (!rememberInstance) return;
64
+
65
+ localStorage.setItem(itemId(form, input), isCheckbox(input) ? input.checked : input.value);
66
+ });
67
+ });
68
+
69
+ // Recover information
70
+ formInputs.forEach(input => {
71
+ if (input.type == 'submit') return;
72
+
73
+ const value = localStorage.getItem(itemId(form, input));
74
+
75
+ if (value) input[isCheckbox(input) ? 'checked' : 'value'] = value;
37
76
  });
77
+
78
+ // Redirect after a timeout, so users have time to disable.
79
+ setTimeout(() => {
80
+ if (!document.querySelector('#remember').checked) return;
81
+ document.querySelector('form').submit();
82
+ }, {{ site.auto_submit_seconds | default: 3 }} * 1000);
38
83
  });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: share-to-fediverse-jekyll-theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll