summaryrefslogtreecommitdiff
path: root/bower_components/bootstrap/js/modal.js
diff options
context:
space:
mode:
Diffstat (limited to 'bower_components/bootstrap/js/modal.js')
-rw-r--r--bower_components/bootstrap/js/modal.js95
1 files changed, 66 insertions, 29 deletions
diff --git a/bower_components/bootstrap/js/modal.js b/bower_components/bootstrap/js/modal.js
index 20ff2704..29eedf11 100644
--- a/bower_components/bootstrap/js/modal.js
+++ b/bower_components/bootstrap/js/modal.js
@@ -1,5 +1,5 @@
/* ========================================================================
- * Bootstrap: modal.js v3.1.1
+ * Bootstrap: modal.js v3.2.0
* http://getbootstrap.com/javascript/#modals
* ========================================================================
* Copyright 2011-2014 Twitter, Inc.
@@ -14,10 +14,12 @@
// ======================
var Modal = function (element, options) {
- this.options = options
- this.$element = $(element)
- this.$backdrop =
- this.isShown = null
+ this.options = options
+ this.$body = $(document.body)
+ this.$element = $(element)
+ this.$backdrop =
+ this.isShown = null
+ this.scrollbarWidth = 0
if (this.options.remote) {
this.$element
@@ -28,6 +30,8 @@
}
}
+ Modal.VERSION = '3.2.0'
+
Modal.DEFAULTS = {
backdrop: true,
keyboard: true,
@@ -35,7 +39,7 @@
}
Modal.prototype.toggle = function (_relatedTarget) {
- return this[!this.isShown ? 'show' : 'hide'](_relatedTarget)
+ return this.isShown ? this.hide() : this.show(_relatedTarget)
}
Modal.prototype.show = function (_relatedTarget) {
@@ -48,6 +52,10 @@
this.isShown = true
+ this.checkScrollbar()
+ this.$body.addClass('modal-open')
+
+ this.setScrollbar()
this.escape()
this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
@@ -56,7 +64,7 @@
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.appendTo(that.$body) // don't move modals dom position
}
that.$element
@@ -77,11 +85,11 @@
transition ?
that.$element.find('.modal-dialog') // wait for modal to slide in
- .one($.support.transition.end, function () {
- that.$element.focus().trigger(e)
+ .one('bsTransitionEnd', function () {
+ that.$element.trigger('focus').trigger(e)
})
.emulateTransitionEnd(300) :
- that.$element.focus().trigger(e)
+ that.$element.trigger('focus').trigger(e)
})
}
@@ -96,6 +104,9 @@
this.isShown = false
+ this.$body.removeClass('modal-open')
+
+ this.resetScrollbar()
this.escape()
$(document).off('focusin.bs.modal')
@@ -107,7 +118,7 @@
$.support.transition && this.$element.hasClass('fade') ?
this.$element
- .one($.support.transition.end, $.proxy(this.hideModal, this))
+ .one('bsTransitionEnd', $.proxy(this.hideModal, this))
.emulateTransitionEnd(300) :
this.hideModal()
}
@@ -117,7 +128,7 @@
.off('focusin.bs.modal') // guard against infinite focus loop
.on('focusin.bs.modal', $.proxy(function (e) {
if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
- this.$element.focus()
+ this.$element.trigger('focus')
}
}, this))
}
@@ -136,7 +147,6 @@
var that = this
this.$element.hide()
this.backdrop(function () {
- that.removeBackdrop()
that.$element.trigger('hidden.bs.modal')
})
}
@@ -147,13 +157,14 @@
}
Modal.prototype.backdrop = function (callback) {
+ var that = this
var animate = this.$element.hasClass('fade') ? 'fade' : ''
if (this.isShown && this.options.backdrop) {
var doAnimate = $.support.transition && animate
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
- .appendTo(document.body)
+ .appendTo(this.$body)
this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) {
if (e.target !== e.currentTarget) return
@@ -170,31 +181,56 @@
doAnimate ?
this.$backdrop
- .one($.support.transition.end, callback)
+ .one('bsTransitionEnd', callback)
.emulateTransitionEnd(150) :
callback()
} else if (!this.isShown && this.$backdrop) {
this.$backdrop.removeClass('in')
+ var callbackRemove = function () {
+ that.removeBackdrop()
+ callback && callback()
+ }
$.support.transition && this.$element.hasClass('fade') ?
this.$backdrop
- .one($.support.transition.end, callback)
+ .one('bsTransitionEnd', callbackRemove)
.emulateTransitionEnd(150) :
- callback()
+ callbackRemove()
} else if (callback) {
callback()
}
}
+ Modal.prototype.checkScrollbar = function () {
+ if (document.body.clientWidth >= window.innerWidth) return
+ this.scrollbarWidth = this.scrollbarWidth || this.measureScrollbar()
+ }
+
+ Modal.prototype.setScrollbar = function () {
+ var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)
+ if (this.scrollbarWidth) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)
+ }
+
+ Modal.prototype.resetScrollbar = function () {
+ this.$body.css('padding-right', '')
+ }
+
+ Modal.prototype.measureScrollbar = function () { // thx walsh
+ var scrollDiv = document.createElement('div')
+ scrollDiv.className = 'modal-scrollbar-measure'
+ this.$body.append(scrollDiv)
+ var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
+ this.$body[0].removeChild(scrollDiv)
+ return scrollbarWidth
+ }
+
// MODAL PLUGIN DEFINITION
// =======================
- var old = $.fn.modal
-
- $.fn.modal = function (option, _relatedTarget) {
+ function Plugin(option, _relatedTarget) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.modal')
@@ -206,6 +242,9 @@
})
}
+ var old = $.fn.modal
+
+ $.fn.modal = Plugin
$.fn.modal.Constructor = Modal
@@ -224,20 +263,18 @@
$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
var $this = $(this)
var href = $this.attr('href')
- var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
+ var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
if ($this.is('a')) e.preventDefault()
- $target
- .modal(option, this)
- .one('hide', function () {
- $this.is(':visible') && $this.focus()
+ $target.one('show.bs.modal', function (showEvent) {
+ if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown
+ $target.one('hidden.bs.modal', function () {
+ $this.is(':visible') && $this.trigger('focus')
})
+ })
+ Plugin.call($target, option, this)
})
- $(document)
- .on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') })
- .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') })
-
}(jQuery);