1 /* =========================================================
2 * bootstrap-modal.js v2.1.1
3 * http://twitter.github.com/bootstrap/javascript.html#modals
4 * =========================================================
5 * Copyright 2012 Twitter, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================================================= */
23 "use strict"; // jshint ;_;
26 /* MODAL CLASS DEFINITION
27 * ====================== */
29 var Modal = function (element, options) {
30 this.options = options
31 this.$element = $(element)
32 .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
33 this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
40 , toggle: function () {
41 return this[!this.isShown ? 'show' : 'hide']()
48 this.$element.trigger(e)
50 if (this.isShown || e.isDefaultPrevented()) return
52 $('body').addClass('modal-open')
58 this.backdrop(function () {
59 var transition = $.support.transition && that.$element.hasClass('fade')
61 if (!that.$element.parent().length) {
62 that.$element.appendTo(document.body) //don't move modals dom position
69 that.$element[0].offsetWidth // force reflow
74 .attr('aria-hidden', false)
80 that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) :
81 that.$element.trigger('shown')
86 , hide: function (e) {
87 e && e.preventDefault()
93 this.$element.trigger(e)
95 if (!this.isShown || e.isDefaultPrevented()) return
99 $('body').removeClass('modal-open')
103 $(document).off('focusin.modal')
107 .attr('aria-hidden', true)
109 $.support.transition && this.$element.hasClass('fade') ?
110 this.hideWithTransition() :
114 , enforceFocus: function () {
116 $(document).on('focusin.modal', function (e) {
117 if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
118 that.$element.focus()
123 , escape: function () {
125 if (this.isShown && this.options.keyboard) {
126 this.$element.on('keyup.dismiss.modal', function ( e ) {
127 e.which == 27 && that.hide()
129 } else if (!this.isShown) {
130 this.$element.off('keyup.dismiss.modal')
134 , hideWithTransition: function () {
136 , timeout = setTimeout(function () {
137 that.$element.off($.support.transition.end)
141 this.$element.one($.support.transition.end, function () {
142 clearTimeout(timeout)
147 , hideModal: function (that) {
155 , removeBackdrop: function () {
156 this.$backdrop.remove()
157 this.$backdrop = null
160 , backdrop: function (callback) {
162 , animate = this.$element.hasClass('fade') ? 'fade' : ''
164 if (this.isShown && this.options.backdrop) {
165 var doAnimate = $.support.transition && animate
167 this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
168 .appendTo(document.body)
170 if (this.options.backdrop != 'static') {
171 this.$backdrop.click($.proxy(this.hide, this))
174 if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
176 this.$backdrop.addClass('in')
179 this.$backdrop.one($.support.transition.end, callback) :
182 } else if (!this.isShown && this.$backdrop) {
183 this.$backdrop.removeClass('in')
185 $.support.transition && this.$element.hasClass('fade')?
186 this.$backdrop.one($.support.transition.end, $.proxy(this.removeBackdrop, this)) :
187 this.removeBackdrop()
189 } else if (callback) {
196 /* MODAL PLUGIN DEFINITION
197 * ======================= */
199 $.fn.modal = function (option) {
200 return this.each(function () {
202 , data = $this.data('modal')
203 , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option)
204 if (!data) $this.data('modal', (data = new Modal(this, options)))
205 if (typeof option == 'string') data[option]()
206 else if (options.show) data.show()
210 $.fn.modal.defaults = {
216 $.fn.modal.Constructor = Modal
223 $('body').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
225 , href = $this.attr('href')
226 , $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
227 , option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
233 .one('hide', function () {
240 /* ============================================================
241 * bootstrap-button.js v2.1.1
242 * http://twitter.github.com/bootstrap/javascript.html#buttons
243 * ============================================================
244 * Copyright 2012 Twitter, Inc.
246 * Licensed under the Apache License, Version 2.0 (the "License");
247 * you may not use this file except in compliance with the License.
248 * You may obtain a copy of the License at
250 * http://www.apache.org/licenses/LICENSE-2.0
252 * Unless required by applicable law or agreed to in writing, software
253 * distributed under the License is distributed on an "AS IS" BASIS,
254 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
255 * See the License for the specific language governing permissions and
256 * limitations under the License.
257 * ============================================================ */
262 "use strict"; // jshint ;_;
265 /* BUTTON PUBLIC CLASS DEFINITION
266 * ============================== */
268 var Button = function (element, options) {
269 this.$element = $(element)
270 this.options = $.extend({}, $.fn.button.defaults, options)
273 Button.prototype.setState = function (state) {
275 , $el = this.$element
277 , val = $el.is('input') ? 'val' : 'html'
279 state = state + 'Text'
280 data.resetText || $el.data('resetText', $el[val]())
282 $el[val](data[state] || this.options[state])
284 // push to event loop to allow forms to submit
285 setTimeout(function () {
286 state == 'loadingText' ?
287 $el.addClass(d).attr(d, d) :
288 $el.removeClass(d).removeAttr(d)
292 Button.prototype.toggle = function () {
293 var $parent = this.$element.closest('[data-toggle="buttons-radio"]')
297 .removeClass('active')
299 this.$element.toggleClass('active')
303 /* BUTTON PLUGIN DEFINITION
304 * ======================== */
306 $.fn.button = function (option) {
307 return this.each(function () {
309 , data = $this.data('button')
310 , options = typeof option == 'object' && option
311 if (!data) $this.data('button', (data = new Button(this, options)))
312 if (option == 'toggle') data.toggle()
313 else if (option) data.setState(option)
317 $.fn.button.defaults = {
318 loadingText: 'loading...'
321 $.fn.button.Constructor = Button
328 $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
329 var $btn = $(e.target)
330 if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
331 $btn.button('toggle')