|
1 | 1 | /* ======================================================================== |
2 | | - * Bootstrap: modal.js v3.3.0 |
| 2 | + * Bootstrap: modal.js v3.3.1 |
3 | 3 | * http://getbootstrap.com/javascript/#modals |
4 | 4 | * ======================================================================== |
5 | 5 | * Copyright 2011-2014 Twitter, Inc. |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 |
|
33 | | - Modal.VERSION = '3.3.0' |
| 33 | + Modal.VERSION = '3.3.1' |
34 | 34 |
|
35 | 35 | Modal.TRANSITION_DURATION = 300 |
36 | 36 | Modal.BACKDROP_TRANSITION_DURATION = 150 |
|
56 | 56 | this.isShown = true |
57 | 57 |
|
58 | 58 | this.checkScrollbar() |
| 59 | + this.setScrollbar() |
59 | 60 | this.$body.addClass('modal-open') |
60 | 61 |
|
61 | | - this.setScrollbar() |
62 | 62 | this.escape() |
| 63 | + this.resize() |
63 | 64 |
|
64 | 65 | this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) |
65 | 66 |
|
|
74 | 75 | .show() |
75 | 76 | .scrollTop(0) |
76 | 77 |
|
| 78 | + if (that.options.backdrop) that.adjustBackdrop() |
| 79 | + that.adjustDialog() |
| 80 | + |
77 | 81 | if (transition) { |
78 | 82 | that.$element[0].offsetWidth // force reflow |
79 | 83 | } |
|
108 | 112 | this.isShown = false |
109 | 113 |
|
110 | 114 | this.escape() |
| 115 | + this.resize() |
111 | 116 |
|
112 | 117 | $(document).off('focusin.bs.modal') |
113 | 118 |
|
|
143 | 148 | } |
144 | 149 | } |
145 | 150 |
|
| 151 | + Modal.prototype.resize = function () { |
| 152 | + if (this.isShown) { |
| 153 | + $(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this)) |
| 154 | + } else { |
| 155 | + $(window).off('resize.bs.modal') |
| 156 | + } |
| 157 | + } |
| 158 | + |
146 | 159 | Modal.prototype.hideModal = function () { |
147 | 160 | var that = this |
148 | 161 | this.$element.hide() |
149 | 162 | this.backdrop(function () { |
150 | 163 | that.$body.removeClass('modal-open') |
| 164 | + that.resetAdjustments() |
151 | 165 | that.resetScrollbar() |
152 | 166 | that.$element.trigger('hidden.bs.modal') |
153 | 167 | }) |
|
204 | 218 | } |
205 | 219 | } |
206 | 220 |
|
| 221 | + // these following methods are used to handle overflowing modals |
| 222 | + |
| 223 | + Modal.prototype.handleUpdate = function () { |
| 224 | + if (this.options.backdrop) this.adjustBackdrop() |
| 225 | + this.adjustDialog() |
| 226 | + } |
| 227 | + |
| 228 | + Modal.prototype.adjustBackdrop = function () { |
| 229 | + this.$backdrop |
| 230 | + .css('height', 0) |
| 231 | + .css('height', this.$element[0].scrollHeight) |
| 232 | + } |
| 233 | + |
| 234 | + Modal.prototype.adjustDialog = function () { |
| 235 | + var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight |
| 236 | + |
| 237 | + this.$element.css({ |
| 238 | + paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '', |
| 239 | + paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : '' |
| 240 | + }) |
| 241 | + } |
| 242 | + |
| 243 | + Modal.prototype.resetAdjustments = function () { |
| 244 | + this.$element.css({ |
| 245 | + paddingLeft: '', |
| 246 | + paddingRight: '' |
| 247 | + }) |
| 248 | + } |
| 249 | + |
207 | 250 | Modal.prototype.checkScrollbar = function () { |
| 251 | + this.bodyIsOverflowing = document.body.scrollHeight > document.documentElement.clientHeight |
208 | 252 | this.scrollbarWidth = this.measureScrollbar() |
209 | 253 | } |
210 | 254 |
|
211 | 255 | Modal.prototype.setScrollbar = function () { |
212 | 256 | var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10) |
213 | | - if (this.scrollbarWidth) this.$body.css('padding-right', bodyPad + this.scrollbarWidth) |
| 257 | + if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth) |
214 | 258 | } |
215 | 259 |
|
216 | 260 | Modal.prototype.resetScrollbar = function () { |
217 | 261 | this.$body.css('padding-right', '') |
218 | 262 | } |
219 | 263 |
|
220 | 264 | Modal.prototype.measureScrollbar = function () { // thx walsh |
221 | | - if (document.body.clientWidth >= window.innerWidth) return 0 |
222 | 265 | var scrollDiv = document.createElement('div') |
223 | 266 | scrollDiv.className = 'modal-scrollbar-measure' |
224 | 267 | this.$body.append(scrollDiv) |
|
0 commit comments