aboutsummaryrefslogtreecommitdiff
path: root/js/modal.js
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2014-11-11 19:25:16 -0800
committerMark Otto <[email protected]>2014-11-11 19:25:16 -0800
commit1e268ddfc30def5f4b2b0f2ace34b7de549ea830 (patch)
tree7cc63bc43a6c3b603cef4f004a2285e5c034a710 /js/modal.js
parent4f6aeaa6347725436296131c4d2b059243390a04 (diff)
parent001d5e00c58bbb8e4d34c085c5b27b214a475bd5 (diff)
downloadbootstrap-1e268ddfc30def5f4b2b0f2ace34b7de549ea830.tar.xz
bootstrap-1e268ddfc30def5f4b2b0f2ace34b7de549ea830.zip
Merge branch 'master' into labels-readme
Diffstat (limited to 'js/modal.js')
-rw-r--r--js/modal.js53
1 files changed, 48 insertions, 5 deletions
diff --git a/js/modal.js b/js/modal.js
index 6e2ac7e74..ed3f0293f 100644
--- a/js/modal.js
+++ b/js/modal.js
@@ -1,5 +1,5 @@
/* ========================================================================
- * Bootstrap: modal.js v3.2.0
+ * Bootstrap: modal.js v3.3.0
* http://getbootstrap.com/javascript/#modals
* ========================================================================
* Copyright 2011-2014 Twitter, Inc.
@@ -30,7 +30,7 @@
}
}
- Modal.VERSION = '3.2.0'
+ Modal.VERSION = '3.3.0'
Modal.TRANSITION_DURATION = 300
Modal.BACKDROP_TRANSITION_DURATION = 150
@@ -56,10 +56,11 @@
this.isShown = true
this.checkScrollbar()
+ this.setScrollbar()
this.$body.addClass('modal-open')
- this.setScrollbar()
this.escape()
+ this.resize()
this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
@@ -74,6 +75,9 @@
.show()
.scrollTop(0)
+ if (that.options.backdrop) that.adjustBackdrop()
+ that.adjustDialog()
+
if (transition) {
that.$element[0].offsetWidth // force reflow
}
@@ -108,6 +112,7 @@
this.isShown = false
this.escape()
+ this.resize()
$(document).off('focusin.bs.modal')
@@ -143,11 +148,20 @@
}
}
+ Modal.prototype.resize = function () {
+ if (this.isShown) {
+ $(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this))
+ } else {
+ $(window).off('resize.bs.modal')
+ }
+ }
+
Modal.prototype.hideModal = function () {
var that = this
this.$element.hide()
this.backdrop(function () {
that.$body.removeClass('modal-open')
+ that.resetAdjustments()
that.resetScrollbar()
that.$element.trigger('hidden.bs.modal')
})
@@ -204,13 +218,43 @@
}
}
+ // these following methods are used to handle overflowing modals
+
+ Modal.prototype.handleUpdate = function () {
+ if (this.options.backdrop) this.adjustBackdrop()
+ this.adjustDialog()
+ }
+
+ Modal.prototype.adjustBackdrop = function () {
+ this.$backdrop
+ .css('height', 0)
+ .css('height', this.$element[0].scrollHeight)
+ }
+
+ Modal.prototype.adjustDialog = function () {
+ var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight
+
+ this.$element.css({
+ paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '',
+ paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
+ })
+ }
+
+ Modal.prototype.resetAdjustments = function () {
+ this.$element.css({
+ paddingLeft: '',
+ paddingRight: ''
+ })
+ }
+
Modal.prototype.checkScrollbar = function () {
+ this.bodyIsOverflowing = document.body.scrollHeight > document.documentElement.clientHeight
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)
+ if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)
}
Modal.prototype.resetScrollbar = function () {
@@ -218,7 +262,6 @@
}
Modal.prototype.measureScrollbar = function () { // thx walsh
- if (document.body.clientWidth >= window.innerWidth) return 0
var scrollDiv = document.createElement('div')
scrollDiv.className = 'modal-scrollbar-measure'
this.$body.append(scrollDiv)