Requires

Provides

Fx.Reveal.js

Defines Fx.Reveal, a class that shows and hides elements with a transition.

License:
MIT-style license
Authors:
Aaron Newton
  1. 26
  2. 27
  3. 28
  4. 29
  5. 30
  6. 31
  7. 32
  8. 33
  9. 34
  10. 35
  11. 36
  12. 37
  13. 38
  14. 39
  15. 40
  16. 41
  17. 42
  18. 43
  19. 44
  20. 45
  21. 46
  22. 47
  23. 48
  24. 49
  25. 50
  26. 51
  27. 52
  28. 53
  29. 54
  30. 55
  31. 56
  32. 57
  33. 58
  34. 59
  35. 60
  36. 61
  37. 62
  38. 63
  39. 64
  40. 65
  41. 66
  42. 67
  43. 68
  44. 69
  45. 70
  46. 71
  47. 72
  48. 73
  49. 74
  50. 75
  51. 76
  52. 77
  53. 78
  54. 79
  55. 80
  56. 81
  57. 82
  58. 83
  59. 84
  60. 85
  61. 86
  62. 87
  63. 88
  64. 89
  65. 90
  66. 91
  67. 92
  68. 93
  69. 94
  70. 95
  71. 96
  72. 97
  73. 98
  74. 99
  75. 100
  76. 101
  77. 102
  78. 103
  79. 104
  80. 105
  81. 106
  82. 107
  83. 108
  84. 109
  85. 110
  86. 111
  87. 112
  88. 113
  89. 114
  90. 115
  91. 116
  92. 117
  93. 118
  94. 119
  95. 120
  96. 121
  97. 122
  98. 123
  99. 124
  100. 125
  101. 126
  102. 127
  103. 128
  104. 129
  105. 130
  106. 131
  107. 132
  108. 133
  109. 134
  110. 135
  111. 136
  112. 137
  113. 138
  114. 139
  115. 140
  116. 141
  117. 142
  118. 143
  119. 144
  120. 145
  121. 146
  122. 147
  123. 148
  124. 149
  125. 150
  126. 151
  127. 152
  128. 153
  129. 154
  130. 155
  131. 156
  132. 157
  133. 158
  134. 159
  135. 160
  136. 161
  137. 162
  138. 163
  139. 164
  140. 165
  141. 166
  142. 167
  143. 168
  144. 169
  145. 170
  146. 171
  147. 172
  148. 173
  149. 174
  150. 175
  151. 176
  152. 177
  153. 178
  154. 179
  155. 180
  156. 181
  157. 182
  158. 183
  159. 184
  160. 185
  161. 186
  162. 187
  163. 188
  164. 189
  165. 190
  166. 191
  167. 192
  168. 193
  169. 194
  170. 195
  171. 196
  172. 197
  173. 198
  174. 199
  175. 200
  176. 201
  177. 202
  178. 203
  179. 204
  180. 205
  181. 206
  182. 207
  183. 208
  184. 209
  185. 210
  186. 211
  187. 212
  188. 213
  189. 214
  190. 215
  191. 216
  192. 217
  193. 218
  194. 219
  195. 220
  196. 221
  197. 222
  198. 223
  199. 224
  200. 225
  201. 226
  202. 227
  203. 228
  204. 229
  205. 230
Fx.Reveal = new Class({ Extends: Fx.Morph, options: {/* onShow: function(thisElement){}, onHide: function(thisElement){}, onComplete: function(thisElement){}, heightOverride: null, widthOverride: null,*/ link: 'cancel', styles: ['padding', 'border', 'margin'], transitionOpacity: !Browser.ie6, mode: 'vertical', display: 'block', opacity: 1, hideInputs: Browser.ie ? 'select, input, textarea, object, embed' : null }, dissolve: function(){ if (!this.hiding && !this.showing){ if (this.element.getStyle('display') != 'none'){ this.hiding = true; this.showing = false; this.hidden = true; this.cssText = this.element.style.cssText; var startStyles = this.element.getComputedSize({ styles: this.options.styles, mode: this.options.mode }); if (this.options.transitionOpacity) startStyles.opacity = this.options.opacity; var zero = {}; Object.each(startStyles, function(style, name){ zero[name] = [style, 0]; }); this.element.setStyles({ display: this.options.display, overflow: 'hidden' }); var hideThese = this.options.hideInputs ? this.element.getElements(this.options.hideInputs) : null; if (hideThese) hideThese.setStyle('visibility', 'hidden'); this.$chain.unshift(function(){ if (this.hidden){ this.hiding = false; this.element.style.cssText = this.cssText; this.element.setStyle('display', 'none'); if (hideThese) hideThese.setStyle('visibility', 'visible'); } this.fireEvent('hide', this.element); this.callChain(); }.bind(this)); this.start(zero); } else { this.callChain.delay(10, this); this.fireEvent('complete', this.element); this.fireEvent('hide', this.element); } } else if (this.options.link == 'chain'){ this.chain(this.dissolve.bind(this)); } else if (this.options.link == 'cancel' && !this.hiding){ this.cancel(); this.dissolve(); } return this; }, reveal: function(){ if (!this.showing && !this.hiding){ if (this.element.getStyle('display') == 'none' || this.element.getStyle('visiblity') == 'hidden' || this.element.getStyle('opacity') == 0){ this.hiding = false; this.showing = true; this.hidden = false; this.cssText = this.element.style.cssText; var startStyles; this.element.measure(function(){ startStyles = this.element.getComputedSize({ styles: this.options.styles, mode: this.options.mode }); }.bind(this)); if (this.options.heightOverride != null) startStyles.height = this.options.heightOverride.toInt(); if (this.options.widthOverride != null) startStyles.width = this.options.widthOverride.toInt(); if (this.options.transitionOpacity){ this.element.setStyle('opacity', 0); startStyles.opacity = this.options.opacity; } var zero = { height: 0, display: this.options.display }; Object.each(startStyles, function(style, name){ zero[name] = 0; }); zero.overflow = 'hidden'; this.element.setStyles(zero); var hideThese = this.options.hideInputs ? this.element.getElements(this.options.hideInputs) : null; if (hideThese) hideThese.setStyle('visibility', 'hidden'); this.$chain.unshift(function(){ this.element.style.cssText = this.cssText; this.element.setStyle('display', this.options.display); if (!this.hidden) this.showing = false; if (hideThese) hideThese.setStyle('visibility', 'visible'); this.callChain(); this.fireEvent('show', this.element); }.bind(this)); this.start(startStyles); } else { this.callChain(); this.fireEvent('complete', this.element); this.fireEvent('show', this.element); } } else if (this.options.link == 'chain'){ this.chain(this.reveal.bind(this)); } else if (this.options.link == 'cancel' && !this.showing){ this.cancel(); this.reveal(); } return this; }, toggle: function(){ if (this.element.getStyle('display') == 'none' || this.element.getStyle('visiblity') == 'hidden' || this.element.getStyle('opacity') == 0){ this.reveal(); } else { this.dissolve(); } return this; }, cancel: function(){ this.parent.apply(this, arguments); this.element.style.cssText = this.cssText; this.hiding = false; this.showing = false; } }); Element.Properties.reveal = { set: function(options){ this.get('reveal').cancel().setOptions(options); return this; }, get: function(){ var reveal = this.retrieve('reveal'); if (!reveal){ reveal = new Fx.Reveal(this); this.store('reveal', reveal); } return reveal; } }; Element.Properties.dissolve = Element.Properties.reveal; Element.implement({ reveal: function(options){ this.get('reveal').setOptions(options).reveal(); return this; }, dissolve: function(options){ this.get('reveal').setOptions(options).dissolve(); return this; }, nix: function(options){ var params = Array.link(arguments, {destroy: Boolean.type, options: Object.type}); this.get('reveal').setOptions(options).dissolve().chain(function(){ this[params.destroy ? 'destroy' : 'dispose'](); }.bind(this)); return this; }, wink: function(){ var params = Array.link(arguments, {duration: Number.type, options: Object.type}); var reveal = this.get('reveal').setOptions(params.options); reveal.reveal().chain(function(){ (function(){ reveal.dissolve(); }).delay(params.duration || 2000); }); } });