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.
- package/README.md +195 -163
- 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
package/assets/js/ui.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ---------------------------------------------------------------------------
|
|
3
|
+
* ui.js - toasts, busy buttons and page views
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
* AIOA.ui.setView(id) loading / error / settings
|
|
6
|
+
* AIOA.ui.setBusy(button, busy, label) spinner while a request runs
|
|
7
|
+
* AIOA.ui.toast(type, title, msg, action) notification in the top right
|
|
8
|
+
*/
|
|
9
|
+
(function (AIOA) {
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const { $ } = AIOA.util;
|
|
13
|
+
|
|
14
|
+
// Small inline icons used by the toasts
|
|
15
|
+
const ICONS = {
|
|
16
|
+
check: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>',
|
|
17
|
+
alert: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round"><path d="M12 7v6M12 17v.5"/></svg>',
|
|
18
|
+
close: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Only one of these is visible at a time (the "status" partial and the layout)
|
|
22
|
+
const VIEWS = ['load', 'error_block', 'settings_block'];
|
|
23
|
+
|
|
24
|
+
AIOA.ui = {
|
|
25
|
+
/** Show one view: "load", "error_block" or "settings_block" */
|
|
26
|
+
setView(id) {
|
|
27
|
+
VIEWS.forEach((view) => {
|
|
28
|
+
document.getElementById(view).hidden = view !== id;
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/** Swap a button's content for a spinner + label while busy, and restore it afterwards */
|
|
33
|
+
setBusy(button, busy, label) {
|
|
34
|
+
if (busy) {
|
|
35
|
+
button.dataset.html = button.innerHTML;
|
|
36
|
+
button.disabled = true;
|
|
37
|
+
button.setAttribute('aria-busy', 'true');
|
|
38
|
+
button.innerHTML = '<span class="aioa-spinner" aria-hidden="true"></span><span>' + label + '</span>';
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
button.disabled = false;
|
|
43
|
+
button.removeAttribute('aria-busy');
|
|
44
|
+
if (button.dataset.html) {
|
|
45
|
+
button.innerHTML = button.dataset.html;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Show a toast notification.
|
|
51
|
+
* @param {"success"|"error"} type
|
|
52
|
+
* @param {string} title
|
|
53
|
+
* @param {string} [message]
|
|
54
|
+
* @param {{href: string, label: string}} [action] optional link (opens in a new tab)
|
|
55
|
+
*/
|
|
56
|
+
toast(type, title, message, action) {
|
|
57
|
+
const el = document.createElement('div');
|
|
58
|
+
el.className = 'aioa-toast is-' + type;
|
|
59
|
+
if (type === 'error') {
|
|
60
|
+
el.setAttribute('role', 'alert');
|
|
61
|
+
}
|
|
62
|
+
el.innerHTML = '<span class="aioa-toast-ic" aria-hidden="true">' + (type === 'success' ? ICONS.check : ICONS.alert) + '</span>' +
|
|
63
|
+
'<div class="aioa-toast-body"><strong></strong><p></p></div>' +
|
|
64
|
+
'<button type="button" class="aioa-toast-close" aria-label="Dismiss notification">' + ICONS.close + '</button>';
|
|
65
|
+
|
|
66
|
+
// Text is set with textContent so messages from the API can't inject HTML
|
|
67
|
+
el.querySelector('strong').textContent = title;
|
|
68
|
+
el.querySelector('p').textContent = message || '';
|
|
69
|
+
|
|
70
|
+
if (action) {
|
|
71
|
+
const link = document.createElement('a');
|
|
72
|
+
link.href = action.href;
|
|
73
|
+
link.target = '_blank';
|
|
74
|
+
link.rel = 'noopener';
|
|
75
|
+
link.textContent = action.label;
|
|
76
|
+
el.querySelector('.aioa-toast-body').appendChild(link);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const close = () => {
|
|
80
|
+
el.classList.add('is-leaving');
|
|
81
|
+
setTimeout(() => el.remove(), 200);
|
|
82
|
+
};
|
|
83
|
+
el.querySelector('.aioa-toast-close').addEventListener('click', close);
|
|
84
|
+
$('#toasts').appendChild(el);
|
|
85
|
+
|
|
86
|
+
// Links stay longer so there is time to click them
|
|
87
|
+
setTimeout(close, action ? 15000 : (type === 'error' ? 8000 : 5000));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
})(window.AIOA);
|
package/index.js
CHANGED
|
@@ -1,39 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ---------------------------------------------------------------------------
|
|
3
|
+
* All in One Accessibility® - ApostropheCMS module
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
* 1. Widget: every page of the website gets the All in One Accessibility widget
|
|
6
|
+
* script (views/scriptTag.html, appended to <head>). The widget loads the
|
|
7
|
+
* settings saved for the website by itself. When the website was registered
|
|
8
|
+
* by an admin in the EU, the EU widget script is used.
|
|
9
|
+
*
|
|
10
|
+
* 2. Settings page: "All in One Accessibility" in the admin bar opens the
|
|
11
|
+
* settings page in a modal (ui/apos/components/AllInOneAccessibilitySettings.vue).
|
|
12
|
+
* The page is its own HTML document (views/layout.ejs), so the website's CSS
|
|
13
|
+
* and the widget never load on it. Signed-in admins only.
|
|
14
|
+
*
|
|
15
|
+
* GET <settingsPath>/ The settings page (light theme). Reads ?url=, ?username=, ?email=
|
|
16
|
+
* POST <settingsPath>/route?action=... AJAX route used by the page. Every response is JSON.
|
|
17
|
+
* GET <settingsPath>/assets/... CSS, JavaScript and icons
|
|
18
|
+
*
|
|
19
|
+
* <settingsPath> defaults to /api/v1/apostrophecms-plugin-all-in-one-accessibility/settings
|
|
20
|
+
*
|
|
21
|
+
* A website that is not registered yet is registered for the free widget (once)
|
|
22
|
+
* as soon as the settings page opens, with no_required_eu from ipapi.co (EU or not)
|
|
23
|
+
* and the signed-in admin's name and email.
|
|
24
|
+
*
|
|
25
|
+
* Route actions (app/skynet-widget.js):
|
|
26
|
+
* fetchWidgetSettings Load settings ({"not_registered": true} for a new website; never registers)
|
|
27
|
+
* registerDomain Register the free widget for a new website (once), with no_required_eu
|
|
28
|
+
* getDashboardLink Dashboard sign-in link, manage_domain from check-website (paid plans)
|
|
29
|
+
* fetchScanDetails Accessibility Score tab: scan results of a domain (paid plans)
|
|
30
|
+
*
|
|
31
|
+
* Module options (app.js), all optional:
|
|
32
|
+
* domain Website domain. Default: the host of the Apostrophe `baseUrl`,
|
|
33
|
+
* otherwise the host the request was made to
|
|
34
|
+
* widget Add the widget to the website. Default: true
|
|
35
|
+
* region Widget script: 'auto' (default) | 'global' | 'eu'
|
|
36
|
+
* settingsPath Path of the settings page. Default: <module action URL>/settings
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
import fs from 'node:fs';
|
|
40
|
+
import path from 'node:path';
|
|
41
|
+
import ejs from 'ejs';
|
|
42
|
+
import * as config from './app/config.js';
|
|
43
|
+
import { aioaRequest, aioaSlug, asset, jsonForScript, lastValue } from './app/helpers.js';
|
|
44
|
+
import * as SkynetWidget from './app/skynet-widget.js';
|
|
45
|
+
|
|
46
|
+
const VIEWS_DIR = path.join(config.AIOA_ROOT, 'views');
|
|
47
|
+
const ASSETS_DIR = path.join(config.AIOA_ROOT, 'assets');
|
|
48
|
+
const LOG_PREFIX = 'All in One Accessibility:';
|
|
49
|
+
|
|
50
|
+
// Route actions, by name (the same names as the other language versions)
|
|
51
|
+
const ACTIONS = {
|
|
52
|
+
fetchWidgetSettings: SkynetWidget.fetchWidgetSettings,
|
|
53
|
+
registerDomain: SkynetWidget.registerDomain,
|
|
54
|
+
getDashboardLink: SkynetWidget.getDashboardLink,
|
|
55
|
+
fetchScanDetails: SkynetWidget.getScanDetails,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Seconds a page waits for the widget region (global or EU) before it uses the global script
|
|
59
|
+
const REGION_TIMEOUT = 3;
|
|
60
|
+
|
|
61
|
+
// How long a widget region is remembered: a known region for 6 hours, an unknown one
|
|
62
|
+
// (website not registered yet, API not reachable) for 1 minute
|
|
63
|
+
const REGION_TTL = 6 * 60 * 60 * 1000;
|
|
64
|
+
const REGION_RETRY_TTL = 60 * 1000;
|
|
65
|
+
|
|
66
|
+
// Content types of the files in assets/
|
|
67
|
+
const MIME_TYPES = {
|
|
68
|
+
'.css': 'text/css; charset=utf-8',
|
|
69
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
70
|
+
'.svg': 'image/svg+xml',
|
|
71
|
+
};
|
|
72
|
+
|
|
1
73
|
export default {
|
|
2
|
-
extend: '@apostrophecms/widget-type',
|
|
3
74
|
options: {
|
|
4
75
|
label: 'All in One Accessibility',
|
|
76
|
+
domain: '',
|
|
77
|
+
widget: true,
|
|
78
|
+
region: 'auto',
|
|
79
|
+
settingsPath: '',
|
|
5
80
|
},
|
|
6
|
-
|
|
7
|
-
|
|
81
|
+
|
|
82
|
+
init(self) {
|
|
83
|
+
self.settingsPath = normalizePath(self.options.settingsPath) || `${self.action}/settings`;
|
|
84
|
+
|
|
85
|
+
// Widget region by domain: { base, expires } or a pending lookup
|
|
86
|
+
self.regionCache = new Map();
|
|
87
|
+
|
|
88
|
+
self.apos.template.append('head', `${self.__meta.name}:scriptTag`);
|
|
8
89
|
self.addManagerModal();
|
|
9
90
|
self.addToAdminBar();
|
|
91
|
+
self.enableBrowserData();
|
|
10
92
|
},
|
|
93
|
+
|
|
11
94
|
methods(self) {
|
|
12
95
|
return {
|
|
13
96
|
addManagerModal() {
|
|
14
97
|
self.apos.modal.add(
|
|
15
|
-
|
|
98
|
+
self.__meta.name,
|
|
16
99
|
self.getComponentName('managerModal', 'AllInOneAccessibilitySettings'),
|
|
17
|
-
{ moduleName:
|
|
100
|
+
{ moduleName: self.__meta.name }
|
|
18
101
|
);
|
|
19
102
|
},
|
|
103
|
+
|
|
20
104
|
addToAdminBar() {
|
|
105
|
+
// Admins only, like the settings page and its route (see canManage)
|
|
21
106
|
self.apos.adminBar.add(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
107
|
+
self.__meta.name,
|
|
108
|
+
self.options.label,
|
|
109
|
+
{ action: 'edit', type: '@apostrophecms/user' }
|
|
25
110
|
);
|
|
26
111
|
},
|
|
27
|
-
|
|
112
|
+
|
|
113
|
+
getBrowserData(req) {
|
|
114
|
+
if (!self.canManage(req)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
settingsUrl: self.apos.prefix + self.settingsPath + '/',
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Platform integration point: who may open the settings page and call its route.
|
|
124
|
+
* Default: admins (users who may edit other users). Extend this method to change it.
|
|
125
|
+
*/
|
|
126
|
+
canManage(req) {
|
|
127
|
+
return !!req.user && self.apos.permission.can(req, 'edit', '@apostrophecms/user');
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Website domain: the module option "domain", otherwise the host of the Apostrophe
|
|
132
|
+
* baseUrl, otherwise the host of the request ('' when none is a valid domain).
|
|
133
|
+
*/
|
|
134
|
+
websiteDomain(req) {
|
|
135
|
+
for (const value of [ self.options.domain, self.apos.baseUrl, req.hostname ]) {
|
|
136
|
+
const domain = SkynetWidget.normalizeDomain(value);
|
|
137
|
+
if (SkynetWidget.isValidDomain(domain)) {
|
|
138
|
+
return domain;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return '';
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Widget script for the website (without the query string):
|
|
146
|
+
* region 'eu' / 'global' that script
|
|
147
|
+
* region 'auto' the EU script when the website was registered from the EU
|
|
148
|
+
* (no_required_eu = 0), otherwise the global script
|
|
149
|
+
*/
|
|
150
|
+
async widgetScriptBase(domain) {
|
|
151
|
+
if (self.options.region === 'eu') {
|
|
152
|
+
return config.AIOA_WIDGET_SCRIPT_EU;
|
|
153
|
+
}
|
|
154
|
+
if (self.options.region === 'global' || !domain) {
|
|
155
|
+
return config.AIOA_WIDGET_SCRIPT;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const cached = self.regionCache.get(domain);
|
|
159
|
+
if (cached && cached.pending) {
|
|
160
|
+
return cached.pending;
|
|
161
|
+
}
|
|
162
|
+
if (cached && cached.expires > Date.now()) {
|
|
163
|
+
return cached.base;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// One lookup at a time per domain: other page views wait for the same answer
|
|
167
|
+
const pending = SkynetWidget.getWidgetRegion(domain, REGION_TIMEOUT).then((region) => {
|
|
168
|
+
const base = region === 'eu' ? config.AIOA_WIDGET_SCRIPT_EU : config.AIOA_WIDGET_SCRIPT;
|
|
169
|
+
self.regionCache.set(domain, {
|
|
170
|
+
base,
|
|
171
|
+
expires: Date.now() + (region ? REGION_TTL : REGION_RETRY_TTL),
|
|
172
|
+
});
|
|
173
|
+
return base;
|
|
174
|
+
});
|
|
175
|
+
self.regionCache.set(domain, { pending });
|
|
176
|
+
return pending;
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
/** Render the settings page (views/layout.ejs) */
|
|
180
|
+
renderSettingsPage(req) {
|
|
181
|
+
const query = aioaRequest(req.query);
|
|
182
|
+
|
|
183
|
+
// Everything the templates need (views/layout.ejs)
|
|
184
|
+
const page = {
|
|
185
|
+
domain: query.url || self.websiteDomain(req),
|
|
186
|
+
name: query.username || (req.user && (req.user.title || req.user.username)) || '',
|
|
187
|
+
email: query.email || (req.user && req.user.email) || '',
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return ejs.renderFile(path.join(VIEWS_DIR, 'layout.ejs'), {
|
|
191
|
+
page,
|
|
192
|
+
cfg: config,
|
|
193
|
+
asset,
|
|
194
|
+
slug: aioaSlug,
|
|
195
|
+
jsonForScript,
|
|
196
|
+
}, {
|
|
197
|
+
cache: process.env.NODE_ENV === 'production',
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
routes(self) {
|
|
204
|
+
const base = self.settingsPath;
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
get: {
|
|
208
|
+
// Express matches this route with and without the trailing slash
|
|
209
|
+
async [base + '/'](req, res) {
|
|
210
|
+
// The page loads its assets and route relative to the folder: always open it with a trailing slash.
|
|
211
|
+
// req.url has no sitewide prefix; Apostrophe's res.redirect adds it back.
|
|
212
|
+
const url = new URL(req.url, 'http://localhost');
|
|
213
|
+
if (!url.pathname.endsWith('/')) {
|
|
214
|
+
return res.redirect(302, url.pathname + '/' + url.search);
|
|
215
|
+
}
|
|
216
|
+
if (!self.canManage(req)) {
|
|
217
|
+
return sendForbidden(res, 'Only signed-in admins can open the All in One Accessibility settings.');
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const html = await self.renderSettingsPage(req);
|
|
221
|
+
res.set({
|
|
222
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
223
|
+
'Cache-Control': 'no-store',
|
|
224
|
+
'X-Robots-Tag': 'noindex, nofollow',
|
|
225
|
+
});
|
|
226
|
+
res.send(html);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
self.apos.util.error(LOG_PREFIX, err);
|
|
229
|
+
res.status(500).send('Unable to load the All in One Accessibility settings.');
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
// CSS, JavaScript and icons. Only .css, .js and .svg files inside assets/ are served.
|
|
234
|
+
[base + '/assets/*'](req, res) {
|
|
235
|
+
const file = path.join(ASSETS_DIR, path.normalize('/' + (req.params[0] || '')));
|
|
236
|
+
const type = MIME_TYPES[path.extname(file)];
|
|
237
|
+
if (!type || !file.startsWith(ASSETS_DIR + path.sep)) {
|
|
238
|
+
return res.status(404).send('Not found');
|
|
239
|
+
}
|
|
240
|
+
fs.stat(file, (err, stat) => {
|
|
241
|
+
if (err || !stat.isFile()) {
|
|
242
|
+
return res.status(404).send('Not found');
|
|
243
|
+
}
|
|
244
|
+
res.set({
|
|
245
|
+
'Content-Type': type,
|
|
246
|
+
'Cache-Control': 'public, max-age=86400',
|
|
247
|
+
});
|
|
248
|
+
fs.createReadStream(file).pipe(res);
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
post: {
|
|
254
|
+
// AJAX router used by the page. Apostrophe's CSRF check applies to this route.
|
|
255
|
+
async [base + '/route'](req, res) {
|
|
256
|
+
if (!self.canManage(req)) {
|
|
257
|
+
return sendJson(res, { error: 'Only signed-in admins can change the All in One Accessibility settings.' }, 403);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const action = lastValue(req.query.action);
|
|
261
|
+
if (!Object.hasOwn(ACTIONS, action)) {
|
|
262
|
+
return sendJson(res, { error: 'Unknown action.' });
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const fields = {};
|
|
266
|
+
for (const [ key, value ] of Object.entries(req.body || {})) {
|
|
267
|
+
fields[key] = lastValue(value);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
try {
|
|
271
|
+
const result = await ACTIONS[action](fields);
|
|
272
|
+
// A new registration changes the widget region: look it up again on the next page view
|
|
273
|
+
if (action === 'registerDomain') {
|
|
274
|
+
self.regionCache.delete(SkynetWidget.normalizeDomain(fields.url));
|
|
275
|
+
}
|
|
276
|
+
sendJson(res, result);
|
|
277
|
+
} catch (err) {
|
|
278
|
+
self.apos.util.error(LOG_PREFIX, err);
|
|
279
|
+
sendJson(res, { error: 'Unable to process the request. Please try again.' }, 500);
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
};
|
|
28
284
|
},
|
|
285
|
+
|
|
29
286
|
components(self) {
|
|
30
287
|
return {
|
|
288
|
+
// The widget <script> tag (views/scriptTag.html), on every page of the website
|
|
31
289
|
async scriptTag(req) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
290
|
+
if (self.options.widget === false) {
|
|
291
|
+
return { scriptUrl: '' };
|
|
292
|
+
}
|
|
293
|
+
const base = await self.widgetScriptBase(self.websiteDomain(req));
|
|
294
|
+
return {
|
|
295
|
+
scriptUrl: base + config.AIOA_WIDGET_QUERY,
|
|
296
|
+
scriptId: config.AIOA_WIDGET_SCRIPT_ID,
|
|
297
|
+
};
|
|
298
|
+
},
|
|
37
299
|
};
|
|
38
|
-
}
|
|
300
|
+
},
|
|
39
301
|
};
|
|
302
|
+
|
|
303
|
+
/* =======================================================================
|
|
304
|
+
* Helpers
|
|
305
|
+
* ===================================================================== */
|
|
306
|
+
|
|
307
|
+
/** "settings/" -> "/settings", "" -> "" */
|
|
308
|
+
function normalizePath(value) {
|
|
309
|
+
const trimmed = String(value || '').trim().replace(/\/+$/, '');
|
|
310
|
+
if (!trimmed) {
|
|
311
|
+
return '';
|
|
312
|
+
}
|
|
313
|
+
return trimmed.startsWith('/') ? trimmed : '/' + trimmed;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function sendJson(res, data, status = 200) {
|
|
317
|
+
res.status(status).set('Content-Type', 'application/json; charset=utf-8').send(JSON.stringify(data));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function sendForbidden(res, message) {
|
|
321
|
+
res.status(403).set({
|
|
322
|
+
'Content-Type': 'text/plain; charset=utf-8',
|
|
323
|
+
'Cache-Control': 'no-store',
|
|
324
|
+
}).send(message);
|
|
325
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apostrophecms-plugin-all-in-one-accessibility",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Free website accessibility widget for ApostropheCMS: improves WCAG 2.0, 2.1, 2.2, ADA and EAA compliance, with a settings page for color, size, position and icon.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"apostrophecms",
|
|
8
8
|
"apostrophecms-plugin",
|
|
9
|
+
"apostrophe",
|
|
10
|
+
"accessibility",
|
|
11
|
+
"a11y",
|
|
12
|
+
"wcag",
|
|
13
|
+
"ada",
|
|
14
|
+
"eaa",
|
|
9
15
|
"All in One Accessibility",
|
|
10
16
|
"ADA",
|
|
11
17
|
"All in One Accessibility apostrophecms",
|
|
@@ -15,25 +21,29 @@
|
|
|
15
21
|
],
|
|
16
22
|
"repository": {
|
|
17
23
|
"type": "git",
|
|
18
|
-
"url": "https://github.com/skynettechnologies/apostrophecms-plugin-all-in-one-accessibility"
|
|
24
|
+
"url": "git+https://github.com/skynettechnologies/apostrophecms-plugin-all-in-one-accessibility.git"
|
|
19
25
|
},
|
|
20
26
|
"bugs": {
|
|
21
27
|
"url": "https://github.com/skynettechnologies/apostrophecms-plugin-all-in-one-accessibility/issues"
|
|
22
28
|
},
|
|
23
|
-
"homepage": "https://
|
|
29
|
+
"homepage": "https://www.skynettechnologies.com/apostrophe-cms-website-accessibility",
|
|
24
30
|
"license": "MIT",
|
|
25
31
|
"author": "Skynet Technologies USA LLC <developer3@skynettechnologies.com>",
|
|
26
32
|
"main": "index.js",
|
|
33
|
+
"files": [
|
|
34
|
+
"index.js",
|
|
35
|
+
"app/",
|
|
36
|
+
"assets/",
|
|
37
|
+
"ui/",
|
|
38
|
+
"views/"
|
|
39
|
+
],
|
|
27
40
|
"publishConfig": {
|
|
28
41
|
"access": "public"
|
|
29
42
|
},
|
|
30
43
|
"dependencies": {
|
|
31
|
-
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
},
|
|
34
|
-
"peerDependencies": {
|
|
44
|
+
"ejs": "^3.1.10"
|
|
35
45
|
},
|
|
36
46
|
"engines": {
|
|
37
|
-
"node": ">=18"
|
|
47
|
+
"node": ">=18.18"
|
|
38
48
|
}
|
|
39
49
|
}
|