@nera-static/starter-business 1.1.1 → 1.2.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/CHANGELOG.md +15 -0
- package/README.md +16 -4
- package/config/contact-form.yaml +2 -2
- package/package.json +28 -21
- package/theme/views/partials/contact-form.pug +1 -1
- package/theme/views/partials/footer-extra.pug +0 -1
- package/theme/views/vendor/plugin-contact-form/contact-form.pug +17 -17
- package/theme/views/vendor/plugin-navigation/helper/mixins.pug +2 -2
- package/theme/views/vendor/plugin-navigation/helper/setup.pug +24 -24
- package/theme/views/vendor/plugin-social-media-links/social-media-links.pug +1 -1
- package/theme/views/vendor/plugin-structured-data/index.pug +1 -1
- package/theme/assets/js/contact-form.js +0 -241
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.2.0] - 2026-12-03
|
|
9
|
+
|
|
10
|
+
A new site gets `@nera-static/theme-business` 2 and the current majors of the plugins. It looks and reads the same as one from 1.1.1. A site made from an earlier version is not affected: a starter has no update path (to move such a site to the new majors, follow the Migration sections of theme-business 2.0.0 and of the plugins named below).
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- `@nera-static/theme-business` ^2.0.0 (was ^1.0.2), `@nera-static/plugin-contact-form` ^2.0.0 (was ^1.1.1), `@nera-static/plugin-social-media-links` ^3.0.0 (was ^2.3.0) and `@nera-static/plugin-structured-data` ^2.0.0 (was ^1.1.0). The other plugins are raised to their current releases: `plugin-images` ^1.1.0, `plugin-navigation` ^3.2.0, `plugin-sitemap` ^1.2.0.
|
|
15
|
+
- The contact form's script comes from plugin-contact-form, which copies it to `public/_nera/contact-form.js` on every build: the form's template loads `/_nera/contact-form.js` (was `/js/contact-form.js`), so a site always runs the script of the plugin version it has installed. The comment in `config/contact-form.yaml` and the README name the new place.
|
|
16
|
+
- The published templates in `theme/views/vendor/` are those of the plugin versions above (plugin-contact-form, plugin-navigation, plugin-social-media-links and plugin-structured-data changed, in formatting, comments and the script path; the rendered pages are otherwise the same).
|
|
17
|
+
- Internal: `npm run lint` runs `nera-stan`, the tests use `@nera-static/test-utils`, and `npm test` runs the suite once (`npm run test:watch` watches). The README has a Development section.
|
|
18
|
+
|
|
19
|
+
### Removed
|
|
20
|
+
|
|
21
|
+
- `theme/assets/js/contact-form.js`, the copy of plugin-contact-form 1.x's script.
|
|
22
|
+
|
|
8
23
|
## [1.1.1] - 2026-11-23
|
|
9
24
|
|
|
10
25
|
### Changed
|
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
A ready-to-edit site for a small business, built with the
|
|
9
9
|
[Nera](https://github.com/seebaermichi/nera) static site generator on
|
|
10
|
-
[`@nera-static/theme-business`](https://www.npmjs.com/package/@nera-static/theme-business)
|
|
11
|
-
home with a hero image and service cards, about, services, opening hours, a
|
|
10
|
+
[`@nera-static/theme-business`](https://www.npmjs.com/package/@nera-static/theme-business)
|
|
11
|
+
2.x: home with a hero image and service cards, about, services, opening hours, a
|
|
12
12
|
contact form, navigation, responsive images, social links, a sitemap,
|
|
13
13
|
schema.org structured data and imprint and privacy placeholders. One small
|
|
14
14
|
script for the contact form, no third-party requests; a fresh site passes `nera build --check` and
|
|
@@ -39,8 +39,9 @@ language gets a copy of the English `translations:` entry to translate.
|
|
|
39
39
|
runs that plugin last
|
|
40
40
|
- `theme/views/partials/`: the theme's seams, filled with the plugins' output
|
|
41
41
|
- `theme/views/vendor/`: the plugins' published templates
|
|
42
|
-
-
|
|
43
|
-
|
|
42
|
+
- the contact form's script, which opens the visitor's own mail program (the
|
|
43
|
+
form has no backend): plugin-contact-form writes it to
|
|
44
|
+
`/_nera/contact-form.js` on every build, and its template loads it from there
|
|
44
45
|
- `theme/assets/images/hero.jpg`: the home page's hero image
|
|
45
46
|
- plugins: contact-form, images, navigation, social-media-links, sitemap,
|
|
46
47
|
structured-data
|
|
@@ -82,6 +83,17 @@ Replace the copied `de:` entry in `config/app.yaml` with:
|
|
|
82
83
|
contact_consent: 'Beim Senden öffnet sich Ihr eigenes E-Mail-Programm; diese Website versendet nichts. Mehr dazu in der <a href="/privacy.html">Datenschutzerklärung</a>.'
|
|
83
84
|
```
|
|
84
85
|
|
|
86
|
+
## Development
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npx vitest run # scaffolds sites from this repo and builds them with the real CLI
|
|
90
|
+
npm run lint # nera-stan: code, Pug and structure
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The published templates in `theme/views/vendor/` are the installed plugins'
|
|
94
|
+
own, unedited; a test fails when a plugin update changes one, until it is
|
|
95
|
+
published again (`npx nera-<name> --force`).
|
|
96
|
+
|
|
85
97
|
## Requirements
|
|
86
98
|
|
|
87
99
|
- `@nera-static/nera` 1.11.0 or later, with `@nera-static/core` 4.15.0 or
|
package/config/contact-form.yaml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# The form has no backend: on submit the client script
|
|
2
|
-
# (
|
|
3
|
-
# the message filled in. Every text is a translation key (config/app.yaml).
|
|
2
|
+
# (/_nera/contact-form.js, which every build writes) opens the visitor's own
|
|
3
|
+
# mail client with the message filled in. Every text is a translation key (config/app.yaml).
|
|
4
4
|
#
|
|
5
5
|
# A placeholder: replace it with your own address before you deploy. It is
|
|
6
6
|
# never printed as readable text.
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nera-static/starter-business",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A ready-to-edit Nera site for a small business on @nera-static/theme-business: home, about, services, opening hours, a contact form, navigation, responsive images, social links, a sitemap, schema.org structured data and imprint and privacy placeholders. One small script for the contact form.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"lint": "
|
|
8
|
-
"test": "vitest",
|
|
9
|
-
"prepare": "husky"
|
|
7
|
+
"lint": "nera-stan",
|
|
8
|
+
"test": "vitest run",
|
|
9
|
+
"prepare": "husky",
|
|
10
|
+
"test:watch": "vitest"
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
12
13
|
"config",
|
|
@@ -21,12 +22,6 @@
|
|
|
21
22
|
"starter",
|
|
22
23
|
"business"
|
|
23
24
|
],
|
|
24
|
-
"nera": {
|
|
25
|
-
"starter": {
|
|
26
|
-
"label": "Business",
|
|
27
|
-
"description": "A ready-to-edit Nera site for a small business on @nera-static/theme-business: home, about, services, opening hours, a contact form, navigation, responsive images, social links, a sitemap, schema.org structured data and imprint and privacy placeholders. One small script for the contact form."
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
25
|
"author": "Michael Becker",
|
|
31
26
|
"license": "MIT",
|
|
32
27
|
"repository": {
|
|
@@ -43,20 +38,32 @@
|
|
|
43
38
|
"engines": {
|
|
44
39
|
"node": ">=22.12.0"
|
|
45
40
|
},
|
|
41
|
+
"nera": {
|
|
42
|
+
"starter": {
|
|
43
|
+
"label": "Business",
|
|
44
|
+
"description": "A ready-to-edit Nera site for a small business on @nera-static/theme-business: home, about, services, opening hours, a contact form, navigation, responsive images, social links, a sitemap, schema.org structured data and imprint and privacy placeholders. One small script for the contact form."
|
|
45
|
+
}
|
|
46
|
+
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@nera-static/plugin-contact-form": "^
|
|
48
|
-
"@nera-static/plugin-images": "^1.0
|
|
49
|
-
"@nera-static/plugin-navigation": "^3.
|
|
50
|
-
"@nera-static/plugin-sitemap": "^1.
|
|
51
|
-
"@nera-static/plugin-social-media-links": "^
|
|
52
|
-
"@nera-static/plugin-structured-data": "^
|
|
53
|
-
"@nera-static/theme-business": "^
|
|
48
|
+
"@nera-static/plugin-contact-form": "^2.0.0",
|
|
49
|
+
"@nera-static/plugin-images": "^1.1.0",
|
|
50
|
+
"@nera-static/plugin-navigation": "^3.2.0",
|
|
51
|
+
"@nera-static/plugin-sitemap": "^1.2.0",
|
|
52
|
+
"@nera-static/plugin-social-media-links": "^3.0.0",
|
|
53
|
+
"@nera-static/plugin-structured-data": "^2.0.0",
|
|
54
|
+
"@nera-static/theme-business": "^2.0.0"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@nera-static/nera": "^1.
|
|
57
|
-
"
|
|
57
|
+
"@nera-static/nera": "^1.31.0",
|
|
58
|
+
"@nera-static/plugin-utils": "^1.11.0",
|
|
59
|
+
"@nera-static/stan": "^1.3.0",
|
|
60
|
+
"@nera-static/test-utils": "^1.1.0",
|
|
58
61
|
"husky": "^9.1.7",
|
|
59
|
-
"vitest": "^5.1.1"
|
|
60
|
-
|
|
62
|
+
"vitest": "^5.1.1"
|
|
63
|
+
},
|
|
64
|
+
"nera-stan": {
|
|
65
|
+
"skip": {
|
|
66
|
+
"structure/starter-tree": "the theme's seams include plugin views from /vendor/<plugin>/, which core resolves only inside the site, so the starter ships them as published by each plugin (npx nera-<name>); the label, files and First steps parts are pinned by test/package.test.js"
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
69
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
//- Contact form partial (plugin-contact-form).
|
|
2
2
|
//-
|
|
3
|
-
//- On submit the
|
|
4
|
-
//- `
|
|
5
|
-
//- `mailto:` link and opens the visitor's mail client.
|
|
6
|
-
//- nothing is submitted over the network.
|
|
3
|
+
//- On submit the plugin's browser script — copied to
|
|
4
|
+
//- `public/_nera/contact-form.js` by every build and loaded at the foot of
|
|
5
|
+
//- this file — builds a `mailto:` link and opens the visitor's mail client.
|
|
6
|
+
//- There is no backend and nothing is submitted over the network.
|
|
7
7
|
//-
|
|
8
8
|
//- TRANSLATIONS: every user-facing string (labels, placeholders, subject,
|
|
9
9
|
//- messages, checkbox Yes/No) is a translation key resolved here through the
|
|
@@ -46,7 +46,7 @@ if cf && cf.fields && cf.fields.length > 0
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
var clientConfigJson = JSON.stringify(clientConfig).replace(/</g, '\\u003c')
|
|
49
|
-
script(type=
|
|
49
|
+
script(type='application/json', data-contact-config)!= clientConfigJson
|
|
50
50
|
|
|
51
51
|
//- The recipient is carried on a data attribute, never printed as text.
|
|
52
52
|
//- In `entities` mode every character is an HTML numeric entity,
|
|
@@ -70,7 +70,7 @@ if cf && cf.fields && cf.fields.length > 0
|
|
|
70
70
|
if field.type === 'checkbox'
|
|
71
71
|
label.contact-form__label.contact-form__label--checkbox(for=fieldId)
|
|
72
72
|
input.contact-form__input.contact-form__input--checkbox(
|
|
73
|
-
type=
|
|
73
|
+
type='checkbox',
|
|
74
74
|
id=fieldId,
|
|
75
75
|
name=field.name,
|
|
76
76
|
data-contact-field,
|
|
@@ -98,17 +98,17 @@ if cf && cf.fields && cf.fields.length > 0
|
|
|
98
98
|
required=field.required
|
|
99
99
|
)
|
|
100
100
|
if field.required
|
|
101
|
-
option(value=
|
|
101
|
+
option(value='', disabled, selected) …
|
|
102
102
|
each option in field.options
|
|
103
103
|
option(value=option.value) #{tr(option.label)}
|
|
104
104
|
else if field.type === 'radio'
|
|
105
105
|
span.contact-form__label #{fieldLabel}
|
|
106
|
-
.contact-form__options(role=
|
|
106
|
+
.contact-form__options(role='radiogroup', aria-label=fieldLabel)
|
|
107
107
|
each option, i in field.options
|
|
108
108
|
- var optId = fieldId + '-' + i
|
|
109
109
|
label.contact-form__label.contact-form__label--radio(for=optId)
|
|
110
110
|
input.contact-form__input.contact-form__input--radio(
|
|
111
|
-
type=
|
|
111
|
+
type='radio',
|
|
112
112
|
id=optId,
|
|
113
113
|
name=field.name,
|
|
114
114
|
value=option.value,
|
|
@@ -141,24 +141,24 @@ if cf && cf.fields && cf.fields.length > 0
|
|
|
141
141
|
//- leave it blank, or a bot reading the HTML would simply skip it. Real
|
|
142
142
|
//- users never read it: the container is `aria-hidden` and moved
|
|
143
143
|
//- off-screen by the inline style, which also guarantees it stays hidden
|
|
144
|
-
//- even if the site ships no CSS for it. `autocomplete=
|
|
144
|
+
//- even if the site ships no CSS for it. `autocomplete='off'` stops a
|
|
145
145
|
//- browser from autofilling it for a real visitor (a false positive).
|
|
146
|
-
.contact-form__decoy(aria-hidden=
|
|
146
|
+
.contact-form__decoy(aria-hidden='true', style='position:absolute;left:-9999px;top:auto;width:1px;height:1px;overflow:hidden')
|
|
147
147
|
label(for='contact-' + cf.honeypot)= cf.honeypot
|
|
148
148
|
input(
|
|
149
|
-
type=
|
|
149
|
+
type='text',
|
|
150
150
|
id='contact-' + cf.honeypot,
|
|
151
151
|
name=cf.honeypot,
|
|
152
|
-
tabindex=
|
|
153
|
-
autocomplete=
|
|
152
|
+
tabindex='-1',
|
|
153
|
+
autocomplete='off'
|
|
154
154
|
)
|
|
155
155
|
|
|
156
156
|
if cf.consentText
|
|
157
157
|
//- Site-owner authored HTML (see config), resolved per language.
|
|
158
158
|
.contact-form__consent !{tr(cf.consentText)}
|
|
159
159
|
|
|
160
|
-
.contact-form__status(role=
|
|
160
|
+
.contact-form__status(role='alert', aria-live='polite', data-contact-status)
|
|
161
161
|
|
|
162
|
-
button.contact-form__submit(type=
|
|
162
|
+
button.contact-form__submit(type='submit') #{tr(cf.submitLabel)}
|
|
163
163
|
|
|
164
|
-
script(src=
|
|
164
|
+
script(src='/_nera/contact-form.js')
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
mixin link(item, activeClass, activePathClass)
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
- const navBlock = (app.nav && app.nav.navClass) || 'nav'
|
|
3
|
+
a(href=item.href, class=[`${navBlock}__link`, activeClass, activePathClass]) #{ item.name }
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
each item, index in elements || app.nav.elements || []
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
2
|
+
- const isActive = item.href === meta.fullPath
|
|
3
|
+
//- Class names come from config/navigation.yaml via app.nav, falling back to
|
|
4
|
+
//- the BEM defaults so an unconfigured site renders exactly as before.
|
|
5
|
+
- const activeClass = isActive ? ((app.nav && app.nav.activeClass) || 'nav__link--active') : ''
|
|
6
|
+
//- The directory that counts as the site root. Defaults to '/', but a site
|
|
7
|
+
//- that prefixes its pages — a language prefix such as /de, a subdirectory
|
|
8
|
+
//- deployment — passes its own through the mixin's `rootPath` argument.
|
|
9
|
+
- const navRoot = (typeof rootPath !== 'undefined' && rootPath) || '/'
|
|
10
|
+
//- The section an entry stands for: the directory its own href lives in.
|
|
11
|
+
- const itemDir = item.href.replace(/\/[^/]*$/, '') || '/'
|
|
12
|
+
//- Only an entry pointing at a directory's index (`/about/index.html` or
|
|
13
|
+
//- `/about/`) stands for a section. A link to a single page such as
|
|
14
|
+
//- `/about/me.html` would otherwise be marked on every other page in /about,
|
|
15
|
+
//- the section index included.
|
|
16
|
+
- const isSection = /\/(index\.html)?$/.test(item.href)
|
|
17
|
+
//- An entry is an ancestor of the current page when that page sits inside
|
|
18
|
+
//- the entry's section — either directly in it, or further down. Asking the
|
|
19
|
+
//- reverse, whether the entry sits inside the current page's directory,
|
|
20
|
+
//- holds only for pages exactly one level deep: a page at
|
|
21
|
+
//- /tutorials/tags/links.html would not match /tutorials/index.html.
|
|
22
|
+
//- Entries living in the root are never ancestors, since every page is
|
|
23
|
+
//- inside the root and Home would otherwise be marked on every page.
|
|
24
|
+
- const isParent = isSection && itemDir !== navRoot && (meta.dirname === itemDir || meta.dirname.indexOf(itemDir + '/') === 0)
|
|
25
|
+
- const activePathClass = !isActive && isParent ? ((app.nav && app.nav.activePathClass) || 'nav__link--active-path') : ''
|
|
@@ -5,7 +5,7 @@ if app.socialMediaLinks && app.socialMediaLinks.length > 0
|
|
|
5
5
|
li.social-media-links__item
|
|
6
6
|
//- `open_in_new_tab: false` drops the target; pug omits an undefined attribute.
|
|
7
7
|
- const linkTarget = app.socialMediaLinksNewTab === false ? undefined : '_blank'
|
|
8
|
-
a.social-media-links__link(href=link.href, title=link.name, target=linkTarget, rel=
|
|
8
|
+
a.social-media-links__link(href=link.href, title=link.name, target=linkTarget, rel='noopener noreferrer')
|
|
9
9
|
//- Icons are escaped by default. Set `icon_raw: true`
|
|
10
10
|
//- on an entry to inject the value as HTML — needed
|
|
11
11
|
//- for icon-font markup or an inline SVG, and an
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
//- (no `<`, `>` or `&` left in it), so the unescaped `!=` cannot end the
|
|
5
5
|
//- script element. Pages without it get no tag at all.
|
|
6
6
|
if meta && meta.structuredData
|
|
7
|
-
script(type=
|
|
7
|
+
script(type='application/ld+json')!= meta.structuredData
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
// Client script for plugin-contact-form. Published to assets/js/contact-form.js
|
|
2
|
-
// and loaded by the contact-form template. It is pure behavior: it contains no
|
|
3
|
-
// user-facing text and no configuration. Everything it needs — messages,
|
|
4
|
-
// checkbox labels, the subject, the honeypot field name, the error class — is
|
|
5
|
-
// read at runtime from the inert JSON block the template renders
|
|
6
|
-
// (`[data-contact-config]`), so all of it stays configurable and translatable
|
|
7
|
-
// from YAML. On submit it builds a `mailto:` link and hands it to the mail
|
|
8
|
-
// client; it makes no network request.
|
|
9
|
-
//
|
|
10
|
-
// The only literals here are the structural selectors that form the documented
|
|
11
|
-
// contract with the template (`data-contact-*`) and the email-shape regex —
|
|
12
|
-
// none of them is text a site owner or translator would change.
|
|
13
|
-
//
|
|
14
|
-
// `document` and `window` are referenced as free variables so the test suite
|
|
15
|
-
// can run the script with its own stubs (`new Function('document', 'window', …)`)
|
|
16
|
-
// — in the browser they resolve to the real globals.
|
|
17
|
-
|
|
18
|
-
// Deliberately permissive — the goal is to catch obvious typos, not to be an
|
|
19
|
-
// authority on RFC 5322. The mail client is the real validator.
|
|
20
|
-
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
|
21
|
-
|
|
22
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
23
|
-
document.querySelectorAll('[data-contact-form]').forEach(setupForm)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
function setupForm(form) {
|
|
27
|
-
const config = readConfig(form)
|
|
28
|
-
const status = form.querySelector('[data-contact-status]')
|
|
29
|
-
|
|
30
|
-
form.addEventListener('submit', (event) => {
|
|
31
|
-
event.preventDefault()
|
|
32
|
-
|
|
33
|
-
// Honeypot: a real visitor never sees or fills this field. A value here
|
|
34
|
-
// means a bot, so drop the submission silently — no error, no mailto —
|
|
35
|
-
// to give the bot no signal that it was caught. Nothing labels the trap
|
|
36
|
-
// in the page; it is identified structurally, as the one named control
|
|
37
|
-
// that carries no `data-contact-field` marker (real fields all do) and
|
|
38
|
-
// is not a button.
|
|
39
|
-
const trap = Array.from(form.elements).find(
|
|
40
|
-
(element) =>
|
|
41
|
-
element.name &&
|
|
42
|
-
!element.hasAttribute('data-contact-field') &&
|
|
43
|
-
element.type !== 'submit' &&
|
|
44
|
-
element.type !== 'button'
|
|
45
|
-
)
|
|
46
|
-
if (trap && trap.value.trim() !== '') {
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
clearErrors(form, status, config.errorClass)
|
|
51
|
-
|
|
52
|
-
const fields = Array.from(form.querySelectorAll('[data-contact-field]'))
|
|
53
|
-
const messages = config.messages || {}
|
|
54
|
-
|
|
55
|
-
const missing = findMissingRequired(fields)
|
|
56
|
-
if (missing.length > 0) {
|
|
57
|
-
showError(status, messages.required, missing, config.errorClass)
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const invalidEmail = fields.find(isInvalidEmail)
|
|
62
|
-
if (invalidEmail) {
|
|
63
|
-
showError(status, messages.email, [invalidEmail], config.errorClass)
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const recipient = readRecipient(form)
|
|
68
|
-
if (!recipient) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const body = fields
|
|
73
|
-
.map((field) => collectValue(field, config.booleanLabels || {}))
|
|
74
|
-
.filter((entry) => entry !== null)
|
|
75
|
-
.map((entry) => `${entry.label}: ${entry.value}`)
|
|
76
|
-
.join('\r\n')
|
|
77
|
-
|
|
78
|
-
const mailto =
|
|
79
|
-
'mailto:' +
|
|
80
|
-
recipient +
|
|
81
|
-
'?subject=' +
|
|
82
|
-
encodeURIComponent(config.subject || '') +
|
|
83
|
-
'&body=' +
|
|
84
|
-
encodeURIComponent(body)
|
|
85
|
-
|
|
86
|
-
// mailto: URLs are capped in practice (~2000 chars) by the OS/mail
|
|
87
|
-
// client; a very long message may be truncated on the way in.
|
|
88
|
-
window.location.href = mailto
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// The config the template rendered. An absent or malformed block yields an
|
|
93
|
-
// empty object rather than an exception, so a broken custom template degrades
|
|
94
|
-
// instead of throwing.
|
|
95
|
-
function readConfig(form) {
|
|
96
|
-
const element = form.querySelector('[data-contact-config]')
|
|
97
|
-
if (!element) {
|
|
98
|
-
return {}
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
return JSON.parse(element.textContent) || {}
|
|
102
|
-
} catch {
|
|
103
|
-
return {}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// The address, reassembled from whichever obfuscated form the template emitted.
|
|
108
|
-
function readRecipient(form) {
|
|
109
|
-
const codesEl = form.querySelector('[data-contact-recipient-codes]')
|
|
110
|
-
if (codesEl) {
|
|
111
|
-
try {
|
|
112
|
-
const codes = JSON.parse(
|
|
113
|
-
codesEl.getAttribute('data-contact-recipient-codes')
|
|
114
|
-
)
|
|
115
|
-
if (Array.isArray(codes)) {
|
|
116
|
-
return String.fromCharCode.apply(null, codes)
|
|
117
|
-
}
|
|
118
|
-
} catch {
|
|
119
|
-
return ''
|
|
120
|
-
}
|
|
121
|
-
return ''
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const entitiesEl = form.querySelector('[data-contact-recipient]')
|
|
125
|
-
if (entitiesEl) {
|
|
126
|
-
// The HTML parser already decoded the numeric entities in the
|
|
127
|
-
// attribute, so this is the plain address.
|
|
128
|
-
return entitiesEl.getAttribute('data-contact-recipient') || ''
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return ''
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function fieldType(field) {
|
|
135
|
-
return (field.getAttribute('type') || field.tagName || '').toLowerCase()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Returns `{ label, value }` for the email body, or null for a control that
|
|
139
|
-
// contributes nothing (an unchecked radio in a group).
|
|
140
|
-
function collectValue(field, booleanLabels) {
|
|
141
|
-
const label = field.getAttribute('data-contact-label') || field.name || ''
|
|
142
|
-
const type = fieldType(field)
|
|
143
|
-
|
|
144
|
-
if (type === 'checkbox') {
|
|
145
|
-
const value = field.checked
|
|
146
|
-
? booleanLabels.checked
|
|
147
|
-
: booleanLabels.unchecked
|
|
148
|
-
return { label, value: value || '' }
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (type === 'radio') {
|
|
152
|
-
if (!field.checked) {
|
|
153
|
-
return null
|
|
154
|
-
}
|
|
155
|
-
return { label, value: field.value }
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return { label, value: field.value }
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function findMissingRequired(fields) {
|
|
162
|
-
const missing = []
|
|
163
|
-
const seenRadioGroups = {}
|
|
164
|
-
|
|
165
|
-
fields.forEach((field) => {
|
|
166
|
-
if (!field.hasAttribute('required')) {
|
|
167
|
-
return
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const type = fieldType(field)
|
|
171
|
-
|
|
172
|
-
if (type === 'radio') {
|
|
173
|
-
const name = field.name
|
|
174
|
-
if (name in seenRadioGroups) {
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
const checked = fields.some(
|
|
178
|
-
(other) => other.name === name && other.checked
|
|
179
|
-
)
|
|
180
|
-
seenRadioGroups[name] = checked
|
|
181
|
-
if (!checked) {
|
|
182
|
-
missing.push(field)
|
|
183
|
-
}
|
|
184
|
-
return
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (type === 'checkbox') {
|
|
188
|
-
if (!field.checked) {
|
|
189
|
-
missing.push(field)
|
|
190
|
-
}
|
|
191
|
-
return
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (field.value.trim() === '') {
|
|
195
|
-
missing.push(field)
|
|
196
|
-
}
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
return missing
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function isInvalidEmail(field) {
|
|
203
|
-
if (fieldType(field) !== 'email') {
|
|
204
|
-
return false
|
|
205
|
-
}
|
|
206
|
-
const value = field.value.trim()
|
|
207
|
-
// Emptiness is the required check's job — an optional empty email is fine.
|
|
208
|
-
if (value === '') {
|
|
209
|
-
return false
|
|
210
|
-
}
|
|
211
|
-
return !EMAIL_PATTERN.test(value)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function showError(status, message, fields, errorClass) {
|
|
215
|
-
if (status) {
|
|
216
|
-
status.textContent = message || ''
|
|
217
|
-
}
|
|
218
|
-
fields.forEach((field) => {
|
|
219
|
-
if (errorClass) {
|
|
220
|
-
field.classList.add(errorClass)
|
|
221
|
-
}
|
|
222
|
-
field.setAttribute('aria-invalid', 'true')
|
|
223
|
-
})
|
|
224
|
-
const first = fields[0]
|
|
225
|
-
if (first && typeof first.focus === 'function') {
|
|
226
|
-
first.focus()
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function clearErrors(form, status, errorClass) {
|
|
231
|
-
if (status) {
|
|
232
|
-
status.textContent = ''
|
|
233
|
-
}
|
|
234
|
-
if (!errorClass) {
|
|
235
|
-
return
|
|
236
|
-
}
|
|
237
|
-
form.querySelectorAll('.' + errorClass).forEach((field) => {
|
|
238
|
-
field.classList.remove(errorClass)
|
|
239
|
-
field.removeAttribute('aria-invalid')
|
|
240
|
-
})
|
|
241
|
-
}
|