bootstrap_modal_rails 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,337 +19,337 @@
19
19
 
20
20
  !function ($) {
21
21
 
22
- "use strict"; // jshint ;_;
23
-
24
- /* MODAL CLASS DEFINITION
25
- * ====================== */
26
-
27
- var Modal = function (element, options) {
28
- this.init(element, options);
29
- }
30
-
31
- Modal.prototype = {
32
-
33
- constructor: Modal,
34
-
35
- init: function (element, options) {
36
- this.options = options;
37
-
38
- this.$element = $(element)
39
- .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this));
40
-
41
- this.options.remote && this.$element.find('.modal-body').load(this.options.remote);
42
-
43
- var manager = typeof this.options.manager === 'function' ?
44
- this.options.manager.call(this) : this.options.manager;
45
-
46
- manager = manager.appendModal ?
47
- manager : $(manager).modalmanager().data('modalmanager');
48
-
49
- manager.appendModal(this);
50
- },
51
-
52
- toggle: function () {
53
- return this[!this.isShown ? 'show' : 'hide']();
54
- },
55
-
56
- show: function () {
57
- var that = this,
58
- e = $.Event('show');
59
-
60
- if (this.isShown) return;
61
-
62
- this.$element.triggerHandler(e);
63
-
64
- if (e.isDefaultPrevented()) return;
65
-
66
- if (this.options.width){
67
- this.$element.css('width', this.options.width);
68
-
69
- var that = this;
70
- this.$element.css('margin-left', function () {
71
- if (/%/ig.test(that.options.width)){
72
- return -(parseInt(that.options.width) / 2) + '%';
73
- } else {
74
- return -($(this).width() / 2) + 'px';
75
- }
76
- });
77
- }
78
-
79
- var prop = this.options.height ? 'height' : 'max-height';
80
-
81
- var value = this.options.height || this.options.maxHeight;
82
-
83
- if (value){
84
- this.$element.find('.modal-body')
85
- .css('overflow', 'auto')
86
- .css(prop, value);
87
- }
88
-
89
- this.escape();
90
-
91
- this.tab();
92
-
93
- this.options.loading && this.loading();
94
- },
95
-
96
- hide: function (e) {
97
- e && e.preventDefault();
98
-
99
- e = $.Event('hide');
100
-
101
- this.$element.triggerHandler(e);
102
-
103
- if (!this.isShown || e.isDefaultPrevented()) return (this.isShown = false);
104
-
105
- this.isShown = false;
106
-
107
- this.escape();
108
-
109
- this.tab();
110
-
111
- this.isLoading && this.loading();
112
-
113
- $(document).off('focusin.modal');
114
-
115
- this.$element
116
- .removeClass('in')
117
- .removeClass('animated')
118
- .removeClass(this.options.attentionAnimation)
119
- .removeClass('modal-overflow')
120
- .attr('aria-hidden', true);
121
-
122
- $.support.transition && this.$element.hasClass('fade') ?
123
- this.hideWithTransition() :
124
- this.hideModal();
125
- },
126
-
127
- tab: function () {
128
- var that = this;
129
-
130
- if (this.isShown && this.options.consumeTab) {
131
- this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) {
132
- if (e.keyCode && e.keyCode == 9){
133
- var $next = $(this),
134
- $rollover = $(this);
135
-
136
- that.$element.find('[data-tabindex]:enabled:not([readonly])').each(function (e) {
137
- if (!e.shiftKey){
138
- $next = $next.data('tabindex') < $(this).data('tabindex') ?
139
- $next = $(this) :
140
- $rollover = $(this);
141
- } else {
142
- $next = $next.data('tabindex') > $(this).data('tabindex') ?
143
- $next = $(this) :
144
- $rollover = $(this);
145
- }
146
- });
147
-
148
- $next[0] !== $(this)[0] ?
149
- $next.focus() : $rollover.focus();
150
-
151
- e.preventDefault();
152
-
153
- }
154
- });
155
- } else if (!this.isShown) {
156
- this.$element.off('keydown.tabindex.modal');
157
- }
158
- },
159
-
160
- escape: function () {
161
- var that = this;
162
- if (this.isShown && this.options.keyboard) {
163
- if (!this.$element.attr('tabindex')) this.$element.attr('tabindex', -1);
164
-
165
- this.$element.on('keyup.dismiss.modal', function (e) {
166
- e.which == 27 && that.hide();
167
- });
168
- } else if (!this.isShown) {
169
- this.$element.off('keyup.dismiss.modal')
170
- }
171
- },
172
-
173
- hideWithTransition: function () {
174
- var that = this
175
- , timeout = setTimeout(function () {
176
- that.$element.off($.support.transition.end)
177
- that.hideModal()
178
- }, 500);
179
-
180
- this.$element.one($.support.transition.end, function () {
181
- clearTimeout(timeout)
182
- that.hideModal()
183
- });
184
- },
185
-
186
- hideModal: function () {
187
- this.$element
188
- .hide()
189
- .triggerHandler('hidden');
190
-
191
-
192
- var prop = this.options.height ? 'height' : 'max-height';
193
- var value = this.options.height || this.options.maxHeight;
194
-
195
- if (value){
196
- this.$element.find('.modal-body')
197
- .css('overflow', '')
198
- .css(prop, '');
199
- }
200
-
201
- },
202
-
203
- removeLoading: function () {
204
- this.$loading.remove();
205
- this.$loading = null;
206
- this.isLoading = false;
207
- },
208
-
209
- loading: function (callback) {
210
- callback = callback || function () {};
211
-
212
- var animate = this.$element.hasClass('fade') ? 'fade' : '';
213
-
214
- if (!this.isLoading) {
215
- var doAnimate = $.support.transition && animate;
216
-
217
- this.$loading = $('<div class="loading-mask ' + animate + '">')
218
- .append(this.options.spinner)
219
- .appendTo(this.$element);
220
-
221
- if (doAnimate) this.$loading[0].offsetWidth // force reflow
222
-
223
- this.$loading.addClass('in')
224
-
225
- this.isLoading = true;
226
-
227
- doAnimate ?
228
- this.$loading.one($.support.transition.end, callback) :
229
- callback();
230
-
231
- } else if (this.isLoading && this.$loading) {
232
- this.$loading.removeClass('in');
233
-
234
- var that = this;
235
- $.support.transition && this.$element.hasClass('fade')?
236
- this.$loading.one($.support.transition.end, function () { that.removeLoading() }) :
237
- that.removeLoading();
238
-
239
- } else if (callback) {
240
- callback(this.isLoading);
241
- }
242
- },
243
-
244
- focus: function () {
245
- var $focusElem = this.$element.find(this.options.focusOn);
246
-
247
- $focusElem = $focusElem.length ? $focusElem : this.$element;
248
-
249
- $focusElem.focus();
250
- },
251
-
252
- attention: function (){
253
- // NOTE: transitionEnd with keyframes causes odd behaviour
254
-
255
- if (this.options.attentionAnimation){
256
- this.$element
257
- .removeClass('animated')
258
- .removeClass(this.options.attentionAnimation);
259
-
260
- var that = this;
261
-
262
- setTimeout(function () {
263
- that.$element
264
- .addClass('animated')
265
- .addClass(that.options.attentionAnimation);
266
- }, 0);
267
- }
268
-
269
-
270
- this.focus();
271
- },
272
-
273
-
274
- destroy: function () {
275
- var e = $.Event('destroy');
276
- this.$element.triggerHandler(e);
277
- if (e.isDefaultPrevented()) return;
278
-
279
- this.teardown();
280
- },
281
-
282
- teardown: function () {
283
- if (!this.$parent.length){
284
- this.$element.remove();
285
- this.$element = null;
286
- return;
287
- }
288
-
289
- if (this.$parent !== this.$element.parent()){
290
- this.$element.appendTo(this.$parent);
291
- }
292
-
293
- this.$element.off('.modal');
294
- this.$element.removeData('modal');
295
- this.$element
296
- .removeClass('in')
297
- .attr('aria-hidden', true);
298
- }
299
- }
300
-
301
-
302
- /* MODAL PLUGIN DEFINITION
303
- * ======================= */
304
-
305
- $.fn.modal = function (option) {
306
- return this.each(function () {
307
- var $this = $(this),
308
- data = $this.data('modal'),
309
- options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option);
310
-
311
- if (!data) $this.data('modal', (data = new Modal(this, options)))
312
- if (typeof option == 'string') data[option]()
313
- else if (options.show) data.show()
314
- })
315
- }
316
-
317
- $.fn.modal.defaults = {
318
- keyboard: true,
319
- backdrop: true,
320
- loading: false,
321
- show: true,
322
- width: null,
323
- height: null,
324
- maxHeight: null,
325
- modalOverflow: false,
326
- consumeTab: true,
327
- focusOn: null,
328
- attentionAnimation: 'shake',
329
- manager: 'body',
330
- spinner: '<div class="loading-spinner" style="width: 200px; margin-left: -100px;"><div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div></div>'
331
- }
332
-
333
- $.fn.modal.Constructor = Modal
334
-
335
-
336
- /* MODAL DATA-API
337
- * ============== */
338
-
339
- $(function () {
340
- $(document).off('.modal').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
341
- var $this = $(this),
342
- href = $this.attr('href'),
343
- $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))), //strip for ie7
344
- option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data());
345
-
346
- e.preventDefault();
347
- $target
348
- .modal(option)
349
- .one('hide', function () {
350
- $this.focus();
351
- })
352
- });
353
- });
22
+ "use strict"; // jshint ;_;
23
+
24
+ /* MODAL CLASS DEFINITION
25
+ * ====================== */
26
+
27
+ var Modal = function (element, options) {
28
+ this.init(element, options);
29
+ }
30
+
31
+ Modal.prototype = {
32
+
33
+ constructor: Modal,
34
+
35
+ init: function (element, options) {
36
+ this.options = options;
37
+
38
+ this.$element = $(element)
39
+ .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this));
40
+
41
+ this.options.remote && this.$element.find('.modal-body').load(this.options.remote);
42
+
43
+ var manager = typeof this.options.manager === 'function' ?
44
+ this.options.manager.call(this) : this.options.manager;
45
+
46
+ manager = manager.appendModal ?
47
+ manager : $(manager).modalmanager().data('modalmanager');
48
+
49
+ manager.appendModal(this);
50
+ },
51
+
52
+ toggle: function () {
53
+ return this[!this.isShown ? 'show' : 'hide']();
54
+ },
55
+
56
+ show: function () {
57
+ var that = this,
58
+ e = $.Event('show');
59
+
60
+ if (this.isShown) return;
61
+
62
+ this.$element.triggerHandler(e);
63
+
64
+ if (e.isDefaultPrevented()) return;
65
+
66
+ if (this.options.width){
67
+ this.$element.css('width', this.options.width);
68
+
69
+ var that = this;
70
+ this.$element.css('margin-left', function () {
71
+ if (/%/ig.test(that.options.width)){
72
+ return -(parseInt(that.options.width) / 2) + '%';
73
+ } else {
74
+ return -($(this).width() / 2) + 'px';
75
+ }
76
+ });
77
+ }
78
+
79
+ var prop = this.options.height ? 'height' : 'max-height';
80
+
81
+ var value = this.options.height || this.options.maxHeight;
82
+
83
+ if (value){
84
+ this.$element.find('.modal-body')
85
+ .css('overflow', 'auto')
86
+ .css(prop, value);
87
+ }
88
+
89
+ this.escape();
90
+
91
+ this.tab();
92
+
93
+ this.options.loading && this.loading();
94
+ },
95
+
96
+ hide: function (e) {
97
+ e && e.preventDefault();
98
+
99
+ e = $.Event('hide');
100
+
101
+ this.$element.triggerHandler(e);
102
+
103
+ if (!this.isShown || e.isDefaultPrevented()) return (this.isShown = false);
104
+
105
+ this.isShown = false;
106
+
107
+ this.escape();
108
+
109
+ this.tab();
110
+
111
+ this.isLoading && this.loading();
112
+
113
+ $(document).off('focusin.modal');
114
+
115
+ this.$element
116
+ .removeClass('in')
117
+ .removeClass('animated')
118
+ .removeClass(this.options.attentionAnimation)
119
+ .removeClass('modal-overflow')
120
+ .attr('aria-hidden', true);
121
+
122
+ $.support.transition && this.$element.hasClass('fade') ?
123
+ this.hideWithTransition() :
124
+ this.hideModal();
125
+ },
126
+
127
+ tab: function () {
128
+ var that = this;
129
+
130
+ if (this.isShown && this.options.consumeTab) {
131
+ this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) {
132
+ if (e.keyCode && e.keyCode == 9){
133
+ var $next = $(this),
134
+ $rollover = $(this);
135
+
136
+ that.$element.find('[data-tabindex]:enabled:not([readonly])').each(function (e) {
137
+ if (!e.shiftKey){
138
+ $next = $next.data('tabindex') < $(this).data('tabindex') ?
139
+ $next = $(this) :
140
+ $rollover = $(this);
141
+ } else {
142
+ $next = $next.data('tabindex') > $(this).data('tabindex') ?
143
+ $next = $(this) :
144
+ $rollover = $(this);
145
+ }
146
+ });
147
+
148
+ $next[0] !== $(this)[0] ?
149
+ $next.focus() : $rollover.focus();
150
+
151
+ e.preventDefault();
152
+
153
+ }
154
+ });
155
+ } else if (!this.isShown) {
156
+ this.$element.off('keydown.tabindex.modal');
157
+ }
158
+ },
159
+
160
+ escape: function () {
161
+ var that = this;
162
+ if (this.isShown && this.options.keyboard) {
163
+ if (!this.$element.attr('tabindex')) this.$element.attr('tabindex', -1);
164
+
165
+ this.$element.on('keyup.dismiss.modal', function (e) {
166
+ e.which == 27 && that.hide();
167
+ });
168
+ } else if (!this.isShown) {
169
+ this.$element.off('keyup.dismiss.modal')
170
+ }
171
+ },
172
+
173
+ hideWithTransition: function () {
174
+ var that = this
175
+ , timeout = setTimeout(function () {
176
+ that.$element.off($.support.transition.end)
177
+ that.hideModal()
178
+ }, 500);
179
+
180
+ this.$element.one($.support.transition.end, function () {
181
+ clearTimeout(timeout)
182
+ that.hideModal()
183
+ });
184
+ },
185
+
186
+ hideModal: function () {
187
+ this.$element
188
+ .hide()
189
+ .triggerHandler('hidden');
190
+
191
+
192
+ var prop = this.options.height ? 'height' : 'max-height';
193
+ var value = this.options.height || this.options.maxHeight;
194
+
195
+ if (value){
196
+ this.$element.find('.modal-body')
197
+ .css('overflow', '')
198
+ .css(prop, '');
199
+ }
200
+
201
+ },
202
+
203
+ removeLoading: function () {
204
+ this.$loading.remove();
205
+ this.$loading = null;
206
+ this.isLoading = false;
207
+ },
208
+
209
+ loading: function (callback) {
210
+ callback = callback || function () {};
211
+
212
+ var animate = this.$element.hasClass('fade') ? 'fade' : '';
213
+
214
+ if (!this.isLoading) {
215
+ var doAnimate = $.support.transition && animate;
216
+
217
+ this.$loading = $('<div class="loading-mask ' + animate + '">')
218
+ .append(this.options.spinner)
219
+ .appendTo(this.$element);
220
+
221
+ if (doAnimate) this.$loading[0].offsetWidth // force reflow
222
+
223
+ this.$loading.addClass('in')
224
+
225
+ this.isLoading = true;
226
+
227
+ doAnimate ?
228
+ this.$loading.one($.support.transition.end, callback) :
229
+ callback();
230
+
231
+ } else if (this.isLoading && this.$loading) {
232
+ this.$loading.removeClass('in');
233
+
234
+ var that = this;
235
+ $.support.transition && this.$element.hasClass('fade')?
236
+ this.$loading.one($.support.transition.end, function () { that.removeLoading() }) :
237
+ that.removeLoading();
238
+
239
+ } else if (callback) {
240
+ callback(this.isLoading);
241
+ }
242
+ },
243
+
244
+ focus: function () {
245
+ var $focusElem = this.$element.find(this.options.focusOn);
246
+
247
+ $focusElem = $focusElem.length ? $focusElem : this.$element;
248
+
249
+ $focusElem.focus();
250
+ },
251
+
252
+ attention: function (){
253
+ // NOTE: transitionEnd with keyframes causes odd behaviour
254
+
255
+ if (this.options.attentionAnimation){
256
+ this.$element
257
+ .removeClass('animated')
258
+ .removeClass(this.options.attentionAnimation);
259
+
260
+ var that = this;
261
+
262
+ setTimeout(function () {
263
+ that.$element
264
+ .addClass('animated')
265
+ .addClass(that.options.attentionAnimation);
266
+ }, 0);
267
+ }
268
+
269
+
270
+ this.focus();
271
+ },
272
+
273
+
274
+ destroy: function () {
275
+ var e = $.Event('destroy');
276
+ this.$element.triggerHandler(e);
277
+ if (e.isDefaultPrevented()) return;
278
+
279
+ this.teardown();
280
+ },
281
+
282
+ teardown: function () {
283
+ if (!this.$parent.length){
284
+ this.$element.remove();
285
+ this.$element = null;
286
+ return;
287
+ }
288
+
289
+ if (this.$parent !== this.$element.parent()){
290
+ this.$element.appendTo(this.$parent);
291
+ }
292
+
293
+ this.$element.off('.modal');
294
+ this.$element.removeData('modal');
295
+ this.$element
296
+ .removeClass('in')
297
+ .attr('aria-hidden', true);
298
+ }
299
+ }
300
+
301
+
302
+ /* MODAL PLUGIN DEFINITION
303
+ * ======================= */
304
+
305
+ $.fn.modal = function (option) {
306
+ return this.each(function () {
307
+ var $this = $(this),
308
+ data = $this.data('modal'),
309
+ options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option);
310
+
311
+ if (!data) $this.data('modal', (data = new Modal(this, options)))
312
+ if (typeof option == 'string') data[option]()
313
+ else if (options.show) data.show()
314
+ })
315
+ }
316
+
317
+ $.fn.modal.defaults = {
318
+ keyboard: true,
319
+ backdrop: true,
320
+ loading: false,
321
+ show: true,
322
+ width: null,
323
+ height: null,
324
+ maxHeight: null,
325
+ modalOverflow: false,
326
+ consumeTab: true,
327
+ focusOn: null,
328
+ attentionAnimation: 'shake',
329
+ manager: 'body',
330
+ spinner: '<div class="loading-spinner" style="width: 200px; margin-left: -100px;"><div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div></div>'
331
+ }
332
+
333
+ $.fn.modal.Constructor = Modal
334
+
335
+
336
+ /* MODAL DATA-API
337
+ * ============== */
338
+
339
+ $(function () {
340
+ $(document).off('.modal').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
341
+ var $this = $(this),
342
+ href = $this.attr('href'),
343
+ $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))), //strip for ie7
344
+ option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data());
345
+
346
+ e.preventDefault();
347
+ $target
348
+ .modal(option)
349
+ .one('hide', function () {
350
+ $this.focus();
351
+ })
352
+ });
353
+ });
354
354
 
355
355
  }(window.jQuery);