Mercurial > wikked
annotate static/bootstrap/js/modal.js @ 149:d29e2f337b00
Updated to Bootstrap 3.0.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 12 Dec 2013 21:54:04 -0800 |
parents | |
children |
rev | line source |
---|---|
149
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 /* ======================================================================== |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 * Bootstrap: modal.js v3.0.3 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 * http://getbootstrap.com/javascript/#modals |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 * ======================================================================== |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 * Copyright 2013 Twitter, Inc. |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 * |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 * Licensed under the Apache License, Version 2.0 (the "License"); |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 * you may not use this file except in compliance with the License. |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 * You may obtain a copy of the License at |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 * |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 * http://www.apache.org/licenses/LICENSE-2.0 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 * |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 * Unless required by applicable law or agreed to in writing, software |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 * distributed under the License is distributed on an "AS IS" BASIS, |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 * See the License for the specific language governing permissions and |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 * limitations under the License. |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 * ======================================================================== */ |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 +function ($) { "use strict"; |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 // MODAL CLASS DEFINITION |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 // ====================== |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 var Modal = function (element, options) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 this.options = options |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 this.$element = $(element) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 this.$backdrop = |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 this.isShown = null |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 if (this.options.remote) this.$element.load(this.options.remote) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 Modal.DEFAULTS = { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 backdrop: true |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 , keyboard: true |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 , show: true |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 Modal.prototype.toggle = function (_relatedTarget) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
42 return this[!this.isShown ? 'show' : 'hide'](_relatedTarget) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
43 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
44 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 Modal.prototype.show = function (_relatedTarget) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 var that = this |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
48 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 this.$element.trigger(e) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 if (this.isShown || e.isDefaultPrevented()) return |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 this.isShown = true |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 this.escape() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 this.$element.on('click.dismiss.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 this.backdrop(function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 var transition = $.support.transition && that.$element.hasClass('fade') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 if (!that.$element.parent().length) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 that.$element.appendTo(document.body) // don't move modals dom position |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
66 that.$element.show() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
68 if (transition) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
69 that.$element[0].offsetWidth // force reflow |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
70 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
71 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
72 that.$element |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
73 .addClass('in') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
74 .attr('aria-hidden', false) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
75 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
76 that.enforceFocus() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
77 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
79 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
80 transition ? |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
81 that.$element.find('.modal-dialog') // wait for modal to slide in |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
82 .one($.support.transition.end, function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
83 that.$element.focus().trigger(e) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
84 }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
85 .emulateTransitionEnd(300) : |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
86 that.$element.focus().trigger(e) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
87 }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
88 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
89 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
90 Modal.prototype.hide = function (e) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 if (e) e.preventDefault() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
93 e = $.Event('hide.bs.modal') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
95 this.$element.trigger(e) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
97 if (!this.isShown || e.isDefaultPrevented()) return |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 this.isShown = false |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
101 this.escape() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
102 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
103 $(document).off('focusin.bs.modal') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
104 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
105 this.$element |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
106 .removeClass('in') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
107 .attr('aria-hidden', true) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
108 .off('click.dismiss.modal') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
109 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
110 $.support.transition && this.$element.hasClass('fade') ? |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
111 this.$element |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
112 .one($.support.transition.end, $.proxy(this.hideModal, this)) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
113 .emulateTransitionEnd(300) : |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
114 this.hideModal() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
115 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
116 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 Modal.prototype.enforceFocus = function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
118 $(document) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
119 .off('focusin.bs.modal') // guard against infinite focus loop |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
120 .on('focusin.bs.modal', $.proxy(function (e) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
121 if (this.$element[0] !== e.target && !this.$element.has(e.target).length) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
122 this.$element.focus() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
123 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
124 }, this)) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
125 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
126 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
127 Modal.prototype.escape = function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
128 if (this.isShown && this.options.keyboard) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
129 this.$element.on('keyup.dismiss.bs.modal', $.proxy(function (e) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
130 e.which == 27 && this.hide() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
131 }, this)) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
132 } else if (!this.isShown) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
133 this.$element.off('keyup.dismiss.bs.modal') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
134 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
135 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
136 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
137 Modal.prototype.hideModal = function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
138 var that = this |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
139 this.$element.hide() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
140 this.backdrop(function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
141 that.removeBackdrop() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
142 that.$element.trigger('hidden.bs.modal') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
143 }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
144 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
145 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
146 Modal.prototype.removeBackdrop = function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
147 this.$backdrop && this.$backdrop.remove() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
148 this.$backdrop = null |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
149 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
150 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
151 Modal.prototype.backdrop = function (callback) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
152 var that = this |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
153 var animate = this.$element.hasClass('fade') ? 'fade' : '' |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
154 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
155 if (this.isShown && this.options.backdrop) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
156 var doAnimate = $.support.transition && animate |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
157 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
158 this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
159 .appendTo(document.body) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
160 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
161 this.$element.on('click.dismiss.modal', $.proxy(function (e) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
162 if (e.target !== e.currentTarget) return |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
163 this.options.backdrop == 'static' |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
164 ? this.$element[0].focus.call(this.$element[0]) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
165 : this.hide.call(this) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
166 }, this)) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
167 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
168 if (doAnimate) this.$backdrop[0].offsetWidth // force reflow |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
169 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
170 this.$backdrop.addClass('in') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
171 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
172 if (!callback) return |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
173 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
174 doAnimate ? |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
175 this.$backdrop |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
176 .one($.support.transition.end, callback) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
177 .emulateTransitionEnd(150) : |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
178 callback() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
179 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
180 } else if (!this.isShown && this.$backdrop) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
181 this.$backdrop.removeClass('in') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
182 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
183 $.support.transition && this.$element.hasClass('fade')? |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
184 this.$backdrop |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
185 .one($.support.transition.end, callback) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
186 .emulateTransitionEnd(150) : |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
187 callback() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
188 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
189 } else if (callback) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
190 callback() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
191 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
192 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
193 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
194 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
195 // MODAL PLUGIN DEFINITION |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
196 // ======================= |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
197 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
198 var old = $.fn.modal |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
199 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
200 $.fn.modal = function (option, _relatedTarget) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
201 return this.each(function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
202 var $this = $(this) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
203 var data = $this.data('bs.modal') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
204 var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
205 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
206 if (!data) $this.data('bs.modal', (data = new Modal(this, options))) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
207 if (typeof option == 'string') data[option](_relatedTarget) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
208 else if (options.show) data.show(_relatedTarget) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
209 }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
210 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
211 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
212 $.fn.modal.Constructor = Modal |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
213 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
214 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
215 // MODAL NO CONFLICT |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
216 // ================= |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
217 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
218 $.fn.modal.noConflict = function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
219 $.fn.modal = old |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
220 return this |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
221 } |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
222 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
223 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
224 // MODAL DATA-API |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
225 // ============== |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
226 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
227 $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
228 var $this = $(this) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
229 var href = $this.attr('href') |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
230 var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
231 var option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
232 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
233 e.preventDefault() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
234 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
235 $target |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
236 .modal(option, this) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
237 .one('hide', function () { |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
238 $this.is(':visible') && $this.focus() |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
239 }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
240 }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
241 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
242 $(document) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
243 .on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
244 .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') }) |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
245 |
d29e2f337b00
Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
246 }(jQuery); |