diff options
| author | Mark Otto <[email protected]> | 2014-03-16 19:06:17 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2014-03-16 19:06:17 -0700 |
| commit | b7ab7998248696392d3d4c4b1335ef2b6b10d29f (patch) | |
| tree | e23b555f45dd706a9fd3433681fc0c9b0b56193f /js | |
| parent | 2a43e7e78a59c70e217383c12c9ef0482cabb163 (diff) | |
| parent | c6ab3fc7d84450232f3024207015743ecdd929a4 (diff) | |
| download | bootstrap-b7ab7998248696392d3d4c4b1335ef2b6b10d29f.tar.xz bootstrap-b7ab7998248696392d3d4c4b1335ef2b6b10d29f.zip | |
Merge branch 'master' of github.com:twbs/bootstrap
Conflicts:
dist/js/bootstrap.min.js
docs/dist/js/bootstrap.min.js
Diffstat (limited to 'js')
| -rw-r--r-- | js/modal.js | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/js/modal.js b/js/modal.js index f6dc477b1..454d7d57a 100644 --- a/js/modal.js +++ b/js/modal.js @@ -15,6 +15,7 @@ var Modal = function (element, options) { this.options = options + this.$body = $(document.body) this.$element = $(element) this.$backdrop = this.isShown = null @@ -48,6 +49,9 @@ this.isShown = true + 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 +60,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 @@ -96,6 +100,9 @@ this.isShown = false + this.$body.removeClass('modal-open') + + this.resetScrollbar() this.escape() $(document).off('focusin.bs.modal') @@ -153,7 +160,7 @@ 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 @@ -188,6 +195,26 @@ } } + Modal.prototype.setScrollbar = function () { + if (document.body.clientHeight <= window.innerHeight) return + var scrollbarWidth = this.measureScrollbar() + var bodyPad = parseInt(this.$body.css('padding-right') || 0) + if (scrollbarWidth) this.$body.css('padding-right', bodyPad + 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 // ======================= @@ -236,8 +263,4 @@ }) }) - $(document) - .on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') }) - .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') }) - }(jQuery); |
