ink_ui_rails 2.1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +21 -0
  3. data/README.md +39 -0
  4. data/lib/ink_ui_rails.rb +8 -0
  5. data/lib/ink_ui_rails/version.rb +3 -0
  6. data/vendor/assets/fonts/font/FontAwesome.otf +0 -0
  7. data/vendor/assets/fonts/font/fontawesome-webfont.eot +0 -0
  8. data/vendor/assets/fonts/font/fontawesome-webfont.svg +399 -0
  9. data/vendor/assets/fonts/font/fontawesome-webfont.ttf +0 -0
  10. data/vendor/assets/fonts/font/fontawesome-webfont.woff +0 -0
  11. data/vendor/assets/fonts/font/ubuntu-b-webfont.eot +0 -0
  12. data/vendor/assets/fonts/font/ubuntu-b-webfont.svg +245 -0
  13. data/vendor/assets/fonts/font/ubuntu-b-webfont.ttf +0 -0
  14. data/vendor/assets/fonts/font/ubuntu-b-webfont.woff +0 -0
  15. data/vendor/assets/fonts/font/ubuntu-bi-webfont.eot +0 -0
  16. data/vendor/assets/fonts/font/ubuntu-bi-webfont.svg +245 -0
  17. data/vendor/assets/fonts/font/ubuntu-bi-webfont.ttf +0 -0
  18. data/vendor/assets/fonts/font/ubuntu-bi-webfont.woff +0 -0
  19. data/vendor/assets/fonts/font/ubuntu-c-webfont.eot +0 -0
  20. data/vendor/assets/fonts/font/ubuntu-c-webfont.svg +245 -0
  21. data/vendor/assets/fonts/font/ubuntu-c-webfont.ttf +0 -0
  22. data/vendor/assets/fonts/font/ubuntu-c-webfont.woff +0 -0
  23. data/vendor/assets/fonts/font/ubuntu-l-webfont.eot +0 -0
  24. data/vendor/assets/fonts/font/ubuntu-l-webfont.svg +245 -0
  25. data/vendor/assets/fonts/font/ubuntu-l-webfont.ttf +0 -0
  26. data/vendor/assets/fonts/font/ubuntu-l-webfont.woff +0 -0
  27. data/vendor/assets/fonts/font/ubuntu-li-webfont.eot +0 -0
  28. data/vendor/assets/fonts/font/ubuntu-li-webfont.svg +245 -0
  29. data/vendor/assets/fonts/font/ubuntu-li-webfont.ttf +0 -0
  30. data/vendor/assets/fonts/font/ubuntu-li-webfont.woff +0 -0
  31. data/vendor/assets/fonts/font/ubuntu-m-webfont.eot +0 -0
  32. data/vendor/assets/fonts/font/ubuntu-m-webfont.svg +245 -0
  33. data/vendor/assets/fonts/font/ubuntu-m-webfont.ttf +0 -0
  34. data/vendor/assets/fonts/font/ubuntu-m-webfont.woff +0 -0
  35. data/vendor/assets/fonts/font/ubuntu-mi-webfont.eot +0 -0
  36. data/vendor/assets/fonts/font/ubuntu-mi-webfont.svg +245 -0
  37. data/vendor/assets/fonts/font/ubuntu-mi-webfont.ttf +0 -0
  38. data/vendor/assets/fonts/font/ubuntu-mi-webfont.woff +0 -0
  39. data/vendor/assets/fonts/font/ubuntu-r-webfont.eot +0 -0
  40. data/vendor/assets/fonts/font/ubuntu-r-webfont.svg +245 -0
  41. data/vendor/assets/fonts/font/ubuntu-r-webfont.ttf +0 -0
  42. data/vendor/assets/fonts/font/ubuntu-r-webfont.woff +0 -0
  43. data/vendor/assets/fonts/font/ubuntu-ri-webfont.eot +0 -0
  44. data/vendor/assets/fonts/font/ubuntu-ri-webfont.svg +245 -0
  45. data/vendor/assets/fonts/font/ubuntu-ri-webfont.ttf +0 -0
  46. data/vendor/assets/fonts/font/ubuntu-ri-webfont.woff +0 -0
  47. data/vendor/assets/fonts/font/ubuntumono-b-webfont.eot +0 -0
  48. data/vendor/assets/fonts/font/ubuntumono-b-webfont.svg +242 -0
  49. data/vendor/assets/fonts/font/ubuntumono-b-webfont.ttf +0 -0
  50. data/vendor/assets/fonts/font/ubuntumono-b-webfont.woff +0 -0
  51. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.eot +0 -0
  52. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.svg +242 -0
  53. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.ttf +0 -0
  54. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.woff +0 -0
  55. data/vendor/assets/fonts/font/ubuntumono-r-webfont.eot +0 -0
  56. data/vendor/assets/fonts/font/ubuntumono-r-webfont.svg +242 -0
  57. data/vendor/assets/fonts/font/ubuntumono-r-webfont.ttf +0 -0
  58. data/vendor/assets/fonts/font/ubuntumono-r-webfont.woff +0 -0
  59. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.eot +0 -0
  60. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.svg +242 -0
  61. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.ttf +0 -0
  62. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.woff +0 -0
  63. data/vendor/assets/images/img/SAPOlogo.png +0 -0
  64. data/vendor/assets/images/img/favicon.ico +0 -0
  65. data/vendor/assets/images/img/home_bkg.png +0 -0
  66. data/vendor/assets/images/img/home_logo_IE.jpg +0 -0
  67. data/vendor/assets/images/img/icon_Sprite.png +0 -0
  68. data/vendor/assets/images/img/ink-favicon.ico +0 -0
  69. data/vendor/assets/images/img/logo_home.png +0 -0
  70. data/vendor/assets/images/img/shot_ink.png +0 -0
  71. data/vendor/assets/images/img/shot_intra.png +0 -0
  72. data/vendor/assets/images/img/shot_livebots.png +0 -0
  73. data/vendor/assets/images/img/shot_meo.png +0 -0
  74. data/vendor/assets/images/img/shot_musicbox.png +0 -0
  75. data/vendor/assets/images/img/shot_pessoa.png +0 -0
  76. data/vendor/assets/images/img/splash.1024x748.png +0 -0
  77. data/vendor/assets/images/img/splash.320x460.png +0 -0
  78. data/vendor/assets/images/img/splash.768x1004.png +0 -0
  79. data/vendor/assets/images/img/touch-icon.114.png +0 -0
  80. data/vendor/assets/images/img/touch-icon.16.png +0 -0
  81. data/vendor/assets/images/img/touch-icon.256.png +0 -0
  82. data/vendor/assets/images/img/touch-icon.57.png +0 -0
  83. data/vendor/assets/images/img/touch-icon.72.png +0 -0
  84. data/vendor/assets/javascripts/autoload.js +85 -0
  85. data/vendor/assets/javascripts/example.json +1174 -0
  86. data/vendor/assets/javascripts/holder.js +440 -0
  87. data/vendor/assets/javascripts/html5shiv-printshiv.js +496 -0
  88. data/vendor/assets/javascripts/html5shiv.js +298 -0
  89. data/vendor/assets/javascripts/ink-all.js +18015 -0
  90. data/vendor/assets/javascripts/ink-ui.js +7737 -0
  91. data/vendor/assets/javascripts/ink.aux.js +506 -0
  92. data/vendor/assets/javascripts/ink.close.js +54 -0
  93. data/vendor/assets/javascripts/ink.datepicker.js +1194 -0
  94. data/vendor/assets/javascripts/ink.datepicker.pt.js +32 -0
  95. data/vendor/assets/javascripts/ink.draggable.js +437 -0
  96. data/vendor/assets/javascripts/ink.droppable.js +193 -0
  97. data/vendor/assets/javascripts/ink.formvalidator.js +712 -0
  98. data/vendor/assets/javascripts/ink.gallery.js +757 -0
  99. data/vendor/assets/javascripts/ink.imagequery.js +259 -0
  100. data/vendor/assets/javascripts/ink.js +10278 -0
  101. data/vendor/assets/javascripts/ink.modal.js +628 -0
  102. data/vendor/assets/javascripts/ink.pagination.js +473 -0
  103. data/vendor/assets/javascripts/ink.progressbar.js +110 -0
  104. data/vendor/assets/javascripts/ink.smoothscroller.js +234 -0
  105. data/vendor/assets/javascripts/ink.sortablelist.js +338 -0
  106. data/vendor/assets/javascripts/ink.spy.js +123 -0
  107. data/vendor/assets/javascripts/ink.sticky.js +254 -0
  108. data/vendor/assets/javascripts/ink.table.js +621 -0
  109. data/vendor/assets/javascripts/ink.tabs.js +426 -0
  110. data/vendor/assets/javascripts/ink.toggle.js +218 -0
  111. data/vendor/assets/javascripts/ink.treeview.js +179 -0
  112. data/vendor/assets/javascripts/ink_ui.js +1 -0
  113. data/vendor/assets/javascripts/modernizr.js +815 -0
  114. data/vendor/assets/javascripts/prettify.js +28 -0
  115. data/vendor/assets/stylesheets/ink/_ink-ie7.css +1662 -0
  116. data/vendor/assets/stylesheets/ink/_ink.css +7496 -0
  117. data/vendor/assets/stylesheets/ink/ink_ui.scss.css +2 -0
  118. data/vendor/assets/stylesheets/ink_ui.scss.css +1 -0
  119. metadata +203 -0
@@ -0,0 +1,628 @@
1
+ /**
2
+ * @module Ink.UI.Modal_1
3
+ * @author inkdev AT sapo.pt
4
+ * @version 1
5
+ */
6
+ Ink.createModule('Ink.UI.Modal', '1', ['Ink.UI.Aux_1','Ink.Dom.Event_1','Ink.Dom.Css_1','Ink.Dom.Element_1','Ink.Dom.Selector_1','Ink.Util.Array_1'], function(Aux, Event, Css, Element, Selector, InkArray ) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * @class Ink.UI.Modal
11
+ * @constructor
12
+ * @version 1
13
+ * @uses Ink.UI.Aux
14
+ * @uses Ink.Dom.Event
15
+ * @uses Ink.Dom.Css
16
+ * @uses Ink.Dom.Element
17
+ * @uses Ink.Dom.Selector
18
+ * @uses Ink.Util.Array
19
+ * @param {String|DOMElement} selector
20
+ * @param {Object} [options] Options
21
+ * @param {String} [options.width] Default/Initial width. Ex: '600px'
22
+ * @param {String} [options.height] Default/Initial height. Ex: '400px'
23
+ * @param {String} [options.shadeClass] Custom class to be added to the div.ink-shade
24
+ * @param {String} [options.modalClass] Custom class to be added to the div.ink-modal
25
+ * @param {String} [options.trigger] CSS Selector to target elements that will trigger the Modal.
26
+ * @param {String} [options.triggerEvent] Trigger's event to be listened. 'click' is the default value. Ex: 'mouseover', 'touchstart'...
27
+ * @param {String} [options.markup] Markup to be placed in the Modal when created
28
+ * @param {Function} [options.onShow] Callback function to run when the Modal is opened.
29
+ * @param {Function} [options.onDismiss] Callback function to run when the Modal is closed.
30
+ * @param {Boolean} [options.closeOnClick] Determines if the Modal should close when clicked outside of it. 'false' by default.
31
+ * @param {Boolean} [options.responsive] Determines if the Modal should behave responsively (adapt to smaller viewports).
32
+ * @param {Boolean} [options.disableScroll] Determines if the Modal should 'disable' the page's scroll (not the Modal's body).
33
+ *
34
+ * @example
35
+ * <div class="ink-shade fade">
36
+ * <div id="test" class="ink-modal fade" data-trigger="#bModal" data-width="800px" data-height="400px">
37
+ * <div class="modal-header">
38
+ * <button class="modal-close ink-dismiss"></button>
39
+ * <h5>Modal windows can have headers</h5>
40
+ * </div>
41
+ * <div class="modal-body" id="modalContent">
42
+ * <h3>Please confirm your previous choice</h3>
43
+ * <p>"No," said Peleg, "and he hasn't been baptized right either, or it would have washed some of that devil's blue off his face."</p>
44
+ * <p>
45
+ * <img src="http://placehold.it/800x400" style="width: 100%;" alt="">
46
+ * </p>
47
+ * <p>"Do tell, now," cried Bildad, "is this Philistine a regular member of Deacon Deuteronomy's meeting? I never saw him going there, and I pass it every Lord's day."</p>
48
+ * <p>"I don't know anything about Deacon Deuteronomy or his meeting," said I; "all I know is, that Queequeg here is a born member of the First Congregational Church. He is a deacon himself, Queequeg is."</p>
49
+ * </div>
50
+ * <div class="modal-footer">
51
+ * <div class="push-right">
52
+ * <button class="ink-button info">Confirm</button>
53
+ * <button class="ink-button caution ink-dismiss">Cancel</button>
54
+ * </div>
55
+ * </div>
56
+ * </div>
57
+ * </div>
58
+ * <a href="#" id="bModal">Open modal</a>
59
+ * <script>
60
+ * Ink.requireModules( ['Ink.Dom.Selector_1','Ink.UI.Modal_1'], function( Selector, Modal ){
61
+ * var modalElement = Ink.s('#test');
62
+ * var modalObj = new Modal( modalElement );
63
+ * });
64
+ * </script>
65
+ */
66
+ var Modal = function(selector, options) {
67
+
68
+ if( (typeof selector !== 'string') && (typeof selector !== 'object') && (typeof options.markup === 'undefined') ){
69
+ throw 'Invalid Modal selector';
70
+ } else if(typeof selector === 'string'){
71
+ if( selector !== '' ){
72
+ this._element = Selector.select(selector);
73
+ if( this._element.length === 0 ){
74
+ /**
75
+ * From a developer's perspective this should be like it is...
76
+ * ... from a user's perspective, if it doesn't find elements, should just ignore it, no?
77
+ */
78
+ throw 'The Modal selector has not returned any elements';
79
+ } else {
80
+ this._element = this._element[0];
81
+ }
82
+ }
83
+ } else if( !!selector ){
84
+ this._element = selector;
85
+ }
86
+
87
+ this._options = {
88
+ /**
89
+ * Width, height and markup really optional, as they can be obtained by the element
90
+ */
91
+ width: undefined,
92
+ height: undefined,
93
+
94
+ /**
95
+ * To add extra classes
96
+ */
97
+ shadeClass: undefined,
98
+ modalClass: undefined,
99
+
100
+ /**
101
+ * Optional trigger properties
102
+ */
103
+ trigger: undefined,
104
+ triggerEvent: 'click',
105
+
106
+ /**
107
+ * Remaining options
108
+ */
109
+ markup: undefined,
110
+ onShow: undefined,
111
+ onDismiss: undefined,
112
+ closeOnClick: false,
113
+ responsive: true,
114
+ disableScroll: true
115
+ };
116
+
117
+
118
+ this._handlers = {
119
+ click: Ink.bindEvent(this._onClick, this),
120
+ keyDown: Ink.bindEvent(this._onKeyDown, this),
121
+ resize: Ink.bindEvent(this._onResize, this)
122
+ };
123
+
124
+ this._wasDismissed = false;
125
+
126
+ /**
127
+ * Modal Markup
128
+ */
129
+ if( this._element ){
130
+ this._markupMode = Css.hasClassName(this._element,'ink-modal'); // Check if the full modal comes from the markup
131
+ } else {
132
+ this._markupMode = false;
133
+ }
134
+
135
+
136
+
137
+
138
+ if( !this._markupMode ){
139
+
140
+
141
+ this._modalShadow = document.createElement('div');
142
+ this._modalShadowStyle = this._modalShadow.style;
143
+
144
+ this._modalDiv = document.createElement('div');
145
+ this._modalDivStyle = this._modalDiv.style;
146
+
147
+ if( !!this._element ){
148
+ this._options.markup = this._element.innerHTML;
149
+ }
150
+
151
+ /**
152
+ * Not in full markup mode, let's set the classes and css configurations
153
+ */
154
+ Css.addClassName( this._modalShadow,'ink-shade' );
155
+ Css.addClassName( this._modalDiv,'ink-modal' );
156
+ Css.addClassName( this._modalDiv,'ink-space' );
157
+
158
+ /**
159
+ * Applying the main css styles
160
+ */
161
+ // this._modalDivStyle.position = 'absolute';
162
+ this._modalShadow.appendChild( this._modalDiv);
163
+ document.body.appendChild( this._modalShadow );
164
+ } else {
165
+ this._modalDiv = this._element;
166
+ this._modalDivStyle = this._modalDiv.style;
167
+ this._modalShadow = this._modalDiv.parentNode;
168
+ this._modalShadowStyle = this._modalShadow.style;
169
+
170
+ this._contentContainer = Selector.select(".modal-body",this._modalDiv);
171
+ if( !this._contentContainer.length ){
172
+ throw 'Missing div with class "modal-body"';
173
+ }
174
+
175
+ this._contentContainer = this._contentContainer[0];
176
+ this._options.markup = this._contentContainer.innerHTML;
177
+
178
+ /**
179
+ * First, will handle the least important: The dataset
180
+ */
181
+ this._options = Ink.extendObj(this._options,Element.data(this._element));
182
+
183
+ }
184
+
185
+ /**
186
+ * Now, the most important, the initialization options
187
+ */
188
+ this._options = Ink.extendObj(this._options,options || {});
189
+
190
+ if( !this._markupMode ){
191
+ this.setContentMarkup(this._options.markup);
192
+ }
193
+
194
+ if( typeof this._options.shadeClass === 'string' ){
195
+
196
+ InkArray.each( this._options.shadeClass.split(' '), Ink.bind(function( item ){
197
+ Css.addClassName( this._modalShadow, item.trim() );
198
+ }, this));
199
+ }
200
+
201
+ if( typeof this._options.modalClass === 'string' ){
202
+ InkArray.each( this._options.modalClass.split(' '), Ink.bind(function( item ){
203
+ Css.addClassName( this._modalDiv, item.trim() );
204
+ }, this));
205
+ }
206
+
207
+ if( ("trigger" in this._options) && ( typeof this._options.trigger !== 'undefined' ) ){
208
+ var triggerElement,i;
209
+ if( typeof this._options.trigger === 'string' ){
210
+ triggerElement = Selector.select( this._options.trigger );
211
+ if( triggerElement.length > 0 ){
212
+ for( i=0; i<triggerElement.length; i++ ){
213
+ Event.observe( triggerElement[i], this._options.triggerEvent, Ink.bindEvent(this._init, this) );
214
+ }
215
+ }
216
+ }
217
+ } else {
218
+ this._init();
219
+ }
220
+ };
221
+
222
+ Modal.prototype = {
223
+
224
+ /**
225
+ * Init function called by the constructor
226
+ *
227
+ * @method _init
228
+ * @param {Event} [event] In case its fired by the trigger.
229
+ * @private
230
+ */
231
+ _init: function(event) {
232
+
233
+ if( event ){ Event.stop(event); }
234
+
235
+ var elem = (document.compatMode === "CSS1Compat") ? document.documentElement : document.body;
236
+
237
+ this._resizeTimeout = null;
238
+
239
+ Css.addClassName( this._modalShadow,'ink-shade' );
240
+ this._modalShadowStyle.display = this._modalDivStyle.display = 'block';
241
+ setTimeout(Ink.bind(function(){
242
+ Css.addClassName( this._modalShadow,'visible' );
243
+ Css.addClassName( this._modalDiv,'visible' );
244
+ }, this),100);
245
+
246
+ /**
247
+ * Fallback to the old one
248
+ */
249
+ this._contentElement = this._modalDiv;
250
+ this._shadeElement = this._modalShadow;
251
+
252
+ /**
253
+ * Setting the content of the modal
254
+ */
255
+ this.setContentMarkup( this._options.markup );
256
+
257
+ /**
258
+ * If any size has been user-defined, let's set them as max-width and max-height
259
+ */
260
+ if( typeof this._options.width !== 'undefined' ){
261
+ this._modalDivStyle.width = this._options.width;
262
+ if( this._options.width.indexOf('%') === -1 ){
263
+ this._modalDivStyle.maxWidth = Element.elementWidth(this._modalDiv) + 'px';
264
+ }
265
+ } else {
266
+ this._modalDivStyle.maxWidth = this._modalDivStyle.width = Element.elementWidth(this._modalDiv)+'px';
267
+ }
268
+
269
+ if( parseInt(elem.clientWidth,10) <= parseInt(this._modalDivStyle.width,10) ){
270
+ this._modalDivStyle.width = (~~(parseInt(elem.clientWidth,10)*0.9))+'px';
271
+ }
272
+
273
+ if( typeof this._options.height !== 'undefined' ){
274
+ this._modalDivStyle.height = this._options.height;
275
+ if( this._options.height.indexOf('%') === -1 ){
276
+ this._modalDivStyle.maxHeight = Element.elementHeight(this._modalDiv) + 'px';
277
+ }
278
+ } else {
279
+ this._modalDivStyle.maxHeight = this._modalDivStyle.height = Element.elementHeight(this._modalDiv) + 'px';
280
+ }
281
+
282
+ if( parseInt(elem.clientHeight,10) <= parseInt(this._modalDivStyle.height,10) ){
283
+ this._modalDivStyle.height = (~~(parseInt(elem.clientHeight,10)*0.9))+'px';
284
+ }
285
+
286
+ this.originalStatus = {
287
+ viewportHeight: parseInt(elem.clientHeight,10),
288
+ viewportWidth: parseInt(elem.clientWidth,10),
289
+ width: parseInt(this._modalDivStyle.maxWidth,10),
290
+ height: parseInt(this._modalDivStyle.maxHeight,10)
291
+ };
292
+
293
+ /**
294
+ * Let's 'resize' it:
295
+ */
296
+ if(this._options.responsive) {
297
+ this._onResize(true);
298
+ Event.observe( window,'resize',this._handlers.resize );
299
+ } else {
300
+ this._resizeContainer();
301
+ this._reposition();
302
+ }
303
+
304
+ if (this._options.onShow) {
305
+ this._options.onShow(this);
306
+ }
307
+
308
+ if(this._options.disableScroll) {
309
+ this._disableScroll();
310
+ }
311
+
312
+ // subscribe events
313
+ Event.observe(this._shadeElement, 'click', this._handlers.click);
314
+ Event.observe(document, 'keydown', this._handlers.keyDown);
315
+
316
+ Aux.registerInstance(this, this._shadeElement, 'modal');
317
+ },
318
+
319
+ /**
320
+ * Responsible for repositioning the modal
321
+ *
322
+ * @method _reposition
323
+ * @private
324
+ */
325
+ _reposition: function(){
326
+
327
+ this._modalDivStyle.top = this._modalDivStyle.left = '50%';
328
+
329
+ this._modalDivStyle.marginTop = '-' + ( ~~( Element.elementHeight(this._modalDiv)/2) ) + 'px';
330
+ this._modalDivStyle.marginLeft = '-' + ( ~~( Element.elementWidth(this._modalDiv)/2) ) + 'px';
331
+ },
332
+
333
+ /**
334
+ * Responsible for resizing the modal
335
+ *
336
+ * @method _onResize
337
+ * @param {Boolean|Event} runNow Its executed in the begining to resize/reposition accordingly to the viewport. But usually it's an event object.
338
+ * @private
339
+ */
340
+ _onResize: function( runNow ){
341
+
342
+ if( typeof runNow === 'boolean' ){
343
+ this._timeoutResizeFunction.call(this);
344
+ } else if( !this._resizeTimeout && (typeof runNow === 'object') ){
345
+ this._resizeTimeout = setTimeout(Ink.bind(this._timeoutResizeFunction, this),250);
346
+ }
347
+ },
348
+
349
+ /**
350
+ * Timeout Resize Function
351
+ *
352
+ * @method _timeoutResizeFunction
353
+ * @private
354
+ */
355
+ _timeoutResizeFunction: function(){
356
+ /**
357
+ * Getting the current viewport size
358
+ */
359
+ var
360
+ elem = (document.compatMode === "CSS1Compat") ? document.documentElement : document.body,
361
+ currentViewportHeight = parseInt(elem.clientHeight,10),
362
+ currentViewportWidth = parseInt(elem.clientWidth,10)
363
+ ;
364
+
365
+ if( ( currentViewportWidth > this.originalStatus.width ) /* && ( parseInt(this._modalDivStyle.maxWidth,10) >= Element.elementWidth(this._modalDiv) )*/ ){
366
+ /**
367
+ * The viewport width has expanded
368
+ */
369
+ this._modalDivStyle.width = this._modalDivStyle.maxWidth;
370
+
371
+ } else {
372
+ /**
373
+ * The viewport width has not changed or reduced
374
+ */
375
+ //this._modalDivStyle.width = (( currentViewportWidth * this.originalStatus.width ) / this.originalStatus.viewportWidth ) + 'px';
376
+ this._modalDivStyle.width = (~~( currentViewportWidth * 0.9)) + 'px';
377
+ }
378
+
379
+ if( (currentViewportHeight > this.originalStatus.height) && (parseInt(this._modalDivStyle.maxHeight,10) >= Element.elementHeight(this._modalDiv) ) ){
380
+
381
+ /**
382
+ * The viewport height has expanded
383
+ */
384
+ //this._modalDivStyle.maxHeight =
385
+ this._modalDivStyle.height = this._modalDivStyle.maxHeight;
386
+
387
+ } else {
388
+ /**
389
+ * The viewport height has not changed, or reduced
390
+ */
391
+ this._modalDivStyle.height = (~~( currentViewportHeight * 0.9)) + 'px';
392
+ }
393
+
394
+ this._resizeContainer();
395
+ this._reposition();
396
+ this._resizeTimeout = undefined;
397
+ },
398
+
399
+ /**
400
+ * Navigation click handler
401
+ *
402
+ * @method _onClick
403
+ * @param {Event} ev
404
+ * @private
405
+ */
406
+ _onClick: function(ev) {
407
+ var tgtEl = Event.element(ev);
408
+
409
+ if (Css.hasClassName(tgtEl, 'ink-close') || Css.hasClassName(tgtEl, 'ink-dismiss') ||
410
+ (
411
+ this._options.closeOnClick &&
412
+ (!Element.descendantOf(this._shadeElement, tgtEl) || (tgtEl === this._shadeElement))
413
+ )
414
+ ) {
415
+ var
416
+ alertsInTheModal = Selector.select('.ink-alert',this._shadeElement),
417
+ alertsLength = alertsInTheModal.length
418
+ ;
419
+ for( var i = 0; i < alertsLength; i++ ){
420
+ if( Element.descendantOf(alertsInTheModal[i], tgtEl) ){
421
+ return;
422
+ }
423
+ }
424
+
425
+ Event.stop(ev);
426
+ this.dismiss();
427
+ }
428
+ },
429
+
430
+ /**
431
+ * Responsible for handling the escape key pressing.
432
+ *
433
+ * @method _onKeyDown
434
+ * @param {Event} ev
435
+ * @private
436
+ */
437
+ _onKeyDown: function(ev) {
438
+ if (ev.keyCode !== 27 || this._wasDismissed) { return; }
439
+ this.dismiss();
440
+ },
441
+
442
+ /**
443
+ * Responsible for setting the size of the modal (and position) based on the viewport.
444
+ *
445
+ * @method _resizeContainer
446
+ * @private
447
+ */
448
+ _resizeContainer: function()
449
+ {
450
+
451
+ this._contentElement.style.overflow = this._contentElement.style.overflowX = this._contentElement.style.overflowY = 'hidden';
452
+ var containerHeight = Element.elementHeight(this._modalDiv);
453
+
454
+ this._modalHeader = Selector.select('.modal-header',this._modalDiv);
455
+ if( this._modalHeader.length>0 ){
456
+ this._modalHeader = this._modalHeader[0];
457
+ containerHeight -= Element.elementHeight(this._modalHeader);
458
+ }
459
+
460
+ this._modalFooter = Selector.select('.modal-footer',this._modalDiv);
461
+ if( this._modalFooter.length>0 ){
462
+ this._modalFooter = this._modalFooter[0];
463
+ containerHeight -= Element.elementHeight(this._modalFooter);
464
+ }
465
+
466
+ this._contentContainer.style.height = containerHeight + 'px';
467
+ if( containerHeight !== Element.elementHeight(this._contentContainer) ){
468
+ this._contentContainer.style.height = ~~(containerHeight - (Element.elementHeight(this._contentContainer) - containerHeight)) + 'px';
469
+ }
470
+
471
+ if( this._markupMode ){ return; }
472
+
473
+ this._contentContainer.style.overflow = this._contentContainer.style.overflowX = 'hidden';
474
+ this._contentContainer.style.overflowY = 'auto';
475
+ this._contentElement.style.overflow = this._contentElement.style.overflowX = this._contentElement.style.overflowY = 'visible';
476
+ },
477
+
478
+ /**
479
+ * Responsible for 'disabling' the page scroll
480
+ *
481
+ * @method _disableScroll
482
+ * @private
483
+ */
484
+ _disableScroll: function()
485
+ {
486
+ this._oldScrollPos = Element.scroll();
487
+ this._onScrollBinded = Ink.bindEvent(function(event) {
488
+ var tgtEl = Event.element(event);
489
+
490
+ if( !Element.descendantOf(this._modalShadow, tgtEl) ){
491
+ Event.stop(event);
492
+ window.scrollTo(this._oldScrollPos[0], this._oldScrollPos[1]);
493
+ }
494
+ },this);
495
+ Event.observe(window, 'scroll', this._onScrollBinded);
496
+ Event.observe(document, 'touchmove', this._onScrollBinded);
497
+ },
498
+
499
+ /**************
500
+ * PUBLIC API *
501
+ **************/
502
+
503
+ /**
504
+ * Dismisses the modal
505
+ *
506
+ * @method dismiss
507
+ * @public
508
+ */
509
+ dismiss: function() {
510
+ if (this._options.onDismiss) {
511
+ this._options.onDismiss(this);
512
+ }
513
+
514
+ if(this._options.disableScroll) {
515
+ Event.stopObserving(window, 'scroll', this._onScrollBinded);
516
+ Event.stopObserving(document, 'touchmove', this._onScrollBinded);
517
+ }
518
+
519
+ if( this._options.responsive ){
520
+ Event.stopObserving(window, 'resize', this._handlers.resize);
521
+ }
522
+
523
+ // this._modalShadow.parentNode.removeChild(this._modalShadow);
524
+
525
+ if( !this._markupMode ){
526
+ this._modalShadow.parentNode.removeChild(this._modalShadow);
527
+ this.destroy();
528
+ } else {
529
+ Css.removeClassName( this._modalDiv, 'visible' );
530
+ Css.removeClassName( this._modalShadow, 'visible' );
531
+
532
+ var
533
+ dismissInterval,
534
+ transitionEndFn = Ink.bindEvent(function(){
535
+ if( !dismissInterval ){ return; }
536
+ this._modalShadowStyle.display = 'none';
537
+ Event.stopObserving(document,'transitionend',transitionEndFn);
538
+ Event.stopObserving(document,'oTransitionEnd',transitionEndFn);
539
+ Event.stopObserving(document,'webkitTransitionEnd',transitionEndFn);
540
+ clearInterval(dismissInterval);
541
+ dismissInterval = undefined;
542
+ }, this)
543
+ ;
544
+
545
+ Event.observe(document,'transitionend',transitionEndFn);
546
+ Event.observe(document,'oTransitionEnd',transitionEndFn);
547
+ Event.observe(document,'webkitTransitionEnd',transitionEndFn);
548
+
549
+ if( !dismissInterval ){
550
+ dismissInterval = setInterval(Ink.bind(function(){
551
+ if( this._modalShadowStyle.opacity > 0 ){
552
+ return;
553
+ } else {
554
+ this._modalShadowStyle.display = 'none';
555
+ clearInterval(dismissInterval);
556
+ dismissInterval = undefined;
557
+ }
558
+
559
+ }, this),500);
560
+ }
561
+ }
562
+ },
563
+
564
+ /**
565
+ * Removes the modal from the DOM
566
+ *
567
+ * @method destroy
568
+ * @public
569
+ */
570
+ destroy: function() {
571
+ Aux.unregisterInstance(this._instanceId);
572
+
573
+ },
574
+
575
+ /**
576
+ * Returns the content DOM element
577
+ *
578
+ * @method getContentElement
579
+ * @return {DOMElement} Modal main cointainer.
580
+ * @public
581
+ */
582
+ getContentElement: function() {
583
+ return this._contentContainer;
584
+ },
585
+
586
+ /**
587
+ * Replaces the content markup
588
+ *
589
+ * @method setContentMarkup
590
+ * @param {String} contentMarkup
591
+ * @public
592
+ */
593
+ setContentMarkup: function(contentMarkup) {
594
+ if( !this._markupMode ){
595
+ this._modalDiv.innerHTML = [contentMarkup].join('');
596
+ this._contentContainer = Selector.select(".modal-body",this._modalDiv);
597
+ if( !this._contentContainer.length ){
598
+ // throw 'Missing div with class "modal-body"';
599
+ var tempHeader = Selector.select(".modal-header",this._modalDiv);
600
+ var tempFooter = Selector.select(".modal-footer",this._modalDiv);
601
+
602
+ InkArray.each(tempHeader,Ink.bind(function( element ){ element.parentNode.removeChild(element); },this));
603
+ InkArray.each(tempFooter,Ink.bind(function( element ){ element.parentNode.removeChild(element); },this));
604
+
605
+ var body = document.createElement('div');
606
+ Css.addClassName(body,'modal-body');
607
+ body.innerHTML = this._modalDiv.innerHTML;
608
+ this._modalDiv.innerHTML = '';
609
+
610
+ InkArray.each(tempHeader,Ink.bind(function( element ){ this._modalDiv.appendChild(element); },this));
611
+ this._modalDiv.appendChild(body);
612
+ InkArray.each(tempFooter,Ink.bind(function( element ){ this._modalDiv.appendChild(element); },this));
613
+
614
+ this._contentContainer = Selector.select(".modal-body",this._modalDiv);
615
+ }
616
+ this._contentContainer = this._contentContainer[0];
617
+ } else {
618
+ this._contentContainer.innerHTML = [contentMarkup].join('');
619
+ }
620
+ this._contentElement = this._modalDiv;
621
+ this._resizeContainer();
622
+ }
623
+
624
+ };
625
+
626
+ return Modal;
627
+
628
+ });