2011-09-11 01:24:31 -04:00
|
|
|
/* =========================================================
|
2011-10-20 02:12:50 -04:00
|
|
|
* bootstrap-modal.js v2.0.0
|
2011-09-11 01:24:31 -04:00
|
|
|
* http://twitter.github.com/bootstrap/javascript.html#modal
|
|
|
|
* =========================================================
|
|
|
|
* Copyright 2011 Twitter, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
* ========================================================= */
|
|
|
|
|
|
|
|
|
2011-10-05 00:48:53 -04:00
|
|
|
!function( $ ){
|
2011-08-27 02:57:35 -04:00
|
|
|
|
|
|
|
/* MODAL PUBLIC CLASS DEFINITION
|
|
|
|
* ============================= */
|
|
|
|
|
2011-09-10 01:47:49 -04:00
|
|
|
var Modal = function ( content, options ) {
|
2011-10-05 00:48:53 -04:00
|
|
|
this.settings = $.extend({}, $.fn.modal.defaults, options)
|
2011-09-11 23:08:43 -04:00
|
|
|
this.$element = $(content)
|
2011-10-05 03:14:55 -04:00
|
|
|
.delegate('[data-modal-dismiss]', 'click', $.proxy(this.hide, this))
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-10-05 00:48:53 -04:00
|
|
|
if ( this.settings.show ) {
|
|
|
|
this.show()
|
2011-09-11 23:08:43 -04:00
|
|
|
}
|
2011-09-10 01:47:49 -04:00
|
|
|
|
2011-08-27 02:57:35 -04:00
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
Modal.prototype = {
|
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
toggle: function () {
|
|
|
|
return this[!this.isShown ? 'show' : 'hide']()
|
|
|
|
}
|
2011-09-11 01:14:57 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
, show: function () {
|
|
|
|
var that = this
|
|
|
|
this.isShown = true
|
|
|
|
this.$element.trigger('show')
|
2011-09-10 21:13:37 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
escape.call(this)
|
2011-10-20 00:56:06 -04:00
|
|
|
backdrop.call(this)
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
return this
|
|
|
|
}
|
2011-09-10 01:47:49 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
, hide: function (e) {
|
|
|
|
e && e.preventDefault()
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-10-05 00:48:53 -04:00
|
|
|
if ( !this.isShown ) {
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
var that = this
|
|
|
|
this.isShown = false
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
escape.call(this)
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
this.$element
|
|
|
|
.trigger('hide')
|
|
|
|
.removeClass('in')
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
function removeElement () {
|
|
|
|
that.$element
|
|
|
|
.hide()
|
|
|
|
.trigger('hidden')
|
2011-09-10 22:01:16 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
backdrop.call(that)
|
|
|
|
}
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
$.support.transition && this.$element.hasClass('fade') ?
|
2011-10-20 00:56:06 -04:00
|
|
|
this.$element.one($.support.transition.end, removeElement) :
|
2011-09-11 23:08:43 -04:00
|
|
|
removeElement()
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
return this
|
|
|
|
}
|
2011-08-27 02:57:35 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* MODAL PRIVATE METHODS
|
|
|
|
* ===================== */
|
|
|
|
|
2011-10-20 00:56:06 -04:00
|
|
|
function backdrop () {
|
2011-09-11 23:08:43 -04:00
|
|
|
var that = this
|
|
|
|
, animate = this.$element.hasClass('fade') ? 'fade' : ''
|
2011-10-20 00:56:06 -04:00
|
|
|
, callback = $.proxy(show, this)
|
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
if ( this.isShown && this.settings.backdrop ) {
|
2011-10-05 00:48:53 -04:00
|
|
|
var doAnimate = $.support.transition && animate
|
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
|
|
|
|
.appendTo(document.body)
|
|
|
|
|
2011-10-05 00:48:53 -04:00
|
|
|
if ( this.settings.backdrop != 'static' ) {
|
|
|
|
this.$backdrop.click($.proxy(this.hide, this))
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( doAnimate ) {
|
|
|
|
this.$backdrop[0].offsetWidth // force reflow
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$backdrop.addClass('in')
|
|
|
|
|
|
|
|
doAnimate ?
|
2011-10-20 00:56:06 -04:00
|
|
|
this.$backdrop.one($.support.transition.end, callback) :
|
2011-10-05 00:48:53 -04:00
|
|
|
callback()
|
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
} else if ( !this.isShown && this.$backdrop ) {
|
|
|
|
this.$backdrop.removeClass('in')
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
function removeElement() {
|
|
|
|
that.$backdrop.remove()
|
|
|
|
that.$backdrop = null
|
2011-08-27 02:57:35 -04:00
|
|
|
}
|
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
$.support.transition && this.$element.hasClass('fade')?
|
2011-10-20 00:56:06 -04:00
|
|
|
this.$backdrop.one($.support.transition.end, removeElement) :
|
2011-09-11 23:08:43 -04:00
|
|
|
removeElement()
|
|
|
|
} else if ( callback ) {
|
|
|
|
callback()
|
2011-08-27 02:57:35 -04:00
|
|
|
}
|
2011-09-11 23:08:43 -04:00
|
|
|
}
|
2011-08-27 02:57:35 -04:00
|
|
|
|
2011-10-20 00:56:06 -04:00
|
|
|
function show() {
|
|
|
|
var transition = $.support.transition && that.$element.hasClass('fade')
|
|
|
|
, that = this
|
|
|
|
|
|
|
|
this.$element
|
|
|
|
.appendTo(document.body)
|
|
|
|
.show()
|
|
|
|
|
|
|
|
if (transition) {
|
|
|
|
this.$element[0].offsetWidth // force reflow
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$element
|
|
|
|
.addClass('in')
|
|
|
|
|
|
|
|
transition ?
|
|
|
|
this.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) :
|
|
|
|
this.$element.trigger('shown')
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
function escape() {
|
|
|
|
var that = this
|
|
|
|
if ( this.isShown && this.settings.keyboard ) {
|
2011-10-05 00:48:53 -04:00
|
|
|
$(document).bind('keyup.modal', function ( e ) {
|
2011-09-11 23:08:43 -04:00
|
|
|
if ( e.which == 27 ) {
|
|
|
|
that.hide()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else if ( !this.isShown ) {
|
2011-10-05 00:48:53 -04:00
|
|
|
$(document).unbind('keyup.modal')
|
2011-09-11 23:08:43 -04:00
|
|
|
}
|
2011-08-27 02:57:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* MODAL PLUGIN DEFINITION
|
|
|
|
* ======================= */
|
|
|
|
|
2011-08-27 03:19:05 -04:00
|
|
|
$.fn.modal = function ( options ) {
|
2011-09-11 23:08:43 -04:00
|
|
|
var modal = this.data('modal')
|
|
|
|
|
|
|
|
if (!modal) {
|
|
|
|
|
|
|
|
if (typeof options == 'string') {
|
|
|
|
options = {
|
|
|
|
show: /show|toggle/.test(options)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.each(function () {
|
|
|
|
$(this).data('modal', new Modal(this, options))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( options === true ) {
|
|
|
|
return modal
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof options == 'string' ) {
|
|
|
|
modal[options]()
|
|
|
|
} else if ( modal ) {
|
|
|
|
modal.toggle()
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|
2011-08-27 02:57:35 -04:00
|
|
|
}
|
|
|
|
|
2011-09-10 01:47:49 -04:00
|
|
|
$.fn.modal.Modal = Modal
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
$.fn.modal.defaults = {
|
|
|
|
backdrop: false
|
2011-09-11 23:08:43 -04:00
|
|
|
, keyboard: false
|
2011-10-05 00:48:53 -04:00
|
|
|
, show: false
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
2011-09-11 23:08:43 -04:00
|
|
|
|
2011-10-05 00:48:53 -04:00
|
|
|
/* MODAL DATA-IMPLEMENTATION
|
|
|
|
* ========================= */
|
2011-09-11 23:08:43 -04:00
|
|
|
|
2011-10-20 00:56:06 -04:00
|
|
|
$(function () {
|
2011-09-11 23:08:43 -04:00
|
|
|
$('body').delegate('[data-controls-modal]', 'click', function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
var $this = $(this).data('show', true)
|
|
|
|
$('#' + $this.attr('data-controls-modal')).modal( $this.data() )
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2011-10-05 00:48:53 -04:00
|
|
|
}( window.jQuery || window.ender );
|