Fix Canceled -> Cancelled (american vs canadian spelling, canada wins)
[arvados.git] / apps / workbench / app / assets / javascripts / infinite_scroll.js
index 8e6bbf0a818e7527057fe273d023a79bc4581dbd..6b392c48d7042ad16e212214e3b3626f61b7b0a9 100644 (file)
@@ -41,11 +41,26 @@ function maybe_load_more_content(event) {
         $container.append(spinner);
         $container.attr('data-infinite-serial', serial);
 
-        // Combine infiniteContentParams from multiple
-        // sources. filterable.js might put its params in
-        // infiniteContentParamsFilterable, etc.
+        // Combine infiniteContentParams from multiple sources. This
+        // mechanism allows each of several components to set and
+        // update its own set of filters, without having to worry
+        // about stomping on some other component's filters.
+        //
+        // For example, filterable.js writes filters in
+        // infiniteContentParamsFilterable ("search for text foo")
+        // without worrying about clobbering the filters set up by the
+        // tab pane ("only show jobs and pipelines in this tab").
         params = {};
         $.each($container.data(), function(datakey, datavalue) {
+            // Note: We attach these data to DOM elements using
+            // <element data-foo-bar="baz">. We store/retrieve them
+            // using $('element').data('foo-bar'), although
+            // .data('fooBar') would also work. The "all data" hash
+            // returned by $('element').data(), however, always has
+            // keys like 'fooBar'. In other words, where we have a
+            // choice, we stick with the 'foo-bar' style to be
+            // consistent with HTML. Here, our only option is
+            // 'fooBar'.
             if (/^infiniteContentParams/.exec(datakey)) {
                 if (datavalue instanceof Object) {
                     $.each(datavalue, function(hkey, hvalue) {
@@ -105,6 +120,13 @@ function maybe_load_more_content(event) {
      }
 }
 
+function ping_all_scrollers() {
+    // Send a scroll event to all scroll listeners that might need
+    // updating. Adding infinite-scroller class to the window element
+    // doesn't work, so we add it explicitly here.
+    $('.infinite-scroller').add(window).trigger('scroll');
+}
+
 $(document).
     on('click', 'div.infinite-retry button', function() {
         var $retry_div = $(this).closest('.infinite-retry');
@@ -113,7 +135,7 @@ $(document).
                         $retry_div.attr('data-infinite-content-href'));
         $retry_div.
             replaceWith('<div class="spinner spinner-32px spinner-h-center" />');
-        $('.infinite-scroller').trigger('scroll');
+        ping_all_scrollers();
     }).
     on('refresh-content', '[data-infinite-scroller]', function() {
         // Clear all rows, reset source href to initial state, and
@@ -124,8 +146,7 @@ $(document).
         $(this).
             html('').
             attr('data-infinite-content-href', first_page_href);
-        $('.infinite-scroller').
-            trigger('scroll');
+        ping_all_scrollers();
     }).
     on('ready ajax:complete', function() {
         $('[data-infinite-scroller]').each(function() {