foundation.accordion.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;(function ($, window, document, undefined) {
  2. 'use strict';
  3. Foundation.libs.accordion = {
  4. name : 'accordion',
  5. version : '5.2.2',
  6. settings : {
  7. active_class: 'active',
  8. multi_expand: false,
  9. toggleable: true
  10. },
  11. init : function (scope, method, options) {
  12. this.bindings(method, options);
  13. },
  14. events : function () {
  15. var self = this;
  16. var S = this.S;
  17. S(this.scope)
  18. .off('.fndtn.accordion')
  19. .on('click.fndtn.accordion', '[' + this.attr_name() + '] dd > a', function (e) {
  20. var accordion = S(this).closest('[' + self.attr_name() + ']'),
  21. target = S('#' + this.href.split('#')[1]),
  22. siblings = S('dd > .content', accordion),
  23. aunts = $('dd', accordion),
  24. settings = accordion.data(self.attr_name(true) + '-init'),
  25. active_content = S('dd > .content.' + settings.active_class, accordion),
  26. active_parent = S('dd.' + settings.active_class, accordion);
  27. e.preventDefault();
  28. if (! S(this).closest('dl').is(accordion)) { return; }
  29. if (settings.toggleable && target.is(active_content)) {
  30. active_parent.toggleClass(settings.active_class, false);
  31. return target.toggleClass(settings.active_class, false);
  32. }
  33. if (!settings.multi_expand) {
  34. siblings.removeClass(settings.active_class);
  35. aunts.removeClass(settings.active_class);
  36. }
  37. target.addClass(settings.active_class).parent().addClass(settings.active_class);
  38. });
  39. },
  40. off : function () {},
  41. reflow : function () {}
  42. };
  43. }(jQuery, this, this.document));