In this repo i store all my websites, each in a different branch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
5.3 KiB

  1. Skip to content
  2. This repository
  3. Search
  4. Pull requests
  5. Issues
  6. Gist
  7. @inpothet
  8. Sign out
  9. Watch 37
  10. Star 237
  11. Fork 171 zurb/bower-foundation
  12. Code Pull requests 0 Projects 0 Pulse Graphs
  13. Branch: master Find file Copy pathbower-foundation/js/foundation/foundation.accordion.js
  14. 51a281e on Oct 14, 2015
  15. @hellapixels hellapixels Foundation build to bower-foundation
  16. 2 contributors @mhayes @hellapixels
  17. RawBlameHistory
  18. 127 lines (105 sloc) 4.58 KB
  19. ;(function ($, window, document, undefined) {
  20. 'use strict';
  21. Foundation.libs.accordion = {
  22. name : 'accordion',
  23. version : '5.5.3',
  24. settings : {
  25. content_class : 'content',
  26. active_class : 'active',
  27. multi_expand : false,
  28. toggleable : true,
  29. callback : function () {}
  30. },
  31. init : function (scope, method, options) {
  32. this.bindings(method, options);
  33. },
  34. events : function (instance) {
  35. var self = this;
  36. var S = this.S;
  37. self.create(this.S(instance));
  38. S(this.scope)
  39. .off('.fndtn.accordion')
  40. .on('click.fndtn.accordion', '[' + this.attr_name() + '] > dd > a, [' + this.attr_name() + '] > li > a', function (e) {
  41. var accordion = S(this).closest('[' + self.attr_name() + ']'),
  42. groupSelector = self.attr_name() + '=' + accordion.attr(self.attr_name()),
  43. settings = accordion.data(self.attr_name(true) + '-init') || self.settings,
  44. contentAttr = S(this).context.attributes['data-content'],
  45. target = S('#' + (contentAttr ? contentAttr.value : this.href.split('#')[1])),
  46. aunts = $('> dd, > li', accordion),
  47. siblings = aunts.children('.' + settings.content_class),
  48. active_content = siblings.filter('.' + settings.active_class);
  49. e.preventDefault();
  50. if (accordion.attr(self.attr_name())) {
  51. siblings = siblings.add('[' + groupSelector + '] dd > ' + '.' + settings.content_class + ', [' + groupSelector + '] li > ' + '.' + settings.content_class);
  52. aunts = aunts.add('[' + groupSelector + '] dd, [' + groupSelector + '] li');
  53. }
  54. if (settings.toggleable && target.is(active_content)) {
  55. target.parent('dd, li').toggleClass(settings.active_class, false);
  56. target.toggleClass(settings.active_class, false);
  57. S(this).attr('aria-expanded', function(i, attr){
  58. return attr === 'true' ? 'false' : 'true';
  59. });
  60. settings.callback(target);
  61. target.triggerHandler('toggled', [accordion]);
  62. accordion.triggerHandler('toggled', [target]);
  63. return;
  64. }
  65. if (!settings.multi_expand) {
  66. siblings.removeClass(settings.active_class);
  67. aunts.removeClass(settings.active_class);
  68. aunts.children('a').attr('aria-expanded','false');
  69. }
  70. target.addClass(settings.active_class).parent().addClass(settings.active_class);
  71. settings.callback(target);
  72. target.triggerHandler('toggled', [accordion]);
  73. accordion.triggerHandler('toggled', [target]);
  74. S(this).attr('aria-expanded','true');
  75. });
  76. },
  77. create: function($instance) {
  78. var self = this,
  79. accordion = $instance,
  80. aunts = $('> .accordion-navigation', accordion),
  81. settings = accordion.data(self.attr_name(true) + '-init') || self.settings;
  82. aunts.children('a').attr('aria-expanded','false');
  83. aunts.has('.' + settings.content_class + '.' + settings.active_class).addClass(settings.active_class).children('a').attr('aria-expanded','true');
  84. if (settings.multi_expand) {
  85. $instance.attr('aria-multiselectable','true');
  86. }
  87. },
  88. toggle : function(options) {
  89. var options = typeof options !== 'undefined' ? options : {};
  90. var selector = typeof options.selector !== 'undefined' ? options.selector : '';
  91. var toggle_state = typeof options.toggle_state !== 'undefined' ? options.toggle_state : '';
  92. var $accordion = typeof options.$accordion !== 'undefined' ? options.$accordion : this.S(this.scope).closest('[' + this.attr_name() + ']');
  93. var $items = $accordion.find('> dd' + selector + ', > li' + selector);
  94. if ( $items.length < 1 ) {
  95. if ( window.console ) {
  96. console.error('Selection not found.', selector);
  97. }
  98. return false;
  99. }
  100. var S = this.S;
  101. var active_class = this.settings.active_class;
  102. $items.each(function() {
  103. var $item = S(this);
  104. var is_active = $item.hasClass(active_class);
  105. if ( ( is_active && toggle_state === 'close' ) || ( !is_active && toggle_state === 'open' ) || toggle_state === '' ) {
  106. $item.find('> a').trigger('click.fndtn.accordion');
  107. }
  108. });
  109. },
  110. open : function(options) {
  111. var options = typeof options !== 'undefined' ? options : {};
  112. options.toggle_state = 'open';
  113. this.toggle(options);
  114. },
  115. close : function(options) {
  116. var options = typeof options !== 'undefined' ? options : {};
  117. options.toggle_state = 'close';
  118. this.toggle(options);
  119. },
  120. off : function () {},
  121. reflow : function () {}
  122. };
  123. }(jQuery, window, window.document));
  124. Contact GitHub API Training Shop Blog About
  125. © 2017 GitHub, Inc. Terms Privacy Security Status Help