Merge branch '2884-improved-picker' closes #2884
[arvados.git] / apps / workbench / app / assets / javascripts / application.js
index d66cb9224f0f703dfe8484b83b142d483d9b8901..1ade33f0cc9ae81ecd534ecf01d1533f0e2bf354 100644 (file)
@@ -43,12 +43,31 @@ jQuery(function($){
         targets.fadeToggle(200);
     });
 
+    var ajaxCount = 0;
+
     $(document).
         on('ajax:send', function(e, xhr) {
-            $('.loading').fadeTo('fast', 1);
+            ajaxCount += 1;
+            if (ajaxCount == 1) {
+                $('.loading').fadeTo('fast', 1);
+            }
         }).
         on('ajax:complete', function(e, status) {
-            $('.loading').fadeOut('fast', 0);
+            ajaxCount -= 1;
+            if (ajaxCount == 0) {
+                $('.loading').fadeOut('fast', 0);
+            }
+        }).
+        on('ajaxSend', function(e, xhr) {
+            // jQuery triggers 'ajaxSend' event when starting an ajax call, but
+            // rails-generated ajax triggers generate 'ajax:send'.  Workbench
+            // event listeners currently expect 'ajax:send', so trigger the
+            // rails event in response to the jQuery one.
+            $(document).trigger('ajax:send');
+        }).
+        on('ajaxComplete', function(e, xhr) {
+            // See comment above about ajaxSend/ajax:send
+            $(document).trigger('ajax:complete');
         }).
         on('click', '.removable-tag a', function(e) {
             var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
@@ -111,6 +130,11 @@ jQuery(function($){
             $('.btn').button();
         });
 
+    $(document).
+        on('ready ajax:complete', function() {
+            $('[data-toggle~=tooltip]').tooltip({container:'body'});
+        });
+
     HeaderRowFixer = function(selector) {
         this.duplicateTheadTr = function() {
             $(selector).each(function() {