bootstrap-source/bootstrap-3.0.3/js/modal.js
branchlanding-page-2014
changeset 78 b28d5c14c5c2
parent 54 0ded9d7748b7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/bootstrap-source/bootstrap-3.0.3/js/modal.js	Fri Jan 17 11:59:43 2014 +0100
     1.3 @@ -0,0 +1,246 @@
     1.4 +/* ========================================================================
     1.5 + * Bootstrap: modal.js v3.0.3
     1.6 + * http://getbootstrap.com/javascript/#modals
     1.7 + * ========================================================================
     1.8 + * Copyright 2013 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 ($) { "use strict";
    1.25 +
    1.26 +  // MODAL CLASS DEFINITION
    1.27 +  // ======================
    1.28 +
    1.29 +  var Modal = function (element, options) {
    1.30 +    this.options   = options
    1.31 +    this.$element  = $(element)
    1.32 +    this.$backdrop =
    1.33 +    this.isShown   = null
    1.34 +
    1.35 +    if (this.options.remote) this.$element.load(this.options.remote)
    1.36 +  }
    1.37 +
    1.38 +  Modal.DEFAULTS = {
    1.39 +      backdrop: true
    1.40 +    , keyboard: true
    1.41 +    , show: true
    1.42 +  }
    1.43 +
    1.44 +  Modal.prototype.toggle = function (_relatedTarget) {
    1.45 +    return this[!this.isShown ? 'show' : 'hide'](_relatedTarget)
    1.46 +  }
    1.47 +
    1.48 +  Modal.prototype.show = function (_relatedTarget) {
    1.49 +    var that = this
    1.50 +    var e    = $.Event('show.bs.modal', { relatedTarget: _relatedTarget })
    1.51 +
    1.52 +    this.$element.trigger(e)
    1.53 +
    1.54 +    if (this.isShown || e.isDefaultPrevented()) return
    1.55 +
    1.56 +    this.isShown = true
    1.57 +
    1.58 +    this.escape()
    1.59 +
    1.60 +    this.$element.on('click.dismiss.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
    1.61 +
    1.62 +    this.backdrop(function () {
    1.63 +      var transition = $.support.transition && that.$element.hasClass('fade')
    1.64 +
    1.65 +      if (!that.$element.parent().length) {
    1.66 +        that.$element.appendTo(document.body) // don't move modals dom position
    1.67 +      }
    1.68 +
    1.69 +      that.$element.show()
    1.70 +
    1.71 +      if (transition) {
    1.72 +        that.$element[0].offsetWidth // force reflow
    1.73 +      }
    1.74 +
    1.75 +      that.$element
    1.76 +        .addClass('in')
    1.77 +        .attr('aria-hidden', false)
    1.78 +
    1.79 +      that.enforceFocus()
    1.80 +
    1.81 +      var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })
    1.82 +
    1.83 +      transition ?
    1.84 +        that.$element.find('.modal-dialog') // wait for modal to slide in
    1.85 +          .one($.support.transition.end, function () {
    1.86 +            that.$element.focus().trigger(e)
    1.87 +          })
    1.88 +          .emulateTransitionEnd(300) :
    1.89 +        that.$element.focus().trigger(e)
    1.90 +    })
    1.91 +  }
    1.92 +
    1.93 +  Modal.prototype.hide = function (e) {
    1.94 +    if (e) e.preventDefault()
    1.95 +
    1.96 +    e = $.Event('hide.bs.modal')
    1.97 +
    1.98 +    this.$element.trigger(e)
    1.99 +
   1.100 +    if (!this.isShown || e.isDefaultPrevented()) return
   1.101 +
   1.102 +    this.isShown = false
   1.103 +
   1.104 +    this.escape()
   1.105 +
   1.106 +    $(document).off('focusin.bs.modal')
   1.107 +
   1.108 +    this.$element
   1.109 +      .removeClass('in')
   1.110 +      .attr('aria-hidden', true)
   1.111 +      .off('click.dismiss.modal')
   1.112 +
   1.113 +    $.support.transition && this.$element.hasClass('fade') ?
   1.114 +      this.$element
   1.115 +        .one($.support.transition.end, $.proxy(this.hideModal, this))
   1.116 +        .emulateTransitionEnd(300) :
   1.117 +      this.hideModal()
   1.118 +  }
   1.119 +
   1.120 +  Modal.prototype.enforceFocus = function () {
   1.121 +    $(document)
   1.122 +      .off('focusin.bs.modal') // guard against infinite focus loop
   1.123 +      .on('focusin.bs.modal', $.proxy(function (e) {
   1.124 +        if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
   1.125 +          this.$element.focus()
   1.126 +        }
   1.127 +      }, this))
   1.128 +  }
   1.129 +
   1.130 +  Modal.prototype.escape = function () {
   1.131 +    if (this.isShown && this.options.keyboard) {
   1.132 +      this.$element.on('keyup.dismiss.bs.modal', $.proxy(function (e) {
   1.133 +        e.which == 27 && this.hide()
   1.134 +      }, this))
   1.135 +    } else if (!this.isShown) {
   1.136 +      this.$element.off('keyup.dismiss.bs.modal')
   1.137 +    }
   1.138 +  }
   1.139 +
   1.140 +  Modal.prototype.hideModal = function () {
   1.141 +    var that = this
   1.142 +    this.$element.hide()
   1.143 +    this.backdrop(function () {
   1.144 +      that.removeBackdrop()
   1.145 +      that.$element.trigger('hidden.bs.modal')
   1.146 +    })
   1.147 +  }
   1.148 +
   1.149 +  Modal.prototype.removeBackdrop = function () {
   1.150 +    this.$backdrop && this.$backdrop.remove()
   1.151 +    this.$backdrop = null
   1.152 +  }
   1.153 +
   1.154 +  Modal.prototype.backdrop = function (callback) {
   1.155 +    var that    = this
   1.156 +    var animate = this.$element.hasClass('fade') ? 'fade' : ''
   1.157 +
   1.158 +    if (this.isShown && this.options.backdrop) {
   1.159 +      var doAnimate = $.support.transition && animate
   1.160 +
   1.161 +      this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
   1.162 +        .appendTo(document.body)
   1.163 +
   1.164 +      this.$element.on('click.dismiss.modal', $.proxy(function (e) {
   1.165 +        if (e.target !== e.currentTarget) return
   1.166 +        this.options.backdrop == 'static'
   1.167 +          ? this.$element[0].focus.call(this.$element[0])
   1.168 +          : this.hide.call(this)
   1.169 +      }, this))
   1.170 +
   1.171 +      if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
   1.172 +
   1.173 +      this.$backdrop.addClass('in')
   1.174 +
   1.175 +      if (!callback) return
   1.176 +
   1.177 +      doAnimate ?
   1.178 +        this.$backdrop
   1.179 +          .one($.support.transition.end, callback)
   1.180 +          .emulateTransitionEnd(150) :
   1.181 +        callback()
   1.182 +
   1.183 +    } else if (!this.isShown && this.$backdrop) {
   1.184 +      this.$backdrop.removeClass('in')
   1.185 +
   1.186 +      $.support.transition && this.$element.hasClass('fade')?
   1.187 +        this.$backdrop
   1.188 +          .one($.support.transition.end, callback)
   1.189 +          .emulateTransitionEnd(150) :
   1.190 +        callback()
   1.191 +
   1.192 +    } else if (callback) {
   1.193 +      callback()
   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, _relatedTarget) {
   1.204 +    return this.each(function () {
   1.205 +      var $this   = $(this)
   1.206 +      var data    = $this.data('bs.modal')
   1.207 +      var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option)
   1.208 +
   1.209 +      if (!data) $this.data('bs.modal', (data = new Modal(this, options)))
   1.210 +      if (typeof option == 'string') data[option](_relatedTarget)
   1.211 +      else if (options.show) data.show(_relatedTarget)
   1.212 +    })
   1.213 +  }
   1.214 +
   1.215 +  $.fn.modal.Constructor = Modal
   1.216 +
   1.217 +
   1.218 +  // MODAL NO CONFLICT
   1.219 +  // =================
   1.220 +
   1.221 +  $.fn.modal.noConflict = function () {
   1.222 +    $.fn.modal = old
   1.223 +    return this
   1.224 +  }
   1.225 +
   1.226 +
   1.227 +  // MODAL DATA-API
   1.228 +  // ==============
   1.229 +
   1.230 +  $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
   1.231 +    var $this   = $(this)
   1.232 +    var href    = $this.attr('href')
   1.233 +    var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
   1.234 +    var option  = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
   1.235 +
   1.236 +    e.preventDefault()
   1.237 +
   1.238 +    $target
   1.239 +      .modal(option, this)
   1.240 +      .one('hide', function () {
   1.241 +        $this.is(':visible') && $this.focus()
   1.242 +      })
   1.243 +  })
   1.244 +
   1.245 +  $(document)
   1.246 +    .on('show.bs.modal',  '.modal', function () { $(document.body).addClass('modal-open') })
   1.247 +    .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') })
   1.248 +
   1.249 +}(jQuery);
Impressum Datenschutzerklärung