Sha256: 4cbae093227e2077ae50519c1f002b6f3bb4ec78b3388dfe32f6134ad1294029

Contents?: true

Size: 1.23 KB

Versions: 20

Compression:

Stored size: 1.23 KB

Contents

/*  Originally from the Government Wide Pattern Library.
    Modified to check for items expanded on page load and
    to allow you to close an accordion without opening another
    https://github.com/18F/web-design-standards/blob/v0.8/assets/js/components.js#L202-L258
*/

function Accordion($el) {
  var self = this;
  this.$root = $el;
  this.$root.on('click', 'button', function(ev) {
    ev.preventDefault();
    if ( $(this).attr('aria-expanded') === 'true' ) {
      self.hide($(this));
    } else {
      self.show($(this));
    }
  });

}

Accordion.prototype.$ = function(selector) {
  return this.$root.find(selector);
}

Accordion.prototype.hide = function($button) {
  var selector = $button.attr('aria-controls'),
      $content = this.$('#' + selector);
  $button.attr('aria-expanded', false);
  $content.attr('aria-hidden', true);
};

Accordion.prototype.show = function($button) {
  var selector = $button.attr('aria-controls'),
      $content = this.$('#' + selector);
  $button.attr('aria-expanded', true);
  $content.attr('aria-hidden', false);
};

Accordion.prototype.hideAll = function() {
  var self = this;
  this.$('button').each(function() {
    self.hide($(this));
  });
};

function accordion($el) {
  return new Accordion($el);
}

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
guides_style_18f-1.0.6 assets/js/accordion.js
guides_style_18f-2.0.1 assets/js/accordion.js
guides_style_18f-2.0.0 assets/js/accordion.js
guides_style_18f-1.0.4 assets/js/accordion.js
guides_style_18f-1.0.3 assets/js/accordion.js
guides_style_18f-1.0.2 assets/js/accordion.js
guides_style_18f-1.0.1 assets/js/accordion.js
guides_style_18f-1.0.0 assets/js/accordion.js
guides_style_18f-0.4.9 assets/js/accordion.js
guides_style_18f-0.4.8 assets/js/accordion.js
guides_style_18f-0.4.7 assets/js/accordion.js
guides_style_18f-0.4.6 assets/js/accordion.js
guides_style_18f-0.4.5 assets/js/accordion.js
guides_style_18f-0.4.4 assets/js/accordion.js
guides_style_18f-0.4.3 assets/js/accordion.js
guides_style_18f-0.4.2 assets/js/accordion.js
guides_style_18f-0.4.1 assets/js/accordion.js
guides_style_18f-0.4.0 assets/js/accordion.js
guides_style_18f-0.3.0 assets/js/accordion.js
guides_style_18f-0.2.0 assets/js/accordion.js