bootstrap-modal.js 6.27 KiB
/* =========================================================
 * bootstrap-modal.js v2.1.2
 * http://twitter.github.com/bootstrap/javascript.html#modals
 * =========================================================
 * Copyright 2012 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.
 * ========================================================= */
!function ($) {
  "use strict"; // jshint ;_;
 /* MODAL CLASS DEFINITION
  * ====================== */
  var Modal = function (element, options) {
    this.options = options
    this.$element = $(element)
      .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
    this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
  Modal.prototype = {
      constructor: Modal
    , toggle: function () {
        return this[!this.isShown ? 'show' : 'hide']()
    , show: function () {
        var that = this
          , e = $.Event('show')
        this.$element.trigger(e)
        if (this.isShown || e.isDefaultPrevented()) return
        this.isShown = true
        this.escape()
        this.backdrop(function () {
          var transition = $.support.transition && that.$element.hasClass('fade')
          if (!that.$element.parent().length) {
            that.$element.appendTo(document.body) //don't move modals dom position
          that.$element
            .show()
          if (transition) {
            that.$element[0].offsetWidth // force reflow
          that.$element