Revert "applied @joshbarr tweaks"

This reverts commit 8df933f58c49fa9c26283ffd2b5b2289ef72bc19.
This commit is contained in:
Dave Cranwell 2015-09-01 16:32:15 +01:00
parent 411eec5d33
commit 5aea7dd51e

View file

@ -147,40 +147,38 @@ $(function() {
$(document).on('click', 'button.button-longrunning', function(e){
var $self = $(this);
var $replacementElem = $('em', $self);
// Time (seconds) after which the button re-activates
var reEnableAfter = 30;
var dataName = 'disabledtimeout'
// Trigger form submission if it's a submit button
if (this.form && this.getAttribute('type') === 'submit') {
$(this.form).trigger('submit');
}
// Disabling a button prevents it submitting the form, so disabling
// must occur on a brief timeout only after this function returns.
var timeout = setTimeout(function(){
if(!$self.data(dataName)) {
// Button re-enables after a timeout to prevent button becoming
// permanently un-usable
$self.data(dataName, setTimeout(function(){
clearTimeout($self.data(dataName));
$self.prop('disabled', '').removeData(dataName).removeClass('button-longrunning-active')
if($self.data('clicked-text')){
$replacementElem.text($self.data('original-text'));
}
if(!$self.data(dataName)) {
// Button re-enables after a timeout to prevent button becoming
// permanently un-usable
$self.data(dataName, setTimeout(function(){
clearTimeout($self.data(dataName));
}, reEnableAfter * 1000));
$self.prop('disabled', '').removeData(dataName).removeClass('button-longrunning-active')
if($self.data('clicked-text')){
$replacementElem.text($self.data('original-text'));
if($self.data('clicked-text') && $replacementElem.length){
// Save current button text
$self.data('original-text', $replacementElem.text());
$replacementElem.text($self.data('clicked-text'));
}
}, reEnableAfter * 1000));
if($self.data('clicked-text') && $replacementElem.length){
// Save current button text
$self.data('original-text', $replacementElem.text());
$replacementElem.text($self.data('clicked-text'));
// Disabling button must be done last: disabled buttons can't be
// modified in the normal way, it would seem.
$self.addClass('button-longrunning-active').prop('disabled', 'true');
}
// Disabling button must be done last: disabled buttons can't be
// modified in the normal way, it would seem.
$self.addClass('button-longrunning-active').prop('disabled', 'true');
}
clearTimeout(timeout);
},10);
});
});