44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
|
import {basename} from './functions';
|
||
|
import each from './form-elements-each';
|
||
|
import Doc from './doc';
|
||
|
|
||
|
// Just kill form submission
|
||
|
Doc.getByTag('form')[0].onsubmit = function (e) {
|
||
|
e.preventDefault();
|
||
|
e.stopPropagation();
|
||
|
|
||
|
console.log(`Form 'submit' event fired.`);
|
||
|
|
||
|
return false;
|
||
|
};
|
||
|
|
||
|
// What polyfills did we have to load?
|
||
|
const $polyfillPattern = /\/polyfills\//;
|
||
|
const scriptList = Doc.scripts().filter(file => {
|
||
|
return $polyfillPattern.test(file.getAttribute('src'))
|
||
|
});
|
||
|
if (scriptList.length > 0) {
|
||
|
const polyfillList = [];
|
||
|
scriptList.forEach(file => {
|
||
|
const src = file.getAttribute('src');
|
||
|
const name = basename(src).replace('.js', '')
|
||
|
.replace('.min', '');
|
||
|
|
||
|
const el = `<li>${name}</li>`;
|
||
|
|
||
|
if (!polyfillList.includes(el)) {
|
||
|
polyfillList.push(el);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
const tag = Doc.getById('polyfills-loaded');
|
||
|
tag.innerHTML = '<h3>Polyfills loaded by this browser:</h3>';
|
||
|
tag.innerHTML += `<ul>${polyfillList.join("\n")}</ul>`;
|
||
|
}
|
||
|
|
||
|
// Get each form field's html and syntax highlight it
|
||
|
Doc.qsa('.form-field').forEach(each);
|
||
|
|
||
|
|
||
|
|