From 8b88745f0fb37d44a69e0c99e5d84dd3b372ff0f Mon Sep 17 00:00:00 2001 From: Tobias Stenzel Date: Thu, 14 Sep 2017 12:18:51 +0000 Subject: [PATCH] delay ajax load indicator by 300ms * avoid flashing for short AJAX calls --- .../additionals_delay_ajax_indicator.js | 14 ++++++++++++++ lib/additionals/helpers.rb | 1 + 2 files changed, 15 insertions(+) create mode 100644 assets/javascripts/additionals_delay_ajax_indicator.js diff --git a/assets/javascripts/additionals_delay_ajax_indicator.js b/assets/javascripts/additionals_delay_ajax_indicator.js new file mode 100644 index 00000000..29a63b0d --- /dev/null +++ b/assets/javascripts/additionals_delay_ajax_indicator.js @@ -0,0 +1,14 @@ + function delayAjaxIndicator() { + $(document).off('ajaxSend').bind('ajaxSend', function(event, xhr, settings) { + if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') { + $('#ajax-indicator').stop(true, false).delay(300).show(0); + } + }); + + $(document).off('ajaxStop').bind('ajaxStop', function() { + $('#ajax-indicator').hide(0); + }); + + }; + + $(document).ready(delayAjaxIndicator) diff --git a/lib/additionals/helpers.rb b/lib/additionals/helpers.rb index f1b653cc..8c599c2d 100644 --- a/lib/additionals/helpers.rb +++ b/lib/additionals/helpers.rb @@ -188,6 +188,7 @@ module Additionals def additionals_load_select2 additionals_include_js('additionals_to_select2') + additionals_include_js('additionals_delay_ajax_indicator') end def additionals_load_font_awesome