Skip to content

Commit b7ab799

Browse files
committed
Merge branch 'master' of github.com:twbs/bootstrap
Conflicts: dist/js/bootstrap.min.js docs/dist/js/bootstrap.min.js
2 parents 2a43e7e + c6ab3fc commit b7ab799

17 files changed

+95
-25
lines changed

dist/css/bootstrap-rtl.css

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/bootstrap-rtl.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/bootstrap.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/bootstrap.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/bootstrap.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/bootstrap.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
796796

797797
var Modal = function (element, options) {
798798
this.options = options
799+
this.$body = $(document.body)
799800
this.$element = $(element)
800801
this.$backdrop =
801802
this.isShown = null
@@ -829,6 +830,9 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
829830

830831
this.isShown = true
831832

833+
this.$body.addClass('modal-open')
834+
835+
this.setScrollbar()
832836
this.escape()
833837

834838
this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
@@ -837,7 +841,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
837841
var transition = $.support.transition && that.$element.hasClass('fade')
838842

839843
if (!that.$element.parent().length) {
840-
that.$element.appendTo(document.body) // don't move modals dom position
844+
that.$element.appendTo(that.$body) // don't move modals dom position
841845
}
842846

843847
that.$element
@@ -877,6 +881,9 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
877881

878882
this.isShown = false
879883

884+
this.$body.removeClass('modal-open')
885+
886+
this.resetScrollbar()
880887
this.escape()
881888

882889
$(document).off('focusin.bs.modal')
@@ -934,7 +941,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
934941
var doAnimate = $.support.transition && animate
935942

936943
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
937-
.appendTo(document.body)
944+
.appendTo(this.$body)
938945

939946
this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) {
940947
if (e.target !== e.currentTarget) return
@@ -969,6 +976,26 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
969976
}
970977
}
971978

979+
Modal.prototype.setScrollbar = function () {
980+
if (document.body.clientHeight <= window.innerHeight) return
981+
var scrollbarWidth = this.measureScrollbar()
982+
var bodyPad = parseInt(this.$body.css('padding-right') || 0)
983+
if (scrollbarWidth) this.$body.css('padding-right', bodyPad + scrollbarWidth)
984+
}
985+
986+
Modal.prototype.resetScrollbar = function () {
987+
this.$body.css('padding-right', '')
988+
}
989+
990+
Modal.prototype.measureScrollbar = function () { // thx walsh
991+
var scrollDiv = document.createElement('div')
992+
scrollDiv.className = 'modal-scrollbar-measure'
993+
this.$body.append(scrollDiv)
994+
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
995+
this.$body[0].removeChild(scrollDiv)
996+
return scrollbarWidth
997+
}
998+
972999

9731000
// MODAL PLUGIN DEFINITION
9741001
// =======================
@@ -1017,10 +1044,6 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
10171044
})
10181045
})
10191046

1020-
$(document)
1021-
.on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') })
1022-
.on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') })
1023-
10241047
}(jQuery);
10251048

10261049
/* ========================================================================

dist/js/bootstrap.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/css/docs.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/js/customize.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/js/raw-files.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)