Requires

Provides

Fx.Accordion.js

An Fx.Elements extension which allows you to easily create accordion type controls.

License:
MIT-style license
Authors:
Valerio Proietti
  1. 25
  2. 26
  3. 27
  4. 28
  5. 29
  6. 30
  7. 31
  8. 32
  9. 33
  10. 34
  11. 35
  12. 36
  13. 37
  14. 38
  15. 39
  16. 40
  17. 41
  18. 42
  19. 43
  20. 44
  21. 45
  22. 46
  23. 47
  24. 48
  25. 49
  26. 50
  27. 51
  28. 52
  29. 53
  30. 54
  31. 55
  32. 56
  33. 57
  34. 58
  35. 59
  36. 60
  37. 61
  38. 62
  39. 63
  40. 64
  41. 65
  42. 66
  43. 67
  44. 68
  45. 69
  46. 70
  47. 71
  48. 72
  49. 73
  50. 74
  51. 75
  52. 76
  53. 77
  54. 78
  55. 79
  56. 80
  57. 81
  58. 82
  59. 83
  60. 84
  61. 85
  62. 86
  63. 87
  64. 88
  65. 89
  66. 90
  67. 91
  68. 92
  69. 93
  70. 94
  71. 95
  72. 96
  73. 97
  74. 98
  75. 99
  76. 100
  77. 101
  78. 102
  79. 103
  80. 104
  81. 105
  82. 106
  83. 107
  84. 108
  85. 109
  86. 110
  87. 111
  88. 112
  89. 113
  90. 114
  91. 115
  92. 116
  93. 117
  94. 118
  95. 119
  96. 120
  97. 121
  98. 122
  99. 123
  100. 124
  101. 125
  102. 126
  103. 127
  104. 128
  105. 129
  106. 130
  107. 131
  108. 132
  109. 133
  110. 134
  111. 135
  112. 136
  113. 137
  114. 138
  115. 139
  116. 140
  117. 141
  118. 142
  119. 143
  120. 144
  121. 145
  122. 146
  123. 147
  124. 148
  125. 149
  126. 150
  127. 151
  128. 152
  129. 153
  130. 154
  131. 155
  132. 156
  133. 157
  134. 158
  135. 159
  136. 160
  137. 161
  138. 162
  139. 163
  140. 164
  141. 165
  142. 166
  143. 167
  144. 168
  145. 169
  146. 170
  147. 171
  148. 172
  149. 173
  150. 174
  151. 175
  152. 176
  153. 177
  154. 178
  155. 179
  156. 180
  157. 181
  158. 182
  159. 183
  160. 184
  161. 185
  162. 186
  163. 187
  164. 188
  165. 189
  166. 190
  167. 191
  168. 192
Fx.Accordion = new Class({ Extends: Fx.Elements, options: {/* onActive: function(toggler, section){}, onBackground: function(toggler, section){},*/ fixedHeight: false, fixedWidth: false, display: 0, show: false, height: true, width: false, opacity: true, alwaysHide: false, trigger: 'click', initialDisplayFx: true, returnHeightToAuto: true }, initialize: function(){ var defined = function(obj){ return obj != null; }; var params = Array.link(arguments, { 'container': Type.isElement, //deprecated 'options': Type.isObject, 'togglers': defined, 'elements': defined }); this.parent(params.elements, params.options); this.togglers = $$(params.togglers); this.previous = -1; this.internalChain = new Chain(); if (this.options.alwaysHide) this.options.wait = true; if (this.options.show || this.options.show === 0){ this.options.display = false; this.previous = this.options.show; } if (this.options.start){ this.options.display = false; this.options.show = false; } this.effects = {}; if (this.options.opacity) this.effects.opacity = 'fullOpacity'; if (this.options.width) this.effects.width = this.options.fixedWidth ? 'fullWidth' : 'offsetWidth'; if (this.options.height) this.effects.height = this.options.fixedHeight ? 'fullHeight' : 'scrollHeight'; for (var i = 0, l = this.togglers.length; i < l; i++) this.addSection(this.togglers[i], this.elements[i]); this.elements.each(function(el, i){ if (this.options.show === i){ this.fireEvent('active', [this.togglers[i], el]); } else { for (var fx in this.effects) el.setStyle(fx, 0); } }, this); if (this.options.display || this.options.display === 0 || this.options.initialDisplayFx === false){ this.display(this.options.display, this.options.initialDisplayFx); } if (this.options.fixedHeight !== false) this.options.returnHeightToAuto = false; this.addEvent('complete', this.internalChain.callChain.bind(this.internalChain)); }, addSection: function(toggler, element){ toggler = document.id(toggler); element = document.id(element); this.togglers.include(toggler); this.elements.include(element); var test = this.togglers.contains(toggler); var idx = this.togglers.indexOf(toggler); var displayer = this.display.bind(this, idx); toggler.store('accordion:display', displayer) .addEvent(this.options.trigger, displayer); if (this.options.height) element.setStyles({'padding-top': 0, 'border-top': 'none', 'padding-bottom': 0, 'border-bottom': 'none'}); if (this.options.width) element.setStyles({'padding-left': 0, 'border-left': 'none', 'padding-right': 0, 'border-right': 'none'}); element.fullOpacity = 1; if (this.options.fixedWidth) element.fullWidth = this.options.fixedWidth; if (this.options.fixedHeight) element.fullHeight = this.options.fixedHeight; element.setStyle('overflow', 'hidden'); if (!test){ for (var fx in this.effects) element.setStyle(fx, 0); } return this; }, removeSection: function(toggler, displayIndex){ var idx = this.togglers.indexOf(toggler); var element = this.elements[idx]; var remover = function(){ this.togglers.erase(toggler); this.elements.erase(element); this.detach(toggler); }.bind(this); if (this.now == idx || displayIndex != null){ this.display(displayIndex != null ? displayIndex : (idx - 1 >= 0 ? idx - 1 : 0)).chain(remover); } else { remover(); } return this; }, detach: function(toggler){ var remove = function(toggler){ toggler.removeEvent(this.options.trigger, toggler.retrieve('accordion:display')); }.bind(this); if (!toggler) this.togglers.each(remove); else remove(toggler); return this; }, display: function(index, useFx){ if (!this.check(index, useFx)) return this; useFx = useFx != null ? useFx : true; index = (typeOf(index) == 'element') ? this.elements.indexOf(index) : index; if (index == this.previous) return this; if (this.options.returnHeightToAuto){ var prev = this.elements[this.previous]; if (prev && !this.selfHidden){ for (var fx in this.effects){ prev.setStyle(fx, prev[this.effects[fx]]); } } } if ((this.timer && this.options.wait) || (index === this.previous && !this.options.alwaysHide)) return this; this.previous = index; var obj = {}; this.elements.each(function(el, i){ obj[i] = {}; var hide; if (i != index){ hide = true; } else if (this.options.alwaysHide && ((el.offsetHeight > 0 && this.options.height) || el.offsetWidth > 0 && this.options.width)){ hide = true; this.selfHidden = true; } this.fireEvent(hide ? 'background' : 'active', [this.togglers[i], el]); for (var fx in this.effects) obj[i][fx] = hide ? 0 : el[this.effects[fx]]; }, this); this.internalChain.clearChain(); this.internalChain.chain(function(){ if (this.options.returnHeightToAuto && !this.selfHidden){ var el = this.elements[index]; if (el) el.setStyle('height', 'auto'); }; }.bind(this)); return useFx ? this.start(obj) : this.set(obj); } });

<1.2compat>

Compatibility with 1.2.0

  1. 198
  2. 199
  3. 200
  4. 201
  5. 202
  6. 203
  7. 204
  8. 205
  9. 206
  10. 207
  11. 208
  12. 209
  13. 210
  14. 211
  15. 212
  16. 213
  17. 214
  18. 215
  19. 216
  20. 217
  21. 218
  22. 219
  23. 220
  24. 221
  25. 222
  26. 223
  27. 224
  28. 225
var Accordion = new Class({ Extends: Fx.Accordion, initialize: function(){ this.parent.apply(this, arguments); var params = Array.link(arguments, {'container': Type.isElement}); this.container = params.container; }, addSection: function(toggler, element, pos){ toggler = document.id(toggler); element = document.id(element); var test = this.togglers.contains(toggler); var len = this.togglers.length; if (len && (!test || pos)){ pos = pos != null ? pos : len - 1; toggler.inject(this.togglers[pos], 'before'); element.inject(toggler, 'after'); } else if (this.container && !test){ toggler.inject(this.container); element.inject(this.container); } return this.parent.apply(this, arguments); } });

</1.2compat>