Merge branch 'master' into 5539-better-docker
[arvados.git] / apps / workbench / app / assets / javascripts / infinite_scroll.js
index f07cd0978fb380bfa4205b1e9d3aea146073d926..81a3a4639b8c7f63a2b42a416252664d746a6b78 100644 (file)
@@ -1,7 +1,7 @@
 function maybe_load_more_content(event) {
-    var scroller = this;        // element with scroll bars
-    var $container;             // element that receives new content
-    var src;                    // url for retrieving content
+    var scroller = this;
+    var $container = $(event.data.container);
+    var src;                     // url for retrieving content
     var scrollHeight;
     var spinner, colspan;
     var serial = Date.now();
@@ -11,7 +11,6 @@ function maybe_load_more_content(event) {
         >
         scrollHeight - 50)
     {
-        $container = $(event.data.container);
         if (!$container.attr('data-infinite-content-href0')) {
             // Remember the first page source url, so we can refresh
             // from page 1 later.
@@ -201,7 +200,7 @@ $(document).
                 if( hasHTML5History() && history.state !== undefined && history.state !== null && history.state.order !== undefined && history.state.order[tabId] !== undefined ) {
                     // we will use the list of one or more table columns associated with this header to find the right element
                     // see sortable_columns as it is passed to render_pane in the various tab .erbs (e.g. _show_jobs_and_pipelines.html.erb)
-                    var strippedColumns = history.state.order[tabId].replace(/\s|asc|desc/g,'');
+                    var strippedColumns = history.state.order[tabId].replace(/\s|\basc\b|\bdesc\b/g,'');
                     var sortDirection = history.state.order[tabId].split(" ")[1].replace(/,/,'');
                     $columnHeader = $(this).closest('table').find('[data-sort-order="'+ strippedColumns +'"]');
                     setColumnSort( $(this), $columnHeader, sortDirection );
@@ -226,6 +225,10 @@ $(document).
                 trigger('scroll');
         });
     }).
+    on('shown.bs.tab', 'a[data-toggle="tab"]', function(event) {
+        $(event.target.getAttribute('href') + ' [data-infinite-scroller]').
+            trigger('scroll');
+    }).
     on('click', 'th[data-sort-order]', function() {
         var direction = $(this).data('sort-order-direction');
         // reverse the current direction, or do ascending if none
@@ -242,8 +245,8 @@ $(document).
         // put it in the browser history state if browser allows it
         if( hasHTML5History() ) {
             var tabId = $(this).closest('div.tab-pane').attr('id');
-            var state =  history.state;
-            if( state.order === undefined) {
+            var state =  history.state || {};
+            if( state.order === undefined ) {
                 state.order = {};
             }
             state.order[tabId] = order;