apostrophecms-plugin-all-in-one-accessibility 1.0.7 → 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.
- package/README.md +173 -168
- package/app/config.js +134 -0
- package/app/helpers.js +62 -0
- package/app/skynet-widget.js +509 -0
- package/assets/css/banners.css +77 -0
- package/assets/css/base.css +50 -0
- package/assets/css/components.css +91 -0
- package/assets/css/paid.css +53 -0
- package/assets/css/responsive.css +70 -0
- package/assets/css/score.css +42 -0
- package/assets/css/settings.css +154 -0
- package/assets/css/tabs.css +52 -0
- package/assets/css/tokens.css +53 -0
- package/assets/images/icons/aioa-icon-type-1.svg +1 -0
- package/assets/images/icons/aioa-icon-type-10.svg +1 -0
- package/assets/images/icons/aioa-icon-type-11.svg +1 -0
- package/assets/images/icons/aioa-icon-type-12.svg +1 -0
- package/assets/images/icons/aioa-icon-type-13.svg +1 -0
- package/assets/images/icons/aioa-icon-type-14.svg +29 -0
- package/assets/images/icons/aioa-icon-type-15.svg +26 -0
- package/assets/images/icons/aioa-icon-type-16.svg +17 -0
- package/assets/images/icons/aioa-icon-type-17.svg +24 -0
- package/assets/images/icons/aioa-icon-type-18.svg +20 -0
- package/assets/images/icons/aioa-icon-type-19.svg +25 -0
- package/assets/images/icons/aioa-icon-type-2.svg +1 -0
- package/assets/images/icons/aioa-icon-type-20.svg +24 -0
- package/assets/images/icons/aioa-icon-type-21.svg +28 -0
- package/assets/images/icons/aioa-icon-type-22.svg +21 -0
- package/assets/images/icons/aioa-icon-type-23.svg +21 -0
- package/assets/images/icons/aioa-icon-type-24.svg +21 -0
- package/assets/images/icons/aioa-icon-type-25.svg +15 -0
- package/assets/images/icons/aioa-icon-type-26.svg +23 -0
- package/assets/images/icons/aioa-icon-type-27.svg +21 -0
- package/assets/images/icons/aioa-icon-type-28.svg +27 -0
- package/assets/images/icons/aioa-icon-type-29.svg +25 -0
- package/assets/images/icons/aioa-icon-type-3.svg +1 -0
- package/assets/images/icons/aioa-icon-type-4.svg +16 -0
- package/assets/images/icons/aioa-icon-type-5.svg +1 -0
- package/assets/images/icons/aioa-icon-type-6.svg +1 -0
- package/assets/images/icons/aioa-icon-type-7.svg +1 -0
- package/assets/images/icons/aioa-icon-type-8.svg +1 -0
- package/assets/images/icons/aioa-icon-type-9.svg +1 -0
- package/assets/js/app.js +152 -0
- package/assets/js/core.js +249 -0
- package/assets/js/dashboard.js +97 -0
- package/assets/js/paid-features.js +237 -0
- package/assets/js/plan.js +65 -0
- package/assets/js/save.js +35 -0
- package/assets/js/score.js +130 -0
- package/assets/js/settings-form.js +371 -0
- package/assets/js/tabs.js +108 -0
- package/assets/js/ui.js +90 -0
- package/index.js +301 -15
- package/package.json +19 -9
- package/ui/apos/components/AllInOneAccessibilitySettings.vue +126 -679
- package/views/layout.ejs +97 -0
- package/views/partials/accessibility-score.ejs +37 -0
- package/views/partials/header.ejs +13 -0
- package/views/partials/lock.ejs +20 -0
- package/views/partials/paid/links.ejs +33 -0
- package/views/partials/paid/mobile-position.ejs +80 -0
- package/views/partials/paid/toggles.ejs +20 -0
- package/views/partials/paid-banner.ejs +19 -0
- package/views/partials/paid-features.ejs +14 -0
- package/views/partials/score/card.ejs +61 -0
- package/views/partials/settings/color.ejs +37 -0
- package/views/partials/settings/icon-size.ejs +43 -0
- package/views/partials/settings/icon-type.ejs +24 -0
- package/views/partials/settings/position.ejs +70 -0
- package/views/partials/settings/save-bar.ejs +9 -0
- package/views/partials/settings/widget-size.ejs +38 -0
- package/views/partials/settings-form.ejs +39 -0
- package/views/partials/site-strip.ejs +5 -0
- package/views/partials/status.ejs +16 -0
- package/views/partials/tabs.ejs +32 -0
- package/views/partials/upgrade-banner.ejs +34 -0
- package/views/scriptTag.html +7 -1
- package/ui/apos/apps/AllInOneAccessibilitySettings.js +0 -8
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ---------------------------------------------------------------------------
|
|
3
|
+
* core.js - shared namespace, configuration, state and helpers
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
* Loaded first. Every other script works through window.AIOA:
|
|
6
|
+
*
|
|
7
|
+
* AIOA.config fixed values (icon folder, API URLs, default settings)
|
|
8
|
+
* AIOA.boot what the platform sent: domain, name, email (any may be empty)
|
|
9
|
+
* AIOA.state values that change while the page is open
|
|
10
|
+
* AIOA.util DOM and validation helpers
|
|
11
|
+
* AIOA.storage localStorage that never throws
|
|
12
|
+
* AIOA.api requests to the server route and the Skynet API
|
|
13
|
+
*/
|
|
14
|
+
(function (window, document) {
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const AIOA = window.AIOA = window.AIOA || {};
|
|
18
|
+
|
|
19
|
+
/* ---------- Boot data (printed by the page layout in #aioa-boot) ---------- */
|
|
20
|
+
|
|
21
|
+
let boot = {};
|
|
22
|
+
try {
|
|
23
|
+
const bootEl = document.getElementById('aioa-boot');
|
|
24
|
+
boot = JSON.parse(bootEl ? bootEl.textContent : '{}') || {};
|
|
25
|
+
} catch (e) {
|
|
26
|
+
boot = {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* ---------- Configuration ---------- */
|
|
30
|
+
|
|
31
|
+
AIOA.config = {
|
|
32
|
+
iconBase: boot.iconBase || 'assets/images/icons/', // bundled icons (assets/images/icons)
|
|
33
|
+
defaultColor: boot.defaultColor || '420083',
|
|
34
|
+
routeUrl: boot.routeUrl || 'route.php', // server route, from the layout ("route.php" in PHP, "route" in Python / Node.js)
|
|
35
|
+
apiUpdateUrl: boot.apiUpdateUrl || 'https://ada.skynettechnologies.us/api/widget-setting-update-platform',
|
|
36
|
+
geoApiUrl: boot.geoApiUrl || 'https://ipapi.co/json', // EU check (in_eu), only before a website is registered
|
|
37
|
+
|
|
38
|
+
// Used until the settings of a registered website are loaded
|
|
39
|
+
defaults: {
|
|
40
|
+
widget_position: 'bottom_right',
|
|
41
|
+
widget_color_code: '#' + (boot.defaultColor || '420083'),
|
|
42
|
+
widget_icon_type: 'aioa-icon-type-1',
|
|
43
|
+
widget_icon_size: 'aioa-default-icon',
|
|
44
|
+
widget_size: 0
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Website and admin details sent by the platform (empty on headless platforms).
|
|
49
|
+
// A new website is registered with them; see app.js for the fallbacks.
|
|
50
|
+
AIOA.boot = {
|
|
51
|
+
domain: boot.domain || '',
|
|
52
|
+
name: boot.name || '',
|
|
53
|
+
email: boot.email || ''
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/* ---------- Helpers ---------- */
|
|
57
|
+
|
|
58
|
+
const util = AIOA.util = {
|
|
59
|
+
// Website host: a domain name or "localhost", never an IP address (same rules as the server's isValidDomain)
|
|
60
|
+
DOMAIN_RE: /^(?:localhost|(?=.{3,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63})$/,
|
|
61
|
+
|
|
62
|
+
/** First element that matches a CSS selector */
|
|
63
|
+
$(selector) {
|
|
64
|
+
return document.querySelector(selector);
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
/** Every element that matches a CSS selector, as an array */
|
|
68
|
+
$$(selector) {
|
|
69
|
+
return Array.from(document.querySelectorAll(selector));
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/** "https://www.Example.com/shop" -> "www.example.com" (same rules as the server's normalizeDomain) */
|
|
73
|
+
normalizeDomain(value) {
|
|
74
|
+
return String(value || '').trim().toLowerCase()
|
|
75
|
+
.replace(/^[a-z][a-z0-9+.-]*:\/\//, '') // scheme
|
|
76
|
+
.replace(/[/?#].*$/, '') // path, query, hash
|
|
77
|
+
.replace(/:\d+$/, '') // port
|
|
78
|
+
.replace(/^\.+|\.+$/g, '');
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
/** "#abc" / "aabbcc" -> "AABBCC", or null when the value is not a hex color */
|
|
82
|
+
parseHex(value) {
|
|
83
|
+
let hex = String(value || '').trim().replace(/^#/, '');
|
|
84
|
+
if (/^[0-9a-f]{3}$/i.test(hex)) {
|
|
85
|
+
hex = hex.split('').map((c) => c + c).join('');
|
|
86
|
+
}
|
|
87
|
+
return /^[0-9a-f]{6}$/i.test(hex) ? hex.toUpperCase() : null;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
/** Value of the checked radio button in a group, or '' */
|
|
91
|
+
checkedValue(name) {
|
|
92
|
+
const input = document.querySelector('input[name="' + name + '"]:checked');
|
|
93
|
+
return input ? input.value : '';
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
/** Check the radio button with the given value (ignored when it doesn't exist) */
|
|
97
|
+
checkRadio(name, value) {
|
|
98
|
+
const input = document.querySelector('input[name="' + name + '"][value="' + CSS.escape(String(value)) + '"]');
|
|
99
|
+
if (input) {
|
|
100
|
+
input.checked = true;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Saved widget position -> grid value. Older saves use the spelling
|
|
106
|
+
* "middel_left" / "middel_right"; the grid uses "middle_left" / "middle_right".
|
|
107
|
+
*/
|
|
108
|
+
positionValue(value) {
|
|
109
|
+
return String(value || '').replace(/^middel_/, 'middle_');
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
/** Whole number from a field or API value ("40", 40.7, "0.500" -> 40, 40, 0); fallback when empty or not a number */
|
|
113
|
+
wholeNumber(value, fallback) {
|
|
114
|
+
if (value === null || value === undefined || String(value).trim() === '') {
|
|
115
|
+
return fallback;
|
|
116
|
+
}
|
|
117
|
+
const number = Math.trunc(Number(value));
|
|
118
|
+
return Number.isFinite(number) ? number : fallback;
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Whole numbers only in a number field: ".", ",", "e", "+" and "-" can't be typed, and a
|
|
123
|
+
* pasted or dropped value such as "0.500" becomes a whole number (0). With max, the value
|
|
124
|
+
* is also kept between 0 and max while typing.
|
|
125
|
+
*/
|
|
126
|
+
wholeNumberField(input, max) {
|
|
127
|
+
input.addEventListener('keydown', (e) => {
|
|
128
|
+
if (!e.ctrlKey && !e.metaKey && ['.', ',', 'e', 'E', '+', '-'].includes(e.key)) {
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
const normalize = () => {
|
|
133
|
+
let number = util.wholeNumber(input.value, null);
|
|
134
|
+
if (number === null) {
|
|
135
|
+
return; // empty
|
|
136
|
+
}
|
|
137
|
+
if (max !== undefined) {
|
|
138
|
+
number = Math.min(Math.max(number, 0), max);
|
|
139
|
+
}
|
|
140
|
+
if (String(number) !== input.value) {
|
|
141
|
+
input.value = number;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
input.addEventListener('input', normalize);
|
|
145
|
+
input.addEventListener('change', normalize);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Fields that must hold a valid value before saving, such as an exact position ("0" is a
|
|
150
|
+
* value, an empty field is not) or an exact icon size. isValid(input) is the rule; without
|
|
151
|
+
* it a field only has to be filled in. Returns { check, reset }:
|
|
152
|
+
* check() marks each invalid field (red border, aria-invalid), puts message in the
|
|
153
|
+
* error element under them and returns the first invalid field, or null
|
|
154
|
+
* reset() clears the marks and the message
|
|
155
|
+
* Once the message is shown, the marks follow what the admin types.
|
|
156
|
+
*/
|
|
157
|
+
requiredFields(inputs, error, message, isValid) {
|
|
158
|
+
const valid = isValid || ((input) => input.value.trim() !== '');
|
|
159
|
+
const mark = (input, empty) => {
|
|
160
|
+
input.setAttribute('aria-invalid', empty ? 'true' : 'false');
|
|
161
|
+
const box = document.querySelector('[data-for="' + input.id + '"]');
|
|
162
|
+
if (box) {
|
|
163
|
+
box.classList.toggle('is-invalid', empty);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
// The error element stays empty while hidden, so screen readers never read a stale message
|
|
167
|
+
const show = (text) => {
|
|
168
|
+
error.textContent = text;
|
|
169
|
+
error.hidden = !text;
|
|
170
|
+
};
|
|
171
|
+
const check = () => {
|
|
172
|
+
const invalid = inputs.filter((input) => !valid(input));
|
|
173
|
+
inputs.forEach((input) => mark(input, invalid.includes(input)));
|
|
174
|
+
show(invalid.length ? message : '');
|
|
175
|
+
return invalid[0] || null;
|
|
176
|
+
};
|
|
177
|
+
const reset = () => {
|
|
178
|
+
inputs.forEach((input) => mark(input, false));
|
|
179
|
+
show('');
|
|
180
|
+
};
|
|
181
|
+
inputs.forEach((input) => {
|
|
182
|
+
input.addEventListener('input', () => {
|
|
183
|
+
if (!error.hidden) {
|
|
184
|
+
check();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
return { check: check, reset: reset };
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/* ---------- Storage ---------- */
|
|
193
|
+
|
|
194
|
+
AIOA.storage = {
|
|
195
|
+
get(key) {
|
|
196
|
+
try { return window.localStorage.getItem(key) || ''; } catch (e) { return ''; }
|
|
197
|
+
},
|
|
198
|
+
set(key, value) {
|
|
199
|
+
try { window.localStorage.setItem(key, value); } catch (e) { /* storage blocked */ }
|
|
200
|
+
},
|
|
201
|
+
remove(key) {
|
|
202
|
+
try { window.localStorage.removeItem(key); } catch (e) { /* storage blocked */ }
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/* ---------- State ---------- */
|
|
207
|
+
|
|
208
|
+
// Website: the platform's `url`, otherwise this page's own hostname (a domain or localhost, not an IP address).
|
|
209
|
+
// An invalid `url` never falls back to the hostname (on a platform's admin page that is not the website).
|
|
210
|
+
const domain = util.normalizeDomain(AIOA.boot.domain || window.location.hostname);
|
|
211
|
+
const activeDomain = util.DOMAIN_RE.test(domain) ? domain : '';
|
|
212
|
+
|
|
213
|
+
AIOA.state = {
|
|
214
|
+
activeDomain: activeDomain, // website whose settings are shown ('' = none found)
|
|
215
|
+
isPaid: false, // true for a paid plan: Paid Features and Accessibility Score are unlocked
|
|
216
|
+
customPosition: 0, // 1 = exact offsets instead of the preset positions
|
|
217
|
+
customSize: 0 // 1 = exact icon size instead of the preset sizes
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/* ---------- API ---------- */
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* POST form fields and resolve with the parsed JSON (or the raw text).
|
|
224
|
+
* null / undefined values are sent as empty strings.
|
|
225
|
+
*/
|
|
226
|
+
function post(url, data) {
|
|
227
|
+
const body = new URLSearchParams();
|
|
228
|
+
Object.keys(data).forEach((key) => {
|
|
229
|
+
const value = data[key];
|
|
230
|
+
body.append(key, value === null || value === undefined ? '' : value);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
return fetch(url, { method: 'POST', body: body }).then((res) => res.text().then((text) => {
|
|
234
|
+
if (!res.ok) {
|
|
235
|
+
throw new Error('Request failed (' + res.status + ')');
|
|
236
|
+
}
|
|
237
|
+
try { return JSON.parse(text); } catch (e) { return text; }
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
AIOA.api = {
|
|
242
|
+
post: post,
|
|
243
|
+
|
|
244
|
+
/** POST <routeUrl>?action=<action>: the server route (actions: docs/API.md) */
|
|
245
|
+
route(action, data) {
|
|
246
|
+
return post(AIOA.config.routeUrl + '?action=' + encodeURIComponent(action), data || {});
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
})(window, document);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ---------------------------------------------------------------------------
|
|
3
|
+
* dashboard.js - paid plan "Dashboard" button
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
* The dashboard sign-in link ("manage_domain" from check-website, through
|
|
6
|
+
* the server route, action getDashboardLink) is loaded once, as soon as the plan is
|
|
7
|
+
* known to be paid (AIOA.dashboard.load, called by app.js). A click never
|
|
8
|
+
* calls the API, so the dashboard opens at once:
|
|
9
|
+
* link loaded -> opens it in a new tab
|
|
10
|
+
* link still loading -> opens the tab at once, points it at the link when it arrives
|
|
11
|
+
* link failed to load -> error message (reload the page to try again)
|
|
12
|
+
*
|
|
13
|
+
* AIOA.dashboard.load() load the link (once per page load)
|
|
14
|
+
*/
|
|
15
|
+
(function (AIOA, window) {
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const { $$ } = AIOA.util;
|
|
19
|
+
|
|
20
|
+
let request = null; // the one getDashboardLink request of this page load
|
|
21
|
+
let link = ''; // the sign-in link once it has loaded
|
|
22
|
+
let failure = null; // why it could not be loaded
|
|
23
|
+
|
|
24
|
+
/** Load the dashboard link (paid plans, once per page load) */
|
|
25
|
+
function load() {
|
|
26
|
+
if (request) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
request = AIOA.api.route('getDashboardLink', { url: AIOA.state.activeDomain })
|
|
30
|
+
.then((result) => {
|
|
31
|
+
const value = result && result.link;
|
|
32
|
+
// Only ever open an https link
|
|
33
|
+
if (!value || !/^https:\/\//i.test(value)) {
|
|
34
|
+
throw new Error((result && result.error) || 'Unable to load the dashboard link.');
|
|
35
|
+
}
|
|
36
|
+
link = value;
|
|
37
|
+
return value;
|
|
38
|
+
});
|
|
39
|
+
request.catch((err) => {
|
|
40
|
+
failure = err;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Point a tab at the link; when the browser blocked the tab, offer the link in a toast */
|
|
45
|
+
function openIn(win, url) {
|
|
46
|
+
if (win && !win.closed) {
|
|
47
|
+
win.opener = null;
|
|
48
|
+
win.location.href = url;
|
|
49
|
+
} else {
|
|
50
|
+
AIOA.ui.toast('success', 'Your dashboard link is ready', 'Your browser blocked the new tab.', { href: url, label: 'Open dashboard' });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function showError(err) {
|
|
55
|
+
const reason = err instanceof TypeError ? 'Please check your connection.' : (err && err.message) || '';
|
|
56
|
+
AIOA.ui.toast('error', 'Could not open the dashboard', (reason ? reason + ' ' : '') + 'Reload the page to try again.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function openDashboard(button) {
|
|
60
|
+
if (link) {
|
|
61
|
+
openIn(window.open('', '_blank'), link);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (failure || !request) {
|
|
65
|
+
showError(failure);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Still loading: open the tab now (inside the click, so popup blockers allow it)
|
|
70
|
+
// and point it at the link when the request that is already running finishes
|
|
71
|
+
const win = window.open('', '_blank');
|
|
72
|
+
if (win) {
|
|
73
|
+
try {
|
|
74
|
+
win.document.title = 'Opening dashboard…';
|
|
75
|
+
win.document.body.style.cssText = 'font-family:system-ui,sans-serif;display:grid;place-items:center;min-height:90vh;color:#420083';
|
|
76
|
+
win.document.body.textContent = 'Opening your All in One Accessibility dashboard…';
|
|
77
|
+
} catch (e) { /* the new tab is not scriptable, the link still works */ }
|
|
78
|
+
}
|
|
79
|
+
AIOA.ui.setBusy(button, true, 'Opening…');
|
|
80
|
+
|
|
81
|
+
request
|
|
82
|
+
.then((url) => openIn(win, url))
|
|
83
|
+
.catch((err) => {
|
|
84
|
+
if (win && !win.closed) {
|
|
85
|
+
win.close();
|
|
86
|
+
}
|
|
87
|
+
showError(err);
|
|
88
|
+
})
|
|
89
|
+
.finally(() => AIOA.ui.setBusy(button, false));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
$$('[data-aioa-dashboard]').forEach((button) => {
|
|
93
|
+
button.addEventListener('click', () => openDashboard(button));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
AIOA.dashboard = { load: load };
|
|
97
|
+
})(window.AIOA, window);
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ---------------------------------------------------------------------------
|
|
3
|
+
* paid-features.js - Paid Features tab
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
* Fields (the "paid" partials) and the API parameters they become:
|
|
6
|
+
* statement_link, report_problem_link empty or a full http(s) link
|
|
7
|
+
* widget_leave_page, is_sound_disabled switches, 1 / 0
|
|
8
|
+
* is_mobile_position switch: separate position on phones
|
|
9
|
+
* is_widget_custom_position_mobile "Set an exact position in pixels": 0 presets / 1 offsets
|
|
10
|
+
* widget_position_mobile preset, e.g. "bottom_right"
|
|
11
|
+
* Exact position, every value a whole number of px, 0 - 500:
|
|
12
|
+
* horizontal To the left / To the right / Center
|
|
13
|
+
* widget_position_left_mobile, widget_position_right_mobile,
|
|
14
|
+
* widget_position_horizontal_center_offset_mobile
|
|
15
|
+
* vertical To the top / To the bottom
|
|
16
|
+
* widget_position_top_mobile, widget_position_bottom_mobile
|
|
17
|
+
* Only the chosen direction of each axis is sent; the others are empty
|
|
18
|
+
* (widget_position_vertical_center_offset_mobile is always empty).
|
|
19
|
+
*
|
|
20
|
+
* AIOA.paid.fill(result) saved values -> tab
|
|
21
|
+
* AIOA.paid.validate() check the tab before saving: marks every invalid field and
|
|
22
|
+
* returns the problems (see AIOA.form.collect)
|
|
23
|
+
* AIOA.paid.collect() read the tab as API parameters (after validate)
|
|
24
|
+
*/
|
|
25
|
+
(function (AIOA, document) {
|
|
26
|
+
'use strict';
|
|
27
|
+
|
|
28
|
+
const { $, checkedValue, checkRadio, positionValue, wholeNumber, wholeNumberField, requiredFields } = AIOA.util;
|
|
29
|
+
|
|
30
|
+
const LINKS = ['statement_link', 'report_problem_link'];
|
|
31
|
+
const LINK_NAMES = { statement_link: 'Accessibility statement link', report_problem_link: 'Report a problem link' };
|
|
32
|
+
const SWITCHES = ['widget_leave_page', 'is_sound_disabled'];
|
|
33
|
+
const OFFSET_MAX = 500;
|
|
34
|
+
|
|
35
|
+
const isSet = (value) => value !== null && value !== undefined && value !== '';
|
|
36
|
+
const isOn = (value) => Number(value) === 1;
|
|
37
|
+
const num = (value) => wholeNumber(value, 0);
|
|
38
|
+
|
|
39
|
+
// Exact mobile position: both values are required while it is in use
|
|
40
|
+
const mobileFields = requiredFields(
|
|
41
|
+
[$('#mobile_x_value'), $('#mobile_y_value')],
|
|
42
|
+
$('#mobile-pos-error'),
|
|
43
|
+
'Enter a horizontal and a vertical position from 0 to 500 px.'
|
|
44
|
+
);
|
|
45
|
+
const mobileExact = () => $('#is_mobile_position').checked && $('#custom-position-mobile-switcher').checked;
|
|
46
|
+
|
|
47
|
+
/* =========================================================================
|
|
48
|
+
* Links
|
|
49
|
+
* ======================================================================= */
|
|
50
|
+
|
|
51
|
+
/** "www.example.com/page" -> "https://www.example.com/page" (links typed without a scheme) */
|
|
52
|
+
function withScheme(value) {
|
|
53
|
+
const text = String(value || '').trim();
|
|
54
|
+
if (text && !/^[a-z][a-z0-9+.-]*:/i.test(text) && /^[^\s/]+\.[^\s/]+/.test(text)) {
|
|
55
|
+
return 'https://' + text;
|
|
56
|
+
}
|
|
57
|
+
return text;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Empty, or an http(s) link to a real domain */
|
|
61
|
+
function isValidLink(value) {
|
|
62
|
+
if (!value) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const url = new URL(value);
|
|
67
|
+
return (url.protocol === 'https:' || url.protocol === 'http:') && url.hostname.includes('.');
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function setLinkError(name, message) {
|
|
74
|
+
const error = $('#' + name + '-error');
|
|
75
|
+
error.textContent = message || '';
|
|
76
|
+
error.hidden = !message;
|
|
77
|
+
$('#' + name).setAttribute('aria-invalid', message ? 'true' : 'false');
|
|
78
|
+
$('[data-for="' + name + '"]').classList.toggle('is-invalid', !!message);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Add the scheme if needed and show an error under an invalid link; true when valid */
|
|
82
|
+
function checkLink(name) {
|
|
83
|
+
const input = $('#' + name);
|
|
84
|
+
input.value = withScheme(input.value);
|
|
85
|
+
const valid = isValidLink(input.value);
|
|
86
|
+
setLinkError(name, valid ? '' : 'Enter a full link that starts with https://, for example ' + input.placeholder);
|
|
87
|
+
return valid;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* =========================================================================
|
|
91
|
+
* Widget position for mobile
|
|
92
|
+
* ======================================================================= */
|
|
93
|
+
|
|
94
|
+
/** Switch on/off, preset grid <-> exact offsets */
|
|
95
|
+
function syncMobile() {
|
|
96
|
+
$('#mobile-position-body').hidden = !$('#is_mobile_position').checked;
|
|
97
|
+
const custom = $('#custom-position-mobile-switcher').checked;
|
|
98
|
+
$('#mobile-preset').hidden = custom;
|
|
99
|
+
$('#mobile-custom').hidden = !custom;
|
|
100
|
+
if (!mobileExact()) {
|
|
101
|
+
mobileFields.reset();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Move the icon in the "Mobile view" preview to the selected position */
|
|
106
|
+
function updateMobilePreview() {
|
|
107
|
+
const input = document.querySelector('input[name="position_mobile"]:checked');
|
|
108
|
+
if (input) {
|
|
109
|
+
$('#mini-widget-mobile').style.setProperty('--gx', input.dataset.gx);
|
|
110
|
+
$('#mini-widget-mobile').style.setProperty('--gy', input.dataset.gy);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Set one axis of the exact offsets (a whole number, 0 - 500 px) */
|
|
115
|
+
function setAxis(axis, direction, value) {
|
|
116
|
+
$('#mobile_' + axis + '_dir').value = direction;
|
|
117
|
+
$('#mobile_' + axis + '_value').value = Math.min(Math.max(num(value), 0), OFFSET_MAX);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** { direction, value } of one axis of the exact offsets */
|
|
121
|
+
function readAxis(axis) {
|
|
122
|
+
return { direction: $('#mobile_' + axis + '_dir').value, value: num($('#mobile_' + axis + '_value').value) };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* =========================================================================
|
|
126
|
+
* Fill / collect
|
|
127
|
+
* ======================================================================= */
|
|
128
|
+
|
|
129
|
+
function fill(result) {
|
|
130
|
+
const r = result || {};
|
|
131
|
+
mobileFields.reset();
|
|
132
|
+
|
|
133
|
+
LINKS.forEach((name) => {
|
|
134
|
+
$('#' + name).value = r[name] || '';
|
|
135
|
+
setLinkError(name, '');
|
|
136
|
+
});
|
|
137
|
+
SWITCHES.forEach((name) => {
|
|
138
|
+
$('#' + name).checked = isOn(r[name]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
$('#is_mobile_position').checked = isOn(r.is_mobile_position);
|
|
142
|
+
$('#custom-position-mobile-switcher').checked = isOn(r.is_widget_custom_position_mobile);
|
|
143
|
+
checkRadio('position_mobile', 'bottom_right');
|
|
144
|
+
checkRadio('position_mobile', positionValue(r.widget_position_mobile));
|
|
145
|
+
updateMobilePreview();
|
|
146
|
+
|
|
147
|
+
// Horizontal: center offset first, then right wins over left (as on desktop)
|
|
148
|
+
if (isSet(r.widget_position_horizontal_center_offset_mobile)) {
|
|
149
|
+
setAxis('x', 'center', r.widget_position_horizontal_center_offset_mobile);
|
|
150
|
+
} else if (num(r.widget_position_left_mobile) > 0 && !(num(r.widget_position_right_mobile) > 0)) {
|
|
151
|
+
setAxis('x', 'left', r.widget_position_left_mobile);
|
|
152
|
+
} else {
|
|
153
|
+
setAxis('x', 'right', r.widget_position_right_mobile);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Vertical: bottom wins over top (as on desktop)
|
|
157
|
+
if (num(r.widget_position_top_mobile) > 0 && !(num(r.widget_position_bottom_mobile) > 0)) {
|
|
158
|
+
setAxis('y', 'top', r.widget_position_top_mobile);
|
|
159
|
+
} else {
|
|
160
|
+
setAxis('y', 'bottom', r.widget_position_bottom_mobile);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
syncMobile();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Check the tab before saving. Every invalid field is marked at the same time; returns the
|
|
168
|
+
* problems in page order, in the same shape as AIOA.form's.
|
|
169
|
+
*/
|
|
170
|
+
function validate() {
|
|
171
|
+
const problems = [];
|
|
172
|
+
|
|
173
|
+
// Exact mobile position: an empty field is never saved as 0
|
|
174
|
+
const emptyOffset = mobileExact() ? mobileFields.check() : null;
|
|
175
|
+
if (emptyOffset) {
|
|
176
|
+
problems.push({ field: emptyOffset, tab: 'paid', name: 'Widget position for mobile (Paid Features)',
|
|
177
|
+
title: 'Mobile position missing', text: 'Enter the exact mobile position (0 - 500 px) on the Paid Features tab.' });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
LINKS.forEach((name) => {
|
|
181
|
+
if (!checkLink(name)) {
|
|
182
|
+
problems.push({ field: $('#' + name), tab: 'paid', name: LINK_NAMES[name] + ' (Paid Features)',
|
|
183
|
+
title: 'Invalid link', text: 'Check the links on the Paid Features tab.' });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return problems;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function collect() {
|
|
191
|
+
const x = readAxis('x');
|
|
192
|
+
const y = readAxis('y');
|
|
193
|
+
const offset = (axis, direction) => (axis.direction === direction ? axis.value : '');
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
statement_link: $('#statement_link').value,
|
|
197
|
+
report_problem_link: $('#report_problem_link').value,
|
|
198
|
+
widget_leave_page: $('#widget_leave_page').checked ? 1 : 0,
|
|
199
|
+
is_sound_disabled: $('#is_sound_disabled').checked ? 1 : 0,
|
|
200
|
+
is_mobile_position: $('#is_mobile_position').checked ? 1 : 0,
|
|
201
|
+
is_widget_custom_position_mobile: $('#custom-position-mobile-switcher').checked ? 1 : 0,
|
|
202
|
+
widget_position_mobile: checkedValue('position_mobile'),
|
|
203
|
+
widget_position_right_mobile: offset(x, 'right'),
|
|
204
|
+
widget_position_left_mobile: offset(x, 'left'),
|
|
205
|
+
widget_position_horizontal_center_offset_mobile: offset(x, 'center'),
|
|
206
|
+
widget_position_bottom_mobile: offset(y, 'bottom'),
|
|
207
|
+
widget_position_top_mobile: offset(y, 'top'),
|
|
208
|
+
widget_position_vertical_center_offset_mobile: '' // no vertical center option: always cleared
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/* =========================================================================
|
|
213
|
+
* Event listeners
|
|
214
|
+
* ======================================================================= */
|
|
215
|
+
|
|
216
|
+
LINKS.forEach((name) => {
|
|
217
|
+
$('#' + name).addEventListener('blur', () => checkLink(name));
|
|
218
|
+
$('#' + name).addEventListener('input', () => setLinkError(name, ''));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
$('#is_mobile_position').addEventListener('change', syncMobile);
|
|
222
|
+
$('#custom-position-mobile-switcher').addEventListener('change', syncMobile);
|
|
223
|
+
document.querySelectorAll('input[name="position_mobile"]').forEach((radio) => {
|
|
224
|
+
radio.addEventListener('change', updateMobilePreview);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Whole pixels only, kept within 0 - 500 px while typing
|
|
228
|
+
['x', 'y'].forEach((axis) => {
|
|
229
|
+
wholeNumberField($('#mobile_' + axis + '_value'), OFFSET_MAX);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
AIOA.paid = {
|
|
233
|
+
fill: fill,
|
|
234
|
+
validate: validate,
|
|
235
|
+
collect: collect
|
|
236
|
+
};
|
|
237
|
+
})(window.AIOA, document);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ---------------------------------------------------------------------------
|
|
3
|
+
* plan.js - what is shown above the settings, and the tabs for the plan
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
* free plan -> "Upgrade to Paid Plan" banner (#free_plan_upgrade_block); its links
|
|
6
|
+
* carry the website, email and name (upgradeLinks)
|
|
7
|
+
* paid plan -> paid card with "Dashboard" (#paid_plan_block)
|
|
8
|
+
* plus the "Widget installed on <domain>" line.
|
|
9
|
+
* Tabs (AIOA.tabs.setPlan): a paid plan starts with Accessibility Score;
|
|
10
|
+
* on the free plan Paid Features and Accessibility Score are locked.
|
|
11
|
+
*/
|
|
12
|
+
(function (AIOA, document) {
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const { $, $$ } = AIOA.util;
|
|
16
|
+
const state = AIOA.state;
|
|
17
|
+
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* "Upgrade to Paid Plan" links (the banner and the lock overlays, [data-upgrade-link]):
|
|
21
|
+
* add what the trial form can fill in, for example
|
|
22
|
+
* …/trial-subscription?website=example.com&email=dev@example.com&first_name=Jane&last_name=Doe
|
|
23
|
+
* website is the website shown, email the admin's email (only a valid one), first_name the
|
|
24
|
+
* first word of the admin's name and last_name the rest. Empty values are left out.
|
|
25
|
+
*/
|
|
26
|
+
function upgradeLinks() {
|
|
27
|
+
const name = String(AIOA.boot.name || '').trim().split(/\s+/).filter(Boolean);
|
|
28
|
+
const email = String(AIOA.boot.email || '').trim();
|
|
29
|
+
const query = [
|
|
30
|
+
['website', state.activeDomain],
|
|
31
|
+
['email', EMAIL_RE.test(email) ? email : ''],
|
|
32
|
+
['first_name', name[0] || ''],
|
|
33
|
+
['last_name', name.slice(1).join(' ')]
|
|
34
|
+
]
|
|
35
|
+
.filter((pair) => pair[1] !== '')
|
|
36
|
+
.map((pair) => pair[0] + '=' + encodeURIComponent(pair[1]).replace(/%40/g, '@'))
|
|
37
|
+
.join('&');
|
|
38
|
+
|
|
39
|
+
if (query) {
|
|
40
|
+
$$('a[data-upgrade-link]').forEach((link) => {
|
|
41
|
+
const base = link.getAttribute('href');
|
|
42
|
+
link.setAttribute('href', base + (base.includes('?') ? '&' : '?') + query);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
upgradeLinks();
|
|
48
|
+
|
|
49
|
+
AIOA.plan = {
|
|
50
|
+
/**
|
|
51
|
+
* @param {number|string} is_free_widget from the widget settings response: 1 = free plan, anything else = paid plan
|
|
52
|
+
*/
|
|
53
|
+
render(is_free_widget) {
|
|
54
|
+
state.isPaid = parseInt(is_free_widget, 10) !== 1;
|
|
55
|
+
|
|
56
|
+
$('#free_plan_upgrade_block').hidden = state.isPaid;
|
|
57
|
+
$('#paid_plan_block').hidden = !state.isPaid;
|
|
58
|
+
AIOA.tabs.setPlan(state.isPaid);
|
|
59
|
+
|
|
60
|
+
const domain = document.createElement('strong');
|
|
61
|
+
domain.textContent = state.activeDomain;
|
|
62
|
+
$('#site-text').replaceChildren('Widget installed on ', domain);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
})(window.AIOA, document);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ---------------------------------------------------------------------------
|
|
3
|
+
* save.js - "Save Changes"
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
* Sends the settings straight to the Skynet API (widget-setting-update-platform).
|
|
6
|
+
* The website is always registered by the time the settings are shown (app.js).
|
|
7
|
+
*/
|
|
8
|
+
(function (AIOA) {
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
const { $ } = AIOA.util;
|
|
12
|
+
|
|
13
|
+
function save() {
|
|
14
|
+
const params = AIOA.form.collect();
|
|
15
|
+
if (!params) {
|
|
16
|
+
return; // invalid form, the problem is already shown
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const button = $('#submit');
|
|
20
|
+
AIOA.ui.setBusy(button, true, 'Saving…');
|
|
21
|
+
|
|
22
|
+
AIOA.api.post(AIOA.config.apiUpdateUrl, params)
|
|
23
|
+
.then(() => {
|
|
24
|
+
AIOA.form.setDirty(false);
|
|
25
|
+
AIOA.ui.toast('success', 'Settings saved successfully!', 'It may take a few seconds for changes to appear on your website.');
|
|
26
|
+
})
|
|
27
|
+
.catch((err) => {
|
|
28
|
+
console.error('AJAX error:', err);
|
|
29
|
+
AIOA.ui.toast('error', 'Something went wrong.', 'Your settings were not saved. Please try again.');
|
|
30
|
+
})
|
|
31
|
+
.finally(() => AIOA.ui.setBusy(button, false));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
$('#submit').addEventListener('click', save);
|
|
35
|
+
})(window.AIOA);
|