Skip to content

Commit

Permalink
linted
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cranwell committed Sep 1, 2015
1 parent 5aea7dd commit 41dafc9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"node_modules/**",
"**/*.min.js",
"**/vendor/**/*.js",
"./wagtail/wagtailadmin/static/**",
"./wagtail/wagtailadmin/templates/wagtailadmin/edit_handlers/inline_panel.js",
"./wagtail/contrib/wagtailsearchpromotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js",
"./wagtail/wagtailusers/templates/wagtailusers/groups/includes/page_permissions_formset.js",
Expand Down
37 changes: 19 additions & 18 deletions wagtail/wagtailadmin/static_src/wagtailadmin/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ $(function() {
});

/* close all dropdowns on body clicks */
$(document).on('click', function(e){
var targ = e.target;
if(!$(targ).hasClass('dropdown-toggle') && !$(targ).closest('.dropdown').length){
$(document).on('click', function(e) {
var relTarg = e.relatedTarget || e.toElement;
if (!$(relTarg).hasClass('dropdown-toggle')) {
$('.dropdown').removeClass('open');
}
});
Expand Down Expand Up @@ -134,7 +134,6 @@ $(function() {
}
}


/* Functions that need to run/rerun when active tabs are changed */
$(document).on('shown.bs.tab', function(e) {
// Resize autosize textareas
Expand All @@ -144,41 +143,43 @@ $(function() {
});

/* Debounce submission of long-running forms and add spinner to give sense of activity */
$(document).on('click', 'button.button-longrunning', function(e){
$(document).on('click', 'button.button-longrunning', function(e) {
var $self = $(this);
var $replacementElem = $('em', $self);
var reEnableAfter = 30;
var reEnableAfter = 30;
var dataName = 'disabledtimeout'

// Disabling a button prevents it submitting the form, so disabling
// 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)) {

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(){
$self.data(dataName, setTimeout(function() {
clearTimeout($self.data(dataName));

$self.prop('disabled', '').removeData(dataName).removeClass('button-longrunning-active')
if($self.data('clicked-text')){

if ($self.data('clicked-text')) {
$replacementElem.text($self.data('original-text'));
}

}, reEnableAfter * 1000));
if($self.data('clicked-text') && $replacementElem.length){

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');
$self.addClass('button-longrunning-active').prop('disabled', 'true');
}

clearTimeout(timeout);
},10);
}, 10);
});
});

0 comments on commit 41dafc9

Please sign in to comment.