Created
August 23, 2012 21:43
-
-
Save mpezzi/3442264 to your computer and use it in GitHub Desktop.
Double Form Submit Preventer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* jQuery Double Form Submit Preventer Plugin by M. Pezzi | |
* Version: 1.0-alpha (08/23/12) | |
* Dual licensed under the MIT and GPL licences: | |
* http://www.opensource.org/licenses/mit-license.php | |
* http://www.gnu.org/licenses/gpl.html | |
* Requires: jQuery v1.4.2 or later | |
*/ | |
;(function($){ | |
$.fn.disformer = function(options) { | |
return this.each(function(){ | |
var self = $(this), o = $.extend({}, $.fn.disformer.defaults, options), | |
// Elements. | |
$form = self.parents('form'); | |
$form.submit(function(){ | |
$form | |
.css('position', 'relative') | |
.wrapInner('<div class="disformer-wrapper" />') | |
.find('.disformer-wrapper') | |
.delay(o.delay) | |
.animate({ opacity: o.opacity }, function(){ | |
$('<div class="disformer-loader">').hide().appendTo($form) | |
.html(o.text) | |
.css({ | |
position: 'absolute', | |
top: '50%', | |
width: $form.width() + 'px', | |
textAlign: 'center' | |
}) | |
.fadeIn(); | |
}); | |
// Disable the submit button. | |
self.attr('disabled', true); | |
return !o.debug; | |
}); | |
return this; | |
}); | |
}; | |
$.fn.disformer.defaults = { | |
debug: false, | |
delay: 1000, | |
opacity: 0.5, | |
text: 'Sending ...' | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment