corrade-nucleus-nucleons – Blame information for rev 20

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