PageSourceSearch

https://www.ignet.gov/sites/all/modules/jquery_ui_filter/accordion/jquery_ui_filter_accordion.js?tbqtfq

js ignet.gov collected 2026-10-02 05:29:38 UTC 3,718 bytes, 114 lines download raw bytes

1(function ($) {
2
3Drupal.jQueryUiFilter = Drupal.jQueryUiFilter || {}
4Drupal.jQueryUiFilter.accordionOptions = Drupal.jQueryUiFilter.accordionOptions || {}
5
6/**
7 * Scroll to an accordion's active element.
8 */
9Drupal.jQueryUiFilter.accordionScrollTo = function(accordion) {
10  var options = $(accordion).data('options') || {}
11  if (!options['scrollTo'] || !$(accordion).find('.ui-state-active').length) {
12    return;
13  }
14
15  var top = $(accordion).find('.ui-state-active').offset().top;
16  if (options['scrollTo']['duration']) {
17    $('html, body').animate({scrollTop: top}, options['scrollTo']['duration']);
18  }
19  else {
20    $('html, body').scrollTop(top);
21  }
22}
23
24/**
25 * Accordion change event handler to bookmark active element in location.hash.
26 */
27Drupal.jQueryUiFilter.accordionChangeStart = function(event, ui) {
28  var href = ui.newHeader.find('a').attr('href');
29  if (href) {
30    location.hash = href;
31    return false; // Cancel event and let accordionHashChangeEvent handler activate the element.
32  }
33  else {
34    return true;
35  }
36}
37
38/**
39 * On hash change activate and scroll to an accordion element.
40 */
41Drupal.jQueryUiFilter.accordionHashChangeEvent = function() {
42  $accordionHeader = $('.ui-accordion > .ui-accordion-header:has(a[href="' + location.hash + '"])')
43  $accordion = $accordionHeader.parent();
44  var index = $accordionHeader.prevAll('.ui-accordion-header').length;
45
46  if ($.ui.version == '1.8.7') {
47    // NOTE: Accordion 'Active' property not change'ing http://bugs.jqueryui.com/ticket/4576
48    $accordion.accordion('activate', index);
49  }
50  else {
51    // NOTE: Accordion 'Active' property http://api.jqueryui.com/accordion/#option-active
52    $accordion.accordion('option', 'active', index);
53  }
54}
55
56/**
57 * jQuery UI filter accordion behavior.
58 */
59Drupal.behaviors.jQueryUiFilterAccordion  = {attach: function(context) {
60  if (Drupal.settings.jQueryUiFilter.disabled) {
61    return;
62  }
63
64  var headerTag = Drupal.settings.jQueryUiFilter.accordionHeaderTag;
65
66  $('div.jquery-ui-filter-accordion', context).once('jquery-ui-filter-accordion', function () {
67    var options = Drupal.jQueryUiFilter.getOptions('accordion');
68
69    // Look for jQuery UI filter header class.
70    options['header'] = '.jquery-ui-filter-accordion-header';
71
72    if ($(this).hasClass('jquery-ui-filter-accordion-collapsed')) { // Set collapsed options
73      options['collapsible'] = true;
74      options['active'] = false;
75    }
76
77    // Convert <h*> to div to remove tag and insure the accordion does not use the existing h3 style.
78    // Sets active item based on location.hash.
79    var index = 0;
80    $(this).find(headerTag + '.jquery-ui-filter-accordion-header').each(function(){
81      var id = this.id || $(this).text().toLowerCase().replace(/[^-a-z0-9]+/gm, '-');
82      var hash = '#' + id;
83      if (hash == location.hash) {
84        options['active'] = index;
85      }
86      index++;
87
88      $(this).replaceWith('<div class="jquery-ui-filter-header jquery-ui-filter-accordion-header"><a href="' + hash + '">' + $(this).html() + '</a></div>');
89    });
90
91    // DEBUG:
92    // console.log(options);
93
94    // Save options as data and init accordion
95    $(this).data('options', options).accordion(options);
96
97    // Scroll to active
98    Drupal.jQueryUiFilter.accordionScrollTo(this);
99
100    // Bind accordion change event to record history
101    if (options['history']) {
102      $(this).bind('accordionchangestart', Drupal.jQueryUiFilter.accordionChangeStart);
103    }
104
105    // Init hash change event handling once
106    if (!Drupal.jQueryUiFilter.accordionInitialized) {
107      Drupal.jQueryUiFilter.hashChange(Drupal.jQueryUiFilter.accordionHashChangeEvent);
108    }
109    Drupal.jQueryUiFilter.accordionInitialized = true;
110  });
111
112}}
113
114})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.