Migrate JS to ES6
This commit is contained in:
17
package-lock.json
generated
17
package-lock.json
generated
@@ -805,6 +805,23 @@
|
|||||||
"semver": "^5.5.0"
|
"semver": "^5.5.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@babel/runtime": {
|
||||||
|
"version": "7.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.6.2.tgz",
|
||||||
|
"integrity": "sha512-EXxN64agfUqqIGeEjI5dL5z0Sw0ZwWo1mLTi4mQowCZ42O59b7DRpZAnTC6OqdF28wMBMFKNb/4uFGrVaigSpg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"regenerator-runtime": "^0.13.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"regenerator-runtime": {
|
||||||
|
"version": "0.13.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz",
|
||||||
|
"integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"@babel/template": {
|
"@babel/template": {
|
||||||
"version": "7.6.0",
|
"version": "7.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.6.0.tgz",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"author": "Daniel Vassallo",
|
"author": "Daniel Vassallo",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/runtime": "^7.4.5",
|
||||||
"@babel/cli": "^7.4.4",
|
"@babel/cli": "^7.4.4",
|
||||||
"@babel/core": "^7.4.5",
|
"@babel/core": "^7.4.5",
|
||||||
"@babel/plugin-transform-runtime": "^7.4.4",
|
"@babel/plugin-transform-runtime": "^7.4.4",
|
||||||
|
|||||||
45
src/index.js
45
src/index.js
@@ -1,32 +1,14 @@
|
|||||||
import './style.css'
|
import './style.css'
|
||||||
|
|
||||||
var serialize = function (form) {
|
|
||||||
var serialized = ''
|
|
||||||
|
|
||||||
for (var i = 0; i < form.elements.length; i++) {
|
|
||||||
|
|
||||||
var field = form.elements[i]
|
|
||||||
|
|
||||||
if (!field.name || field.disabled || field.type === 'file' || field.type === 'reset' || field.type === 'submit' || field.type === 'button') continue
|
|
||||||
|
|
||||||
if ((field.type !== 'checkbox' && field.type !== 'radio') || field.checked) {
|
|
||||||
serialized += '&' + encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.displayMailChimpStatus = function (data) {
|
window.displayMailChimpStatus = function (data) {
|
||||||
if (!data.result || !data.msg) return
|
if (!data.result || !data.msg) return
|
||||||
|
|
||||||
var mcStatus = document.querySelector('.mc-status')
|
const mcStatus = document.querySelector('.mc-status')
|
||||||
|
|
||||||
if (!mcStatus) return
|
if (!mcStatus) return
|
||||||
|
|
||||||
mcStatus.innerHTML = data.msg
|
mcStatus.innerHTML = data.msg
|
||||||
|
|
||||||
//mcStatus.addAttribute('tabindex', '-1')
|
|
||||||
mcStatus.focus()
|
mcStatus.focus()
|
||||||
|
|
||||||
mcStatus.classList.remove('hidden')
|
mcStatus.classList.remove('hidden')
|
||||||
@@ -41,15 +23,32 @@ window.displayMailChimpStatus = function (data) {
|
|||||||
mcStatus.classList.add('mc-success')
|
mcStatus.classList.add('mc-success')
|
||||||
}
|
}
|
||||||
|
|
||||||
var submitMailChimpForm = function (form) {
|
const serialize = function (form) {
|
||||||
var url = form.getAttribute('action')
|
let serialized = ''
|
||||||
|
|
||||||
|
for (let i = 0; i < form.elements.length; i++) {
|
||||||
|
|
||||||
|
const field = form.elements[i]
|
||||||
|
|
||||||
|
if (!field.name || field.disabled || field.type === 'file' || field.type === 'reset' || field.type === 'submit' || field.type === 'button') continue
|
||||||
|
|
||||||
|
if ((field.type !== 'checkbox' && field.type !== 'radio') || field.checked) {
|
||||||
|
serialized += '&' + encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitMailChimpForm = function (form) {
|
||||||
|
let url = form.getAttribute('action')
|
||||||
url = url.replace('/post?u=', '/post-json?u=')
|
url = url.replace('/post?u=', '/post-json?u=')
|
||||||
url += serialize(form) + '&c=displayMailChimpStatus'
|
url += serialize(form) + '&c=displayMailChimpStatus'
|
||||||
|
|
||||||
var script = window.document.createElement('script')
|
const script = window.document.createElement('script')
|
||||||
script.src = url
|
script.src = url
|
||||||
|
|
||||||
var ref = window.document.getElementsByTagName('script')[0]
|
const ref = window.document.getElementsByTagName('script')[0]
|
||||||
ref.parentNode.insertBefore(script, ref)
|
ref.parentNode.insertBefore(script, ref)
|
||||||
|
|
||||||
script.onload = function () {
|
script.onload = function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user