Requires

Provides

Mask.js

Creates a mask element to cover another.

License:
MIT-style license
Authors:
Aaron Newton
  1. 29
  2. 30
  3. 31
  4. 32
  5. 33
  6. 34
  7. 35
  8. 36
  9. 37
  10. 38
  11. 39
  12. 40
  13. 41
  14. 42
  15. 43
  16. 44
  17. 45
  18. 46
  19. 47
  20. 48
  21. 49
  22. 50
  23. 51
  24. 52
  25. 53
  26. 54
  27. 55
  28. 56
  29. 57
  30. 58
  31. 59
  32. 60
  33. 61
  34. 62
  35. 63
  36. 64
  37. 65
  38. 66
  39. 67
  40. 68
  41. 69
  42. 70
  43. 71
  44. 72
  45. 73
  46. 74
  47. 75
  48. 76
  49. 77
  50. 78
  51. 79
  52. 80
  53. 81
  54. 82
  55. 83
  56. 84
  57. 85
  58. 86
  59. 87
  60. 88
  61. 89
  62. 90
  63. 91
  64. 92
  65. 93
  66. 94
  67. 95
  68. 96
  69. 97
  70. 98
  71. 99
  72. 100
  73. 101
  74. 102
  75. 103
  76. 104
  77. 105
  78. 106
  79. 107
  80. 108
  81. 109
  82. 110
  83. 111
  84. 112
  85. 113
  86. 114
  87. 115
  88. 116
  89. 117
  90. 118
  91. 119
  92. 120
  93. 121
  94. 122
  95. 123
  96. 124
  97. 125
  98. 126
  99. 127
  100. 128
  101. 129
  102. 130
  103. 131
  104. 132
  105. 133
  106. 134
  107. 135
  108. 136
  109. 137
  110. 138
  111. 139
  112. 140
  113. 141
  114. 142
  115. 143
  116. 144
  117. 145
  118. 146
  119. 147
  120. 148
  121. 149
  122. 150
  123. 151
  124. 152
  125. 153
  126. 154
  127. 155
  128. 156
  129. 157
  130. 158
  131. 159
  132. 160
  133. 161
  134. 162
  135. 163
  136. 164
  137. 165
  138. 166
  139. 167
  140. 168
  141. 169
  142. 170
  143. 171
  144. 172
  145. 173
  146. 174
  147. 175
  148. 176
  149. 177
  150. 178
  151. 179
  152. 180
  153. 181
  154. 182
  155. 183
  156. 184
  157. 185
  158. 186
  159. 187
  160. 188
  161. 189
  162. 190
  163. 191
  164. 192
  165. 193
  166. 194
  167. 195
  168. 196
  169. 197
var Mask = new Class({ Implements: [Options, Events], Binds: ['position'], options: {/* onShow: function(){}, onHide: function(){}, onDestroy: function(){}, onClick: function(){}, inject: { where: 'after', target: null, }, hideOnClick: false, id: null, destroyOnHide: false,*/ style: {}, 'class': 'mask', maskMargins: false, useIframeShim: true, iframeShimOptions: {} }, initialize: function(target, options){ this.target = document.id(target) || document.id(document.body); this.target.store('Mask', this); this.setOptions(options); this.render(); this.inject(); }, render: function(){ this.element = new Element('div', { 'class': this.options['class'], id: this.options.id || 'mask-' + Date.now(), styles: Object.merge(this.options.style, { display: 'none' }), events: { click: function(){ this.fireEvent('click'); if (this.options.hideOnClick) this.hide(); }.bind(this) } }); this.hidden = true; }, toElement: function(){ return this.element; }, inject: function(target, where){ where = where || this.options.inject ? this.options.inject.where : '' || this.target == document.body ? 'inside' : 'after'; target = target || this.options.inject ? this.options.inject.target : '' || this.target; this.element.inject(target, where); if (this.options.useIframeShim){ this.shim = new IframeShim(this.element, this.options.iframeShimOptions); this.addEvents({ show: this.shim.show.bind(this.shim), hide: this.shim.hide.bind(this.shim), destroy: this.shim.destroy.bind(this.shim) }); } }, position: function(){ this.resize(this.options.width, this.options.height); this.element.position({ relativeTo: this.target, position: 'topLeft', ignoreMargins: !this.options.maskMargins, ignoreScroll: this.target == document.body }); return this; }, resize: function(x, y){ var opt = { styles: ['padding', 'border'] }; if (this.options.maskMargins) opt.styles.push('margin'); var dim = this.target.getComputedSize(opt); if (this.target == document.body){ var win = window.getScrollSize(); if (dim.totalHeight < win.y) dim.totalHeight = win.y; if (dim.totalWidth < win.x) dim.totalWidth = win.x; } this.element.setStyles({ width: Array.pick([x, dim.totalWidth, dim.x]), height: Array.pick([y, dim.totalHeight, dim.y]) }); return this; }, show: function(){ if (!this.hidden) return this; window.addEvent('resize', this.position); this.position(); this.showMask.apply(this, arguments); return this; }, showMask: function(){ this.element.setStyle('display', 'block'); this.hidden = false; this.fireEvent('show'); }, hide: function(){ if (this.hidden) return this; window.removeEvent('resize', this.position); this.hideMask.apply(this, arguments); if (this.options.destroyOnHide) return this.destroy(); return this; }, hideMask: function(){ this.element.setStyle('display', 'none'); this.hidden = true; this.fireEvent('hide'); }, toggle: function(){ this[this.hidden ? 'show' : 'hide'](); }, destroy: function(){ this.hide(); this.element.destroy(); this.fireEvent('destroy'); this.target.eliminate('mask'); } }); Element.Properties.mask = { set: function(options){ var mask = this.retrieve('mask'); return this.eliminate('mask').store('mask:options', options); }, get: function(options){ if (options || !this.retrieve('mask')){ if (this.retrieve('mask')) this.retrieve('mask').destroy(); if (options || !this.retrieve('mask:options')) this.set('mask', options); this.store('mask', new Mask(this, this.retrieve('mask:options'))); } return this.retrieve('mask'); } }; Element.implement({ mask: function(options){ this.get('mask', options).show(); return this; }, unmask: function(){ this.get('mask').hide(); return this; } });