Refactoring. Client has no global names anymore, and no inline scripts

This commit is contained in:
Adrian Amaglio 2020-12-26 14:03:13 +01:00
parent 5b98424bc6
commit be61601950
3 changed files with 18 additions and 8 deletions

View File

@ -1,3 +1,6 @@
/* Executed after page loading */
(function () {
class JeanCloudContactFormNotifier {
constructor (theme, messageContainer) {
/* Choose the theme */
@ -112,7 +115,6 @@ function jeanCloudContactFormIntercept (formId, notifier) {
}
}
(function () {
/* Get the current js file location */
const path = (document.currentScript.src[-1] == '/' ? document.currentScript.src : document.currentScript.src.replace(/\/[^\/]*$/, ''))
@ -125,6 +127,15 @@ function jeanCloudContactFormIntercept (formId, notifier) {
link.integrity = 'sha384-D12RSMaIURTgZZljhdQqYlQzgEfXvOFwtiqzkWnNcDbKFwMWXcmsCRFO5BNii0MB'
// cat style.css | openssl dgst -sha384 -binary | openssl base64 -A
document.head.appendChild(link);
/* Load the targeted forms */
var configs = document.getElementsByClassName('contact-form-config')
for (var i=0; i<configs.length; i++) {
var formId = configs[i].getAttribute('form-id')
var theme = configs[i].getAttribute('notify-theme')
jeanCloudContactFormIntercept(formId, new JeanCloudContactFormNotifier(theme))
}
var contactMailerPageLoadedTime = Date.now()
})()
var contactMailerPageLoadedTime = Date.now()

View File

@ -1,6 +1,6 @@
{
"name": "jean-cloud-contact-mailer-client",
"version": "1.1.5",
"version": "1.1.6",
"description": "",
"main": "index.js",
"scripts": {

View File

@ -6,9 +6,9 @@
</head>
<body>
<div id="contact-mailer-message"></div>
<form action="http://localhost:8080/submit" method="POST" id="contact-mailer-form">
<form action="/api/submit" method="POST" id="contact-mailer-form">
<noscript>Les protections anti-spam, nécéssitent lutilisation de javascript. Rien dintrusif normalement.</noscript>
<input type="hidden" name="token" value="PK8gQHDx9VoJ7yuEhbj5iCZkcUOAqTYlRSN14XFtdfr3LBs0zn" />
<input type="hidden" name="token" value="5NwE8KOzhinBLVloZrvfb71WJeQ6sXc4xgC0AqFPDHGMjIdmUk" />
<div>
<label for="nom">Votre nom&nbsp;:</label>
<input type="text" name="nom" required="required"/>
@ -27,11 +27,10 @@
</div>
<div>
<label for="objet">Votre message&nbsp;:</label>
<textarea name="message" required="required"></textarea>
<textarea name="message"></textarea>
</div>
<input type="submit" />
</form>
<script src="./client/index.js"></script>
<script> jeanCloudContactFormIntercept ('contact-mailer-form', new JeanCloudContactFormNotifier()) </script>
<script class="contact-form-config" form-id="contact-mailer-form" notify-theme="dark" src="./client/index.js"></script>
</body>
</html>