X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c5f356f041ce97a9c506f0ed276c80e9de24b436..40b15ddcdcb8314f0a1036de6238d0ca4bfb3e41:/apps/workbench/app/assets/javascripts/infinite_scroll.js?ds=sidebyside diff --git a/apps/workbench/app/assets/javascripts/infinite_scroll.js b/apps/workbench/app/assets/javascripts/infinite_scroll.js index 8e6bbf0a81..6b392c48d7 100644 --- a/apps/workbench/app/assets/javascripts/infinite_scroll.js +++ b/apps/workbench/app/assets/javascripts/infinite_scroll.js @@ -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 + // . 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('
'); - $('.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() {