apostrophecms-plugin-all-in-one-accessibility 1.0.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +195 -163
  2. package/app/config.js +134 -0
  3. package/app/helpers.js +62 -0
  4. package/app/skynet-widget.js +509 -0
  5. package/assets/css/banners.css +77 -0
  6. package/assets/css/base.css +50 -0
  7. package/assets/css/components.css +91 -0
  8. package/assets/css/paid.css +53 -0
  9. package/assets/css/responsive.css +70 -0
  10. package/assets/css/score.css +42 -0
  11. package/assets/css/settings.css +154 -0
  12. package/assets/css/tabs.css +52 -0
  13. package/assets/css/tokens.css +53 -0
  14. package/assets/images/icons/aioa-icon-type-1.svg +1 -0
  15. package/assets/images/icons/aioa-icon-type-10.svg +1 -0
  16. package/assets/images/icons/aioa-icon-type-11.svg +1 -0
  17. package/assets/images/icons/aioa-icon-type-12.svg +1 -0
  18. package/assets/images/icons/aioa-icon-type-13.svg +1 -0
  19. package/assets/images/icons/aioa-icon-type-14.svg +29 -0
  20. package/assets/images/icons/aioa-icon-type-15.svg +26 -0
  21. package/assets/images/icons/aioa-icon-type-16.svg +17 -0
  22. package/assets/images/icons/aioa-icon-type-17.svg +24 -0
  23. package/assets/images/icons/aioa-icon-type-18.svg +20 -0
  24. package/assets/images/icons/aioa-icon-type-19.svg +25 -0
  25. package/assets/images/icons/aioa-icon-type-2.svg +1 -0
  26. package/assets/images/icons/aioa-icon-type-20.svg +24 -0
  27. package/assets/images/icons/aioa-icon-type-21.svg +28 -0
  28. package/assets/images/icons/aioa-icon-type-22.svg +21 -0
  29. package/assets/images/icons/aioa-icon-type-23.svg +21 -0
  30. package/assets/images/icons/aioa-icon-type-24.svg +21 -0
  31. package/assets/images/icons/aioa-icon-type-25.svg +15 -0
  32. package/assets/images/icons/aioa-icon-type-26.svg +23 -0
  33. package/assets/images/icons/aioa-icon-type-27.svg +21 -0
  34. package/assets/images/icons/aioa-icon-type-28.svg +27 -0
  35. package/assets/images/icons/aioa-icon-type-29.svg +25 -0
  36. package/assets/images/icons/aioa-icon-type-3.svg +1 -0
  37. package/assets/images/icons/aioa-icon-type-4.svg +16 -0
  38. package/assets/images/icons/aioa-icon-type-5.svg +1 -0
  39. package/assets/images/icons/aioa-icon-type-6.svg +1 -0
  40. package/assets/images/icons/aioa-icon-type-7.svg +1 -0
  41. package/assets/images/icons/aioa-icon-type-8.svg +1 -0
  42. package/assets/images/icons/aioa-icon-type-9.svg +1 -0
  43. package/assets/js/app.js +152 -0
  44. package/assets/js/core.js +249 -0
  45. package/assets/js/dashboard.js +97 -0
  46. package/assets/js/paid-features.js +237 -0
  47. package/assets/js/plan.js +65 -0
  48. package/assets/js/save.js +35 -0
  49. package/assets/js/score.js +130 -0
  50. package/assets/js/settings-form.js +371 -0
  51. package/assets/js/tabs.js +108 -0
  52. package/assets/js/ui.js +90 -0
  53. package/index.js +301 -15
  54. package/package.json +19 -9
  55. package/ui/apos/components/AllInOneAccessibilitySettings.vue +126 -679
  56. package/views/layout.ejs +97 -0
  57. package/views/partials/accessibility-score.ejs +37 -0
  58. package/views/partials/header.ejs +13 -0
  59. package/views/partials/lock.ejs +20 -0
  60. package/views/partials/paid/links.ejs +33 -0
  61. package/views/partials/paid/mobile-position.ejs +80 -0
  62. package/views/partials/paid/toggles.ejs +20 -0
  63. package/views/partials/paid-banner.ejs +19 -0
  64. package/views/partials/paid-features.ejs +14 -0
  65. package/views/partials/score/card.ejs +61 -0
  66. package/views/partials/settings/color.ejs +37 -0
  67. package/views/partials/settings/icon-size.ejs +43 -0
  68. package/views/partials/settings/icon-type.ejs +24 -0
  69. package/views/partials/settings/position.ejs +70 -0
  70. package/views/partials/settings/save-bar.ejs +9 -0
  71. package/views/partials/settings/widget-size.ejs +38 -0
  72. package/views/partials/settings-form.ejs +39 -0
  73. package/views/partials/site-strip.ejs +5 -0
  74. package/views/partials/status.ejs +16 -0
  75. package/views/partials/tabs.ejs +32 -0
  76. package/views/partials/upgrade-banner.ejs +34 -0
  77. package/views/scriptTag.html +7 -1
  78. package/ui/apos/apps/AllInOneAccessibilitySettings.js +0 -8
@@ -0,0 +1,130 @@
1
+ /**
2
+ * ---------------------------------------------------------------------------
3
+ * score.js - Accessibility Score tab
4
+ * ---------------------------------------------------------------------------
5
+ * Paid plan: the first time the tab opens it loads the scan results
6
+ * (server route, action fetchScanDetails) and shows one of:
7
+ * #score-loading #score-error #score-empty (scanning in progress) #score-card
8
+ * Free plan: the sample card stays blurred under the upgrade overlay
9
+ * (AIOA.tabs.setPlan) and nothing is requested.
10
+ */
11
+ (function (AIOA, document) {
12
+ 'use strict';
13
+
14
+ const { $ } = AIOA.util;
15
+ const state = AIOA.state;
16
+ const card = $('#score-card');
17
+ const VIEWS = ['score-loading', 'score-error', 'score-empty', 'score-card'];
18
+ const LEVELS = ['compliant', 'semi', 'not'];
19
+
20
+ let locked = true; // until the plan is known
21
+ let loaded = false; // the score is shown or loading
22
+
23
+ function show(id) {
24
+ VIEWS.forEach((view) => {
25
+ $('#' + view).hidden = view !== id;
26
+ });
27
+ }
28
+
29
+ /** 96.15 -> "96.15%", 100 -> "100%" */
30
+ function percent(value) {
31
+ return Math.round((Number(value) || 0) * 100) / 100 + '%';
32
+ }
33
+
34
+ /** "2026-06-27 05:24:30" (UTC) -> "Jun 27, 2026" */
35
+ function formatDate(value) {
36
+ const date = new Date(String(value).replace(' ', 'T') + 'Z');
37
+ return isNaN(date) ? '' : date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', timeZone: 'UTC' });
38
+ }
39
+
40
+ function field(name) {
41
+ return card.querySelector('[data-field="' + name + '"]');
42
+ }
43
+
44
+ /** Fill the score card from the fetchScanDetails summary */
45
+ function render(summary) {
46
+ // Up to 99, never 100 (the server's summary is capped the same way)
47
+ const score = Math.max(0, Math.min(99, Math.round(Number(summary.score) || 0)));
48
+ const violations = summary.violations || {};
49
+ const altText = summary.alt_text || {};
50
+ const pages = summary.pages || {};
51
+
52
+ card.dataset.level = LEVELS.includes(summary.level) ? summary.level : 'not';
53
+ field('status').textContent = summary.status || '';
54
+
55
+ const donut = card.querySelector('.aioa-donut');
56
+ donut.style.setProperty('--p', score);
57
+ donut.setAttribute('aria-label', 'Accessibility score ' + score + '%' + (summary.status ? ', ' + summary.status : ''));
58
+ field('score').textContent = score;
59
+
60
+ field('violations-pct').textContent = percent(violations.percentage);
61
+ field('violations-count').textContent = num(violations.fixed) + ' / ' + num(violations.total);
62
+ field('alt-pct').textContent = percent(altText.percentage);
63
+ field('alt-count').textContent = num(altText.fixed) + ' / ' + num(altText.total);
64
+ field('pages').textContent = num(pages.scanned);
65
+ field('pages-count').textContent = num(pages.scanned) + ' / ' + num(pages.total);
66
+
67
+ const date = formatDate(summary.last_scan);
68
+ field('last-scan').textContent = date ? 'Last scan: ' + date : '';
69
+
70
+ // Only https report links are offered
71
+ const report = field('report');
72
+ report.hidden = !/^https:\/\//i.test(summary.report_url || '');
73
+ report.href = report.hidden ? '#' : summary.report_url;
74
+
75
+ show('score-card');
76
+ }
77
+
78
+ function num(value) {
79
+ return Number(value) || 0;
80
+ }
81
+
82
+ /** Load the score of the website (once, unless forced by Try again) */
83
+ function load(force) {
84
+ if (locked || (loaded && !force)) {
85
+ return;
86
+ }
87
+ loaded = true;
88
+ show('score-loading');
89
+
90
+ AIOA.api.route('fetchScanDetails', { url: state.activeDomain })
91
+ .then((result) => {
92
+ if (!result || typeof result !== 'object') {
93
+ throw new Error('Unexpected response from the server.');
94
+ }
95
+ if (result.error) {
96
+ throw new Error(result.error);
97
+ }
98
+ if (result.no_scan) {
99
+ show('score-empty'); // not scanned yet, or the scan is still running
100
+ return;
101
+ }
102
+ render(result);
103
+ })
104
+ .catch((err) => {
105
+ loaded = false; // try again the next time the tab opens
106
+ $('#score-error-text').textContent = err instanceof TypeError ?
107
+ 'Please check your connection and try again.' :
108
+ (err.message || 'Please try again.');
109
+ show('score-error');
110
+ });
111
+ }
112
+
113
+ $('#score-retry').addEventListener('click', () => load(true));
114
+
115
+ document.addEventListener('aioa:tab-change', (e) => {
116
+ if (e.detail.tab === 'score') {
117
+ load();
118
+ }
119
+ });
120
+
121
+ // Free plan: sample card under the overlay; paid plan: the real results
122
+ document.addEventListener('aioa:lock-change', (e) => {
123
+ locked = e.detail.locked;
124
+ $('#score-sample').hidden = !locked;
125
+ $('#score-live').hidden = locked;
126
+ if (!locked && AIOA.tabs.current() === 'score') {
127
+ load();
128
+ }
129
+ });
130
+ })(window.AIOA, document);
@@ -0,0 +1,371 @@
1
+ /**
2
+ * ---------------------------------------------------------------------------
3
+ * settings-form.js - the widget settings form
4
+ * ---------------------------------------------------------------------------
5
+ * AIOA.form.settingsFrom(result) API response -> settings with defaults
6
+ * AIOA.form.fill(settings) put settings into the form
7
+ * AIOA.form.collect() validate + read the form as API parameters
8
+ * (+ the Paid Features tab on a paid plan, see paid-features.js)
9
+ * AIOA.form.setDirty(bool) "You have unsaved changes" indicator
10
+ * Also handles the color picker, the preset / custom switches and the
11
+ * live previews (icon images, mini website, --widget-color).
12
+ */
13
+ (function (AIOA, document) {
14
+ 'use strict';
15
+
16
+ const { $, $$, parseHex, checkedValue, checkRadio, positionValue, wholeNumber, wholeNumberField, requiredFields } = AIOA.util;
17
+ const state = AIOA.state;
18
+ const config = AIOA.config;
19
+
20
+ // Exact position: both values are required while "Set an exact position in pixels" is on
21
+ const positionFields = requiredFields(
22
+ [$('#custom_position_x_value'), $('#custom_position_y_value')],
23
+ $('#pos-error'),
24
+ 'Enter a horizontal and a vertical position from 0 to 500 px.'
25
+ );
26
+
27
+ // Exact icon size: a whole number from 24 to 150 px while "Set an exact size in pixels" is on
28
+ const SIZE_MIN = 24;
29
+ const SIZE_MAX = 150;
30
+ const sizeField = requiredFields(
31
+ [$('#widget_icon_size_custom')],
32
+ $('#size-error'),
33
+ 'Enter an exact icon size from ' + SIZE_MIN + ' to ' + SIZE_MAX + ' px.',
34
+ (input) => {
35
+ const size = wholeNumber(input.value, null);
36
+ return size !== null && size >= SIZE_MIN && size <= SIZE_MAX;
37
+ }
38
+ );
39
+
40
+ /* =========================================================================
41
+ * Settings <-> form
42
+ * ======================================================================= */
43
+
44
+ /** Normalize a widget settings response; anything missing falls back to the defaults */
45
+ function settingsFrom(result) {
46
+ const defaults = config.defaults;
47
+ return {
48
+ widget_position: positionValue(result.widget_position) || defaults.widget_position,
49
+ widget_color_code: result.widget_color_code || defaults.widget_color_code,
50
+ widget_icon_type: result.widget_icon_type || defaults.widget_icon_type,
51
+ widget_icon_size: result.widget_icon_size || defaults.widget_icon_size,
52
+ widget_size: result.widget_size || defaults.widget_size,
53
+ widget_icon_size_custom: wholeNumber(result.widget_icon_size_custom, '') || '',
54
+ widget_position_top: wholeNumber(result.widget_position_top, 0),
55
+ widget_position_bottom: wholeNumber(result.widget_position_bottom, 0),
56
+ widget_position_left: wholeNumber(result.widget_position_left, 0),
57
+ widget_position_right: wholeNumber(result.widget_position_right, 0)
58
+ };
59
+ }
60
+
61
+ /** Put settings into the form. state.customPosition / customSize must be set first. */
62
+ function fill(settings) {
63
+ positionFields.reset();
64
+ sizeField.reset();
65
+ $('#custom-position-switcher').checked = state.customPosition === 1;
66
+ $('#custom-size-switcher').checked = state.customSize === 1;
67
+ syncCustomPosition();
68
+ syncCustomSize();
69
+
70
+ setColor(settings.widget_color_code);
71
+
72
+ checkRadio('position', settings.widget_position);
73
+ updateMiniWidget();
74
+ checkRadio('widget_size', settings.widget_size);
75
+ checkRadio('aioa_icon_type', settings.widget_icon_type);
76
+ checkRadio('aioa_icon_size', settings.widget_icon_size);
77
+ updateIconImages(settings.widget_icon_type);
78
+
79
+ $('#widget_icon_size_custom').value = settings.widget_icon_size_custom;
80
+
81
+ // Exact horizontal offset: right wins over left
82
+ const xField = $('#custom_position_x_value');
83
+ const xDirection = $('#custom_position_x_dir');
84
+ if (settings.widget_position_right > 0) {
85
+ xField.value = settings.widget_position_right;
86
+ xDirection.value = 'cust-pos-to-the-right';
87
+ } else if (settings.widget_position_left > 0) {
88
+ xField.value = settings.widget_position_left;
89
+ xDirection.value = 'cust-pos-to-the-left';
90
+ } else {
91
+ xField.value = 0;
92
+ xDirection.value = 'cust-pos-to-the-right'; // default direction
93
+ }
94
+
95
+ // Exact vertical offset: bottom wins over top
96
+ const yField = $('#custom_position_y_value');
97
+ const yDirection = $('#custom_position_y_dir');
98
+ if (settings.widget_position_bottom > 0) {
99
+ yField.value = settings.widget_position_bottom;
100
+ yDirection.value = 'cust-pos-to-the-lower';
101
+ } else if (settings.widget_position_top > 0) {
102
+ yField.value = settings.widget_position_top;
103
+ yDirection.value = 'cust-pos-to-the-upper';
104
+ } else {
105
+ yField.value = 0;
106
+ yDirection.value = 'cust-pos-to-the-lower'; // default direction
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Check every field before saving. Every invalid field is marked in red with its message
112
+ * at the same time, not only the first one. Returns the problems in page order:
113
+ * { field, tab, name, title, text } (title and text: the toast when it is the only problem).
114
+ */
115
+ function validate() {
116
+ const problems = [];
117
+
118
+ if (!parseHex($('#colorcode').value)) {
119
+ setColorError(true);
120
+ problems.push({ field: $('#colorcode'), tab: 'appearance', name: 'Widget color',
121
+ title: 'Invalid color', text: 'Enter a valid hex color code, for example FF5733.' });
122
+ }
123
+
124
+ // Exact position: an empty field is never saved as 0
125
+ const emptyOffset = state.customPosition === 1 ? positionFields.check() : null;
126
+ if (emptyOffset) {
127
+ problems.push({ field: emptyOffset, tab: 'appearance', name: 'Widget position',
128
+ title: 'Position missing', text: 'Enter the exact position (0 - 500 px), or turn off "Set an exact position in pixels".' });
129
+ }
130
+
131
+ const badSize = state.customSize === 1 ? sizeField.check() : null;
132
+ if (badSize) {
133
+ problems.push({ field: badSize, tab: 'appearance', name: 'Icon size for desktop',
134
+ title: 'Invalid icon size', text: 'Enter an exact icon size from ' + SIZE_MIN + ' to ' + SIZE_MAX + ' px.' });
135
+ }
136
+
137
+ // Paid Features: paid plans only
138
+ return state.isPaid ? problems.concat(AIOA.paid.validate()) : problems;
139
+ }
140
+
141
+ /** "A", "A and B", "A, B and C" */
142
+ function joinNames(names) {
143
+ return names.length > 1 ? names.slice(0, -1).join(', ') + ' and ' + names[names.length - 1] : names[0];
144
+ }
145
+
146
+ /** Point the admin at what needs a fix: the first problem's tab and field, and one toast for all of them */
147
+ function report(problems) {
148
+ const first = problems[0];
149
+ AIOA.tabs.select(first.tab);
150
+ first.field.focus();
151
+ if (problems.length === 1) {
152
+ AIOA.ui.toast('error', first.title, first.text);
153
+ } else {
154
+ AIOA.ui.toast('error', 'Check the fields marked in red', joinNames(problems.map((p) => p.name)) + ' need a fix before you can save.');
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Validate the form and build the parameters for widget-setting-update-platform.
160
+ * Shows what is wrong (every problem at once) and returns null when the form is invalid.
161
+ */
162
+ function collect() {
163
+ const problems = validate();
164
+ if (problems.length) {
165
+ report(problems);
166
+ return null;
167
+ }
168
+
169
+ const hex = parseHex($('#colorcode').value);
170
+
171
+ // Whole pixels only (the fields never hold decimals, see wholeNumberField)
172
+ const widget_icon_size_custom = String(wholeNumber($('#widget_icon_size_custom').value, ''));
173
+
174
+ // Exact offsets: only the chosen direction of each axis is sent
175
+ // (empty only while the exact position is off: then 0, as before)
176
+ const custom_position_x = wholeNumber($('#custom_position_x_value').value, 0);
177
+ const custom_position_y = wholeNumber($('#custom_position_y_value').value, 0);
178
+ const x_position_direction = $('#custom_position_x_dir').value;
179
+ const y_position_direction = $('#custom_position_y_dir').value;
180
+
181
+ let widget_position_right = null;
182
+ let widget_position_left = null;
183
+ let widget_position_top = null;
184
+ let widget_position_bottom = null;
185
+
186
+ if (x_position_direction === 'cust-pos-to-the-right') {
187
+ widget_position_right = custom_position_x;
188
+ } else if (x_position_direction === 'cust-pos-to-the-left') {
189
+ widget_position_left = custom_position_x;
190
+ }
191
+
192
+ if (y_position_direction === 'cust-pos-to-the-lower') {
193
+ widget_position_bottom = custom_position_y;
194
+ } else if (y_position_direction === 'cust-pos-to-the-upper') {
195
+ widget_position_top = custom_position_y;
196
+ }
197
+
198
+ const params = {
199
+ u: state.activeDomain,
200
+ widget_position: checkedValue('position'),
201
+ is_widget_custom_position: state.customPosition,
202
+ is_widget_custom_size: state.customSize,
203
+ widget_color_code: '#' + hex,
204
+ widget_icon_type: checkedValue('aioa_icon_type'),
205
+ widget_icon_size: checkedValue('aioa_icon_size'),
206
+ widget_size: checkedValue('widget_size'),
207
+ widget_icon_size_custom: widget_icon_size_custom,
208
+ widget_position_right: widget_position_right,
209
+ widget_position_left: widget_position_left,
210
+ widget_position_top: widget_position_top,
211
+ widget_position_bottom: widget_position_bottom
212
+ };
213
+
214
+ // Paid Features: paid plans only (the tab holds the saved values by then, see app.js;
215
+ // it was checked in validate)
216
+ if (state.isPaid) {
217
+ Object.assign(params, AIOA.paid.collect());
218
+ }
219
+
220
+ return params;
221
+ }
222
+
223
+ /* =========================================================================
224
+ * Previews and switches
225
+ * ======================================================================= */
226
+
227
+ /** Show the selected icon type in every preview image (.iconimg) */
228
+ function updateIconImages(iconType) {
229
+ $$('.iconimg').forEach((img) => {
230
+ img.src = config.iconBase + iconType + '.svg';
231
+ });
232
+ }
233
+
234
+ /** Move the icon in the "Your website" preview to the selected position */
235
+ function updateMiniWidget() {
236
+ const input = document.querySelector('input[name="position"]:checked');
237
+ if (input) {
238
+ $('#mini-widget').style.setProperty('--gx', input.dataset.gx);
239
+ $('#mini-widget').style.setProperty('--gy', input.dataset.gy);
240
+ }
241
+ }
242
+
243
+ /** Preset position grid <-> exact offsets */
244
+ function syncCustomPosition() {
245
+ const on = $('#custom-position-switcher').checked;
246
+ state.customPosition = on ? 1 : 0;
247
+ $('#custom-position-controls').hidden = !on;
248
+ $('#position_html').hidden = on;
249
+ if (!on) {
250
+ positionFields.reset();
251
+ }
252
+ }
253
+
254
+ /** Preset icon sizes <-> exact size */
255
+ function syncCustomSize() {
256
+ const on = $('#custom-size-switcher').checked;
257
+ state.customSize = on ? 1 : 0;
258
+ $('#custom-size-controls').hidden = !on;
259
+ $('#select_icon_size').hidden = on;
260
+ if (!on) {
261
+ sizeField.reset();
262
+ }
263
+ }
264
+
265
+ /* =========================================================================
266
+ * Color picker
267
+ * ======================================================================= */
268
+
269
+ function setColorError(show) {
270
+ $('#colorcode-error').hidden = !show;
271
+ $('#colorcode').setAttribute('aria-invalid', show ? 'true' : 'false');
272
+ $('[data-for="colorcode"]').classList.toggle('is-invalid', show);
273
+ }
274
+
275
+ /**
276
+ * Apply a color to the picker, the presets and the live preview (--widget-color).
277
+ * @param {string} value any hex format; invalid values fall back to the default color
278
+ * @param {boolean} keepText leave the hex field as typed (while the admin is typing)
279
+ */
280
+ function setColor(value, keepText) {
281
+ const hex = parseHex(value) || config.defaultColor;
282
+ if (!keepText) {
283
+ $('#colorcode').value = hex;
284
+ }
285
+ $('#colorpicker').value = '#' + hex.toLowerCase();
286
+ document.documentElement.style.setProperty('--widget-color', '#' + hex);
287
+ setColorError(false);
288
+ $$('.aioa-preset').forEach((btn) => {
289
+ btn.setAttribute('aria-pressed', String(btn.dataset.color === hex));
290
+ });
291
+ }
292
+
293
+ /* =========================================================================
294
+ * Save bar: unsaved changes indicator
295
+ * ======================================================================= */
296
+
297
+ function setDirty(dirty) {
298
+ $('#savebar').classList.toggle('is-dirty', dirty);
299
+ $('#save-state-text').textContent = dirty ? 'You have unsaved changes' : 'All changes saved';
300
+ }
301
+
302
+ /* =========================================================================
303
+ * Event listeners
304
+ * ======================================================================= */
305
+
306
+ // Color picker, hex field, presets, reset
307
+ $('#colorpicker').addEventListener('input', (e) => setColor(e.target.value));
308
+
309
+ $('#colorcode').addEventListener('input', (e) => {
310
+ const clean = e.target.value.replace(/[^0-9a-f]/gi, '').slice(0, 6).toUpperCase();
311
+ if (clean !== e.target.value) {
312
+ e.target.value = clean;
313
+ }
314
+ if (clean.length === 6) {
315
+ setColor(clean, true);
316
+ }
317
+ });
318
+
319
+ $('#colorcode').addEventListener('blur', (e) => {
320
+ const hex = parseHex(e.target.value);
321
+ if (hex) {
322
+ setColor(hex);
323
+ } else {
324
+ setColorError(true);
325
+ }
326
+ });
327
+
328
+ $$('.aioa-preset').forEach((btn) => {
329
+ btn.addEventListener('click', () => {
330
+ setColor(btn.dataset.color);
331
+ setDirty(true);
332
+ });
333
+ });
334
+
335
+ $('#color-reset').addEventListener('click', () => {
336
+ setColor(config.defaultColor);
337
+ setDirty(true);
338
+ });
339
+
340
+ // Any change marks the form as unsaved; Enter must not submit the form
341
+ $('#widget-form').addEventListener('input', () => setDirty(true));
342
+ $('#widget-form').addEventListener('change', () => setDirty(true));
343
+ $('#widget-form').addEventListener('submit', (e) => e.preventDefault());
344
+
345
+ // Preset / custom switches
346
+ $('#custom-position-switcher').addEventListener('change', syncCustomPosition);
347
+ $('#custom-size-switcher').addEventListener('change', syncCustomSize);
348
+
349
+ // Whole pixels only: exact offsets kept within 0 - 500 px while typing,
350
+ // the exact icon size (24 - 150 px) is checked when saving
351
+ ['#custom_position_x_value', '#custom_position_y_value'].forEach((selector) => {
352
+ wholeNumberField($(selector), 500);
353
+ });
354
+ wholeNumberField($('#widget_icon_size_custom'));
355
+
356
+ // Live previews
357
+ $$('input[name="position"]').forEach((radio) => {
358
+ radio.addEventListener('change', updateMiniWidget);
359
+ });
360
+
361
+ $$('input[name="aioa_icon_type"]').forEach((radio) => {
362
+ radio.addEventListener('change', () => updateIconImages(radio.value));
363
+ });
364
+
365
+ AIOA.form = {
366
+ settingsFrom: settingsFrom,
367
+ fill: fill,
368
+ collect: collect,
369
+ setDirty: setDirty
370
+ };
371
+ })(window.AIOA, document);
@@ -0,0 +1,108 @@
1
+ /**
2
+ * ---------------------------------------------------------------------------
3
+ * tabs.js - Appearance Design / Paid Features / Accessibility Score
4
+ * ---------------------------------------------------------------------------
5
+ * ARIA tabs (the "tabs" partial): click a tab, or use the arrow keys,
6
+ * Home and End on the tab row. The save bar shows only on tabs with something
7
+ * to save: Appearance Design, and Paid Features on a paid plan.
8
+ *
9
+ * Order and locks follow the plan (AIOA.tabs.setPlan, called by plan.js):
10
+ * paid plan Accessibility Score, Paid Features, Appearance Design
11
+ * free plan Appearance Design, Paid Features, Accessibility Score; the last
12
+ * two are blurred behind the upgrade overlay (the "lock" partial)
13
+ * The page opens on the tab the admin chose last time (localStorage "aioa-tab-picked"),
14
+ * otherwise on the first tab.
15
+ *
16
+ * AIOA.tabs.select(name, focus) show "appearance", "paid" or "score"
17
+ * AIOA.tabs.current()
18
+ * AIOA.tabs.setPlan(paid)
19
+ *
20
+ * Events on document: "aioa:tab-change" (detail.tab) "aioa:lock-change" (detail.locked)
21
+ */
22
+ (function (AIOA, document) {
23
+ 'use strict';
24
+
25
+ const { $, $$ } = AIOA.util;
26
+ const tablist = $('.aioa-tabs');
27
+ const tabs = $$('.aioa-tab');
28
+ const STORAGE_KEY = 'aioa-tab-picked';
29
+ const ORDER = {
30
+ paid: ['score', 'paid', 'appearance'],
31
+ free: ['appearance', 'paid', 'score']
32
+ };
33
+
34
+ let current = tabs[0].dataset.tab;
35
+ let paidPlan = false; // until the plan is known
36
+
37
+ /** Show one tab and its panel */
38
+ function show(name) {
39
+ const tab = tabs.find((t) => t.dataset.tab === name) || tabs[0];
40
+ current = tab.dataset.tab;
41
+
42
+ tabs.forEach((t) => {
43
+ const on = t === tab;
44
+ t.setAttribute('aria-selected', String(on));
45
+ t.tabIndex = on ? 0 : -1;
46
+ document.getElementById(t.getAttribute('aria-controls')).hidden = !on;
47
+ });
48
+
49
+ // Nothing to save on the score tab, nor on the locked Paid Features tab (free plan)
50
+ $('#save-area').hidden = !(current === 'appearance' || (current === 'paid' && paidPlan));
51
+
52
+ document.dispatchEvent(new CustomEvent('aioa:tab-change', { detail: { tab: current } }));
53
+ return tab;
54
+ }
55
+
56
+ /** Show a tab chosen by the admin, and remember it for the next visit */
57
+ function select(name, focus) {
58
+ const tab = show(name);
59
+ AIOA.storage.set(STORAGE_KEY, current);
60
+ if (focus) {
61
+ tab.focus();
62
+ }
63
+ }
64
+
65
+ /** Lock (free plan) or unlock (paid plan) the paid tabs */
66
+ function setLocked(locked) {
67
+ $$('[data-tab-lock]').forEach((el) => {
68
+ el.hidden = !locked;
69
+ });
70
+ $$('.aioa-lockable').forEach((box) => {
71
+ box.classList.toggle('is-locked', locked);
72
+ box.querySelector('.aioa-lock').hidden = !locked;
73
+ box.querySelector('.aioa-lock-content').inert = locked; // not focusable, not read out
74
+ });
75
+ document.dispatchEvent(new CustomEvent('aioa:lock-change', { detail: { locked: locked } }));
76
+ }
77
+
78
+ /** Order and lock the tabs for the plan, then open the remembered (or first) tab */
79
+ function setPlan(paid) {
80
+ paidPlan = paid;
81
+ const order = paid ? ORDER.paid : ORDER.free;
82
+ tabs.sort((a, b) => order.indexOf(a.dataset.tab) - order.indexOf(b.dataset.tab));
83
+ tablist.append(...tabs);
84
+
85
+ setLocked(!paid);
86
+ show(AIOA.storage.get(STORAGE_KEY) || tabs[0].dataset.tab);
87
+ }
88
+
89
+ tabs.forEach((tab) => {
90
+ tab.addEventListener('click', () => select(tab.dataset.tab));
91
+
92
+ tab.addEventListener('keydown', (e) => {
93
+ const index = tabs.indexOf(tab);
94
+ const target = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: tabs.length - 1 }[e.key];
95
+ if (target === undefined) {
96
+ return;
97
+ }
98
+ e.preventDefault();
99
+ select(tabs[(target + tabs.length) % tabs.length].dataset.tab, true);
100
+ });
101
+ });
102
+
103
+ AIOA.tabs = {
104
+ select: select,
105
+ current: () => current,
106
+ setPlan: setPlan
107
+ };
108
+ })(window.AIOA, document);