js/bootstrap-modal.js
changeset 0 ba8ab09f730e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/bootstrap-modal.js	Fri Jul 04 16:42:41 2014 +0400
     1.3 @@ -0,0 +1,247 @@
     1.4 +/* =========================================================
     1.5 + * bootstrap-modal.js v2.3.1
     1.6 + * http://twitter.github.com/bootstrap/javascript.html#modals
     1.7 + * =========================================================
     1.8 + * Copyright 2012 Twitter, Inc.
     1.9 + *
    1.10 + * Licensed under the Apache License, Version 2.0 (the "License");
    1.11 + * you may not use this file except in compliance with the License.
    1.12 + * You may obtain a copy of the License at
    1.13 + *
    1.14 + * http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + * Unless required by applicable law or agreed to in writing, software
    1.17 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.19 + * See the License for the specific language governing permissions and
    1.20 + * limitations under the License.
    1.21 + * ========================================================= */
    1.22 +
    1.23 +
    1.24 +!function ($) {
    1.25 +
    1.26 +  "use strict"; // jshint ;_;
    1.27 +
    1.28 +
    1.29 + /* MODAL CLASS DEFINITION
    1.30 +  * ====================== */
    1.31 +
    1.32 +  var Modal = function (element, options) {
    1.33 +    this.options = options
    1.34 +    this.$element = $(element)
    1.35 +      .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
    1.36 +    this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
    1.37 +  }
    1.38 +
    1.39 +  Modal.prototype = {
    1.40 +
    1.41 +      constructor: Modal
    1.42 +
    1.43 +    , toggle: function () {
    1.44 +        return this[!this.isShown ? 'show' : 'hide']()
    1.45 +      }
    1.46 +
    1.47 +    , show: function () {
    1.48 +        var that = this
    1.49 +          , e = $.Event('show')
    1.50 +
    1.51 +        this.$element.trigger(e)
    1.52 +
    1.53 +        if (this.isShown || e.isDefaultPrevented()) return
    1.54 +
    1.55 +        this.isShown = true
    1.56 +
    1.57 +        this.escape()
    1.58 +
    1.59 +        this.backdrop(function () {
    1.60 +          var transition = $.support.transition && that.$element.hasClass('fade')
    1.61 +
    1.62 +          if (!that.$element.parent().length) {
    1.63 +            that.$element.appendTo(document.body) //don't move modals dom position
    1.64 +          }
    1.65 +
    1.66 +          that.$element.show()
    1.67 +
    1.68 +          if (transition) {
    1.69 +            that.$element[0].offsetWidth // force reflow
    1.70 +          }
    1.71 +
    1.72 +          that.$element
    1.73 +            .addClass('in')
    1.74 +            .attr('aria-hidden', false)
    1.75 +
    1.76 +          that.enforceFocus()
    1.77 +
    1.78 +          transition ?
    1.79 +            that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown') }) :
    1.80 +            that.$element.focus().trigger('shown')
    1.81 +
    1.82 +        })
    1.83 +      }
    1.84 +
    1.85 +    , hide: function (e) {
    1.86 +        e && e.preventDefault()
    1.87 +
    1.88 +        var that = this
    1.89 +
    1.90 +        e = $.Event('hide')
    1.91 +
    1.92 +        this.$element.trigger(e)
    1.93 +
    1.94 +        if (!this.isShown || e.isDefaultPrevented()) return
    1.95 +
    1.96 +        this.isShown = false
    1.97 +
    1.98 +        this.escape()
    1.99 +
   1.100 +        $(document).off('focusin.modal')
   1.101 +
   1.102 +        this.$element
   1.103 +          .removeClass('in')
   1.104 +          .attr('aria-hidden', true)
   1.105 +
   1.106 +        $.support.transition && this.$element.hasClass('fade') ?
   1.107 +          this.hideWithTransition() :
   1.108 +          this.hideModal()
   1.109 +      }
   1.110 +
   1.111 +    , enforceFocus: function () {
   1.112 +        var that = this
   1.113 +        $(document).on('focusin.modal', function (e) {
   1.114 +          if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
   1.115 +            that.$element.focus()
   1.116 +          }
   1.117 +        })
   1.118 +      }
   1.119 +
   1.120 +    , escape: function () {
   1.121 +        var that = this
   1.122 +        if (this.isShown && this.options.keyboard) {
   1.123 +          this.$element.on('keyup.dismiss.modal', function ( e ) {
   1.124 +            e.which == 27 && that.hide()
   1.125 +          })
   1.126 +        } else if (!this.isShown) {
   1.127 +          this.$element.off('keyup.dismiss.modal')
   1.128 +        }
   1.129 +      }
   1.130 +
   1.131 +    , hideWithTransition: function () {
   1.132 +        var that = this
   1.133 +          , timeout = setTimeout(function () {
   1.134 +              that.$element.off($.support.transition.end)
   1.135 +              that.hideModal()
   1.136 +            }, 500)
   1.137 +
   1.138 +        this.$element.one($.support.transition.end, function () {
   1.139 +          clearTimeout(timeout)
   1.140 +          that.hideModal()
   1.141 +        })
   1.142 +      }
   1.143 +
   1.144 +    , hideModal: function () {
   1.145 +        var that = this
   1.146 +        this.$element.hide()
   1.147 +        this.backdrop(function () {
   1.148 +          that.removeBackdrop()
   1.149 +          that.$element.trigger('hidden')
   1.150 +        })
   1.151 +      }
   1.152 +
   1.153 +    , removeBackdrop: function () {
   1.154 +        this.$backdrop && this.$backdrop.remove()
   1.155 +        this.$backdrop = null
   1.156 +      }
   1.157 +
   1.158 +    , backdrop: function (callback) {
   1.159 +        var that = this
   1.160 +          , animate = this.$element.hasClass('fade') ? 'fade' : ''
   1.161 +
   1.162 +        if (this.isShown && this.options.backdrop) {
   1.163 +          var doAnimate = $.support.transition && animate
   1.164 +
   1.165 +          this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
   1.166 +            .appendTo(document.body)
   1.167 +
   1.168 +          this.$backdrop.click(
   1.169 +            this.options.backdrop == 'static' ?
   1.170 +              $.proxy(this.$element[0].focus, this.$element[0])
   1.171 +            : $.proxy(this.hide, this)
   1.172 +          )
   1.173 +
   1.174 +          if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
   1.175 +
   1.176 +          this.$backdrop.addClass('in')
   1.177 +
   1.178 +          if (!callback) return
   1.179 +
   1.180 +          doAnimate ?
   1.181 +            this.$backdrop.one($.support.transition.end, callback) :
   1.182 +            callback()
   1.183 +
   1.184 +        } else if (!this.isShown && this.$backdrop) {
   1.185 +          this.$backdrop.removeClass('in')
   1.186 +
   1.187 +          $.support.transition && this.$element.hasClass('fade')?
   1.188 +            this.$backdrop.one($.support.transition.end, callback) :
   1.189 +            callback()
   1.190 +
   1.191 +        } else if (callback) {
   1.192 +          callback()
   1.193 +        }
   1.194 +      }
   1.195 +  }
   1.196 +
   1.197 +
   1.198 + /* MODAL PLUGIN DEFINITION
   1.199 +  * ======================= */
   1.200 +
   1.201 +  var old = $.fn.modal
   1.202 +
   1.203 +  $.fn.modal = function (option) {
   1.204 +    return this.each(function () {
   1.205 +      var $this = $(this)
   1.206 +        , data = $this.data('modal')
   1.207 +        , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option)
   1.208 +      if (!data) $this.data('modal', (data = new Modal(this, options)))
   1.209 +      if (typeof option == 'string') data[option]()
   1.210 +      else if (options.show) data.show()
   1.211 +    })
   1.212 +  }
   1.213 +
   1.214 +  $.fn.modal.defaults = {
   1.215 +      backdrop: true
   1.216 +    , keyboard: true
   1.217 +    , show: true
   1.218 +  }
   1.219 +
   1.220 +  $.fn.modal.Constructor = Modal
   1.221 +
   1.222 +
   1.223 + /* MODAL NO CONFLICT
   1.224 +  * ================= */
   1.225 +
   1.226 +  $.fn.modal.noConflict = function () {
   1.227 +    $.fn.modal = old
   1.228 +    return this
   1.229 +  }
   1.230 +
   1.231 +
   1.232 + /* MODAL DATA-API
   1.233 +  * ============== */
   1.234 +
   1.235 +  $(document).on('click.modal.data-api', '[data-toggle="modal"]', function (e) {
   1.236 +    var $this = $(this)
   1.237 +      , href = $this.attr('href')
   1.238 +      , $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
   1.239 +      , option = $target.data('modal') ? 'toggle' : $.extend({ remote:!/#/.test(href) && href }, $target.data(), $this.data())
   1.240 +
   1.241 +    e.preventDefault()
   1.242 +
   1.243 +    $target
   1.244 +      .modal(option)
   1.245 +      .one('hide', function () {
   1.246 +        $this.focus()
   1.247 +      })
   1.248 +  })
   1.249 +
   1.250 +}(window.jQuery);