+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');
+}
+
+function mergeInfiniteContentParams($container) {
+ var params = {};
+ // 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").
+ $.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) {
+ if (hvalue instanceof Array) {
+ params[hkey] = (params[hkey] || []).
+ concat(hvalue);
+ } else if (hvalue instanceof Object) {
+ $.extend(params[hkey], hvalue);
+ } else {
+ params[hkey] = hvalue;
+ }
+ });
+ }
+ }
+ });
+ return params;
+}
+
+function setColumnSort( $container, $header, direction ) {
+ // $container should be the tbody or whatever has all the infinite table data attributes
+ // $header should be the th with a preset data-sort-order attribute
+ // direction should be "asc" or "desc"
+ // This function returns the order by clause for this column header as a string
+
+ // First reset all sort directions
+ $('th[data-sort-order]').removeData('sort-order-direction');
+ // set the current one
+ $header.data('sort-order-direction', direction);
+ // change the ordering parameter
+ var paramsAttr = 'infinite-content-params-' + $container.data('infinite-content-params-attr');
+ var params = $container.data(paramsAttr) || {};
+ params.order = $header.data('sort-order').split(",").join( ' ' + direction + ', ' ) + ' ' + direction;
+ $container.data(paramsAttr, params);
+ // show the correct icon next to the column header
+ $container.trigger('sort-icons');
+
+ return params.order;
+}
+