1 // Load tab panes on demand. See app/views/application/_content.html.erb
3 // Fire when a tab is selected/clicked. Check whether the content in
4 // the corresponding pane is loaded (or is being loaded). If not,
5 // start an AJAX request to load the content.
6 $(document).on('shown.bs.tab', '[data-toggle="tab"]', function(e) {
7 var content_url = $(e.target).attr('data-pane-content-url');
8 var $pane = $($(e.target).attr('href'));
9 if ($pane.hasClass('loaded'))
11 $.ajax(content_url, {dataType: 'html', type: 'GET', context: $pane}).
12 done(function(data, status, jqxhr) {
13 $('> div > div', this).html(data);
14 $(this).addClass('loaded');
18 // Fire when the content in a tab pane becomes stale/dirty. If the
19 // pane is visible now, reload it right away. Otherwise, just replace
20 // the current content with a spinner for now: there's no need to load
21 // the new content unless/until the user clicks the corresponding tab.
22 $(document).on('arv:pane:reload', '.tab-pane', function() {
23 // Unload a single pane. Reload it if it's active.
24 $(this).removeClass('loaded');
25 if ($(this).hasClass('active')) {
26 $('[href=#' + $(this).attr('id') + ']').trigger('shown.bs.tab');
28 // When the user selects this tab, show a spinner instead of
29 // old content while loading.
30 $('> div > div', this).
31 html('<div class="spinner spinner-32px spinner-h-center"></div>');
35 // Mark all panes as stale/dirty. Refresh the active pane.
36 $(document).on('arv-log-event arv:pane:reload:all', function() {
37 $('.tab-pane.loaded').trigger('arv:pane:reload');