From 314274bec4d0d8c095cf3d11dd361aca0a8223d2 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Fri, 6 Mar 2015 09:28:16 +0000 Subject: [PATCH] tweaks to how buttons disable themselves --- .../static_src/wagtailadmin/js/core.js | 38 +++++++++---------- .../templates/wagtailadmin/pages/edit.html | 6 ++- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/js/core.js b/wagtail/wagtailadmin/static_src/wagtailadmin/js/core.js index de43f18e32..6b8c76762c 100644 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/js/core.js +++ b/wagtail/wagtailadmin/static_src/wagtailadmin/js/core.js @@ -84,7 +84,7 @@ $(function() { /* close all dropdowns on body clicks */ $(document).on('click', function(e) { var relTarg = e.relatedTarget || e.toElement; - if (!$(relTarg).hasClass('dropdown-toggle')) { + if(!$(relTarg).hasClass('dropdown-toggle') && !$(relTarg).closest('.dropdown').length){ $('.dropdown').removeClass('open'); } }); @@ -151,25 +151,25 @@ $(function() { var timeoutLength = 30; // Button re-enables after this time (seconds), to allow for errors in submissions causing forms to be permanently un-usable var dataname = 'disabledtimeout' - e.preventDefault(); + // Disabling a button prevents it submitting the form, so disabling must occur on a timeout only after this function returns + var timeout = setTimeout(function(){ + // save original button value + $self.data('original-text', $replacementElem.text()); - // save original button value - $self.data('original-text', $replacementElem.text()); - - if(!$self.data(dataname)) { - $self.data(dataname, setTimeout(function(){ - clearTimeout($self.data(dataname)); - $self.prop('disabled', '').removeData(dataname).removeClass('button-longrunning-active') - $replacementElem.text($self.data('original-text')); - }, timeoutLength * 1000)); + if(!$self.data(dataname)) { + $self.data(dataname, setTimeout(function(){ + clearTimeout($self.data(dataname)); + $self.prop('disabled', '').removeData(dataname).removeClass('button-longrunning-active') + $replacementElem.text($self.data('original-text')); + }, timeoutLength * 1000)); + + if($self.data('clicked-text') && $replacementElem.length){ + $replacementElem.text($self.data('clicked-text')); + } + $self.addClass('button-longrunning-active').prop('disabled', 'true'); + } - if($self.data('clicked-text') && $replacementElem.length){ - $replacementElem.text($self.data('clicked-text')); - } - - $self.closest('form').submit(); - $self.addClass('button-longrunning-active').prop('disabled', 'true'); - - } + clearTimeout(timeout); + },10); }); }); diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/pages/edit.html b/wagtail/wagtailadmin/templates/wagtailadmin/pages/edit.html index b927bcf716..9efd8ac0bb 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/pages/edit.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/pages/edit.html @@ -32,7 +32,7 @@