Skip to content

Instantly share code, notes, and snippets.

@matijs
Forked from adactio/postforms.js
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matijs/9429123 to your computer and use it in GitHub Desktop.
Save matijs/9429123 to your computer and use it in GitHub Desktop.
/*
Show a progress element for any form submission via POST.
Prevent the form element from being submitted twice.
*/
(function ( win, doc ) {
'use strict';
if ( !win.addEventListener ) {
// doesn't cut the mustard.
return;
}
var submitting = false;
function checkForm( event ) {
if ( submitting ) {
event.preventDefault();
}
else {
if ( event.target.method === 'post' ) {
submitting = true;
event.target.appendChild( doc.createElement('progress') );
}
}
}
doc.documentElement.addEventListener( 'submit', checkForm, false );
}( this, this.document ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment