PageSourceSearch

https://www.pm.gc.ca/themes/pm_theme/js/pmaccordion.js?tluucm

js pm.gc.ca collected 2026-09-24 08:25:18 UTC 3,259 bytes, 93 lines download raw bytes

1(function ($, Drupal, drupalSettings) {
2  Drupal.behaviors.pmaccordion = {
3    attach: function (context, settings) {
4      PMAccordion.init();
5    }
6  };
7})(jQuery, Drupal, drupalSettings);
8
9var PMAccordion = function () {
10  var pmaccordion = {
11    initialized: false, // Flag to indicate first-time initialization
12    storedHash: null,  // Holds the hash from URL
13  };
14
15  /*
16   * First-time initialization
17   */
18  function init() {
19    // Only initialize once
20    if (pmaccordion.initialized) {
21      return;
22    }
23
24    // Set the initialized flag now
25    pmaccordion.initialized = true;
26
27    // check if url has hash string (link from footer)
28    $(window).bind('hashchange', function () {
29      storedHash = window.location.hash;
30      // console.log('storedHash = ' + storedHash);
31      if (storedHash) {
32        var btn_in_hash = $(storedHash + ' .btn.btn-link');
33        btn_in_hash.click();
34      }
35    }).trigger('hashchange');
36
37    // this allows only one accordion be openned at the same time
38    $('#notices-accordion button[data-target="#collapseOne2"], #notices-accordion button[data-target="#collapseTwo2"], #notices-accordion button[data-target="#collapseThree2"]').on('click', function () {
39      openAccordion($(this));
40      // this section is added to fix the menu overlapping the content when we click on the links that opened the accordion: Privacy Statement, etc.
41      if ($(window).width() < 768) {
42        if ($('#navbar-collapse').hasClass('in')) {
43          $('#navbar-collapse').removeClass('in');
44            $('#navbar-collapse').attr('aria-expanded', 'false');
45          }
46        }
47      });
48    }
49
50  function openAccordion(thisButton) {
51    var active_card_header = thisButton.closest('.card-header');
52    var parent_card_header = $(active_card_header).closest('.bordered.card.z-depth-0.card');
53    var ids = [];     // this arrays stores the siblings of active cards
54
55    // check if this card is already opened
56    active_card_datat_target = thisButton.attr('datat-target');
57    active_card_accordion = $('#notices-accordion ' + active_card_datat_target)[0];
58    if ($(active_card_accordion).hasClass('in')) {
59      $(active_card_accordion).attr('style', '');
60    }
61
62    // check if the siblings are opened, if so let's keep the active card only opened
63    $(parent_card_header).siblings().each(function () {
64      var card_header_other = $(this).children().first();
65      var card_header_other_id = $(card_header_other).attr('id');
66      if (card_header_other_id != active_card_header) {
67        var btn_other = card_header_other.find('.btn.btn-link').first();
68        if (btn_other.length) {
69          if (!btn_other.hasClass('collapsed')) {
70            btn_other.addClass('collapsed');
71            if (btn_other.attr('aria-expanded') == 'true') {
72              btn_other.attr('aria-expanded', 'false');
73
74              var ar_control = btn_other.attr('aria-controls');
75              var content_acc = $('#' + ar_control);
76              if ($(content_acc).hasClass('in')) {
77                $(content_acc).removeClass('in');
78                $(content_acc).css('height', '0px');
79              }
80            }
81          }
82        }
83      }
84    });
85
86  }
87
88  return {
89    init: init,
90    openAccordion: openAccordion,
91  }
92
93}();

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.