2011-09-11 07:24:31 +02:00
|
|
|
/* =========================================================
|
2011-09-12 20:15:32 +02:00
|
|
|
* bootstrap-modal.js v1.3.0
|
2011-09-11 07:24:31 +02: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-09-19 04:05:21 +02:00
|
|
|
!function( $ ){
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-10-30 02:49:35 +01:00
|
|
|
"use strict"
|
|
|
|
|
2011-08-29 01:47:38 +02:00
|
|
|
/* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
|
|
|
|
* ======================================================= */
|
|
|
|
|
|
|
|
var transitionEnd
|
|
|
|
|
2011-09-16 08:16:06 +02:00
|
|
|
$(document).ready(function () {
|
2011-08-29 01:47:38 +02:00
|
|
|
|
|
|
|
$.support.transition = (function () {
|
|
|
|
var thisBody = document.body || document.documentElement
|
|
|
|
, thisStyle = thisBody.style
|
|
|
|
, support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
|
|
|
|
return support
|
|
|
|
})()
|
|
|
|
|
|
|
|
// set CSS transition event type
|
|
|
|
if ( $.support.transition ) {
|
|
|
|
transitionEnd = "TransitionEnd"
|
|
|
|
if ( $.browser.webkit ) {
|
|
|
|
transitionEnd = "webkitTransitionEnd"
|
|
|
|
} else if ( $.browser.mozilla ) {
|
|
|
|
transitionEnd = "transitionend"
|
|
|
|
} else if ( $.browser.opera ) {
|
|
|
|
transitionEnd = "oTransitionEnd"
|
|
|
|
}
|
2011-08-27 08:57:35 +02:00
|
|
|
}
|
2011-08-29 01:47:38 +02:00
|
|
|
|
|
|
|
})
|
2011-08-27 08:57:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* MODAL PUBLIC CLASS DEFINITION
|
|
|
|
* ============================= */
|
|
|
|
|
2011-09-10 07:47:49 +02:00
|
|
|
var Modal = function ( content, options ) {
|
2011-10-05 06:24:59 +02:00
|
|
|
this.settings = $.extend({}, $.fn.modal.defaults, options)
|
2011-09-12 05:08:43 +02:00
|
|
|
this.$element = $(content)
|
|
|
|
.delegate('.close', 'click.modal', $.proxy(this.hide, this))
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-10-03 07:26:26 +02:00
|
|
|
if ( this.settings.show ) {
|
|
|
|
this.show()
|
2011-09-12 05:08:43 +02:00
|
|
|
}
|
2011-09-10 07:47:49 +02:00
|
|
|
|
2011-08-27 08:57:35 +02:00
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
Modal.prototype = {
|
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
toggle: function () {
|
|
|
|
return this[!this.isShown ? 'show' : 'hide']()
|
|
|
|
}
|
2011-09-11 07:14:57 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
, show: function () {
|
|
|
|
var that = this
|
|
|
|
this.isShown = true
|
|
|
|
this.$element.trigger('show')
|
2011-09-11 03:13:37 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
escape.call(this)
|
|
|
|
backdrop.call(this, function () {
|
2011-09-30 08:38:11 +02:00
|
|
|
var transition = $.support.transition && that.$element.hasClass('fade')
|
|
|
|
|
2011-09-11 04:01:16 +02:00
|
|
|
that.$element
|
2011-09-12 05:08:43 +02:00
|
|
|
.appendTo(document.body)
|
|
|
|
.show()
|
|
|
|
|
2011-09-30 08:38:11 +02:00
|
|
|
if (transition) {
|
2011-09-20 23:50:14 +02:00
|
|
|
that.$element[0].offsetWidth // force reflow
|
2011-09-19 06:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
that.$element
|
|
|
|
.addClass('in')
|
2011-09-30 08:38:11 +02:00
|
|
|
|
|
|
|
transition ?
|
|
|
|
that.$element.one(transitionEnd, function () { that.$element.trigger('shown') }) :
|
|
|
|
that.$element.trigger('shown')
|
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
})
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
return this
|
|
|
|
}
|
2011-09-10 07:47:49 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
, hide: function (e) {
|
|
|
|
e && e.preventDefault()
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-09-30 08:32:10 +02:00
|
|
|
if ( !this.isShown ) {
|
|
|
|
return this
|
2011-09-23 20:38:08 +02:00
|
|
|
}
|
2011-09-23 15:46:08 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
var that = this
|
|
|
|
this.isShown = false
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
escape.call(this)
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
this.$element
|
|
|
|
.trigger('hide')
|
|
|
|
.removeClass('in')
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
$.support.transition && this.$element.hasClass('fade') ?
|
2011-10-30 02:49:35 +01:00
|
|
|
this.$element.one(transitionEnd, $.proxy(hideModal, this)) :
|
|
|
|
hideModal.call(this)
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
return this
|
|
|
|
}
|
2011-08-27 08:57:35 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* MODAL PRIVATE METHODS
|
|
|
|
* ===================== */
|
|
|
|
|
2011-10-30 02:49:35 +01:00
|
|
|
function hideModal (that) {
|
|
|
|
this.$element
|
|
|
|
.hide()
|
|
|
|
.trigger('hidden')
|
|
|
|
|
|
|
|
backdrop.call(this)
|
|
|
|
}
|
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
function backdrop ( callback ) {
|
|
|
|
var that = this
|
|
|
|
, animate = this.$element.hasClass('fade') ? 'fade' : ''
|
|
|
|
if ( this.isShown && this.settings.backdrop ) {
|
2011-09-19 06:03:52 +02:00
|
|
|
var doAnimate = $.support.transition && animate
|
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
|
2011-09-17 23:20:51 +02:00
|
|
|
.appendTo(document.body)
|
|
|
|
|
|
|
|
if ( this.settings.backdrop != 'static' ) {
|
|
|
|
this.$backdrop.click($.proxy(this.hide, this))
|
2011-09-17 21:47:38 +02:00
|
|
|
}
|
2011-09-12 05:08:43 +02:00
|
|
|
|
2011-09-19 06:03:52 +02:00
|
|
|
if ( doAnimate ) {
|
2011-09-20 23:50:14 +02:00
|
|
|
this.$backdrop[0].offsetWidth // force reflow
|
2011-09-19 06:03:52 +02:00
|
|
|
}
|
|
|
|
|
2011-09-20 23:50:14 +02:00
|
|
|
this.$backdrop.addClass('in')
|
2011-09-19 06:03:52 +02:00
|
|
|
|
|
|
|
doAnimate ?
|
2011-09-20 23:50:14 +02:00
|
|
|
this.$backdrop.one(transitionEnd, callback) :
|
2011-09-19 06:03:52 +02:00
|
|
|
callback()
|
2011-09-17 23:20:51 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
} else if ( !this.isShown && this.$backdrop ) {
|
|
|
|
this.$backdrop.removeClass('in')
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
$.support.transition && this.$element.hasClass('fade')?
|
2011-10-30 02:49:35 +01:00
|
|
|
this.$backdrop.one(transitionEnd, $.proxy(removeBackdrop, this)) :
|
|
|
|
removeBackdrop.call(this)
|
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
} else if ( callback ) {
|
|
|
|
callback()
|
2011-08-27 08:57:35 +02:00
|
|
|
}
|
2011-09-12 05:08:43 +02:00
|
|
|
}
|
2011-08-27 08:57:35 +02:00
|
|
|
|
2011-10-30 02:49:35 +01:00
|
|
|
function removeBackdrop() {
|
|
|
|
this.$backdrop.remove()
|
|
|
|
this.$backdrop = null
|
|
|
|
}
|
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
function escape() {
|
|
|
|
var that = this
|
|
|
|
if ( this.isShown && this.settings.keyboard ) {
|
2011-09-19 06:13:56 +02:00
|
|
|
$(document).bind('keyup.modal', function ( e ) {
|
2011-09-12 05:08:43 +02:00
|
|
|
if ( e.which == 27 ) {
|
|
|
|
that.hide()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else if ( !this.isShown ) {
|
2011-09-19 06:13:56 +02:00
|
|
|
$(document).unbind('keyup.modal')
|
2011-09-12 05:08:43 +02:00
|
|
|
}
|
2011-08-27 08:57:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* MODAL PLUGIN DEFINITION
|
|
|
|
* ======================= */
|
|
|
|
|
2011-08-27 09:19:05 +02:00
|
|
|
$.fn.modal = function ( options ) {
|
2011-09-12 05:08:43 +02: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 08:57:35 +02:00
|
|
|
}
|
|
|
|
|
2011-09-10 07:47:49 +02:00
|
|
|
$.fn.modal.Modal = Modal
|
|
|
|
|
2011-08-27 22:03:06 +02:00
|
|
|
$.fn.modal.defaults = {
|
|
|
|
backdrop: false
|
2011-09-12 05:08:43 +02:00
|
|
|
, keyboard: false
|
2011-09-30 08:12:27 +02:00
|
|
|
, show: false
|
2011-08-27 22:03:06 +02:00
|
|
|
}
|
|
|
|
|
2011-09-12 05:08:43 +02:00
|
|
|
|
|
|
|
/* MODAL DATA- IMPLEMENTATION
|
|
|
|
* ========================== */
|
|
|
|
|
2011-09-16 08:16:06 +02:00
|
|
|
$(document).ready(function () {
|
2011-09-12 05:08:43 +02: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-09-23 15:46:08 +02:00
|
|
|
}( window.jQuery || window.ender );
|