diff options
| author | Heinrich Fenkart <[email protected]> | 2015-03-03 05:54:03 +0100 |
|---|---|---|
| committer | Heinrich Fenkart <[email protected]> | 2015-03-03 05:54:03 +0100 |
| commit | 200f6fb10d1b41db80fe0750c13eac4157a9149f (patch) | |
| tree | c58d9ddc5d881d9a7e4fcd1dcccc6a730000245f | |
| parent | 399658178d3248f58f167233d99ae10990cf76fb (diff) | |
| parent | f5beebe726aa8c1810015d8c62931f4559b49664 (diff) | |
| download | bootstrap-200f6fb10d1b41db80fe0750c13eac4157a9149f.tar.xz bootstrap-200f6fb10d1b41db80fe0750c13eac4157a9149f.zip | |
Merge pull request #15881 from twbs/fix-modal-backdrop
Modal: Fix backdrop not readjusting when height changes
| -rw-r--r-- | js/modal.js | 54 | ||||
| -rw-r--r-- | js/tests/unit/modal.js | 4 | ||||
| -rw-r--r-- | js/tests/visual/modal.html | 38 | ||||
| -rw-r--r-- | less/modals.less | 4 | ||||
| -rw-r--r-- | less/variables.less | 3 |
5 files changed, 74 insertions, 29 deletions
diff --git a/js/modal.js b/js/modal.js index 7ee2679a2..13bcf0af8 100644 --- a/js/modal.js +++ b/js/modal.js @@ -14,13 +14,15 @@ // ====================== var Modal = function (element, options) { - this.options = options - this.$body = $(document.body) - this.$element = $(element) - this.$backdrop = null - this.isShown = null - this.originalBodyPad = null - this.scrollbarWidth = 0 + this.options = options + this.$body = $(document.body) + this.$element = $(element) + this.$dialog = this.$element.find('.modal-dialog') + this.$backdrop = null + this.isShown = null + this.originalBodyPad = null + this.scrollbarWidth = 0 + this.ignoreBackdropClick = false if (this.options.remote) { this.$element @@ -65,6 +67,12 @@ this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) + this.$dialog.on('mousedown.dismiss.bs.modal', function () { + that.$element.one('mouseup.dismiss.bs.modal', function (e) { + if ($(e.target).is(that.$element)) that.ignoreBackdropClick = true + }) + }) + this.backdrop(function () { var transition = $.support.transition && that.$element.hasClass('fade') @@ -76,7 +84,6 @@ .show() .scrollTop(0) - if (that.options.backdrop) that.adjustBackdrop() that.adjustDialog() if (transition) { @@ -92,7 +99,7 @@ var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget }) transition ? - that.$element.find('.modal-dialog') // wait for modal to slide in + that.$dialog // wait for modal to slide in .one('bsTransitionEnd', function () { that.$element.trigger('focus').trigger(e) }) @@ -121,6 +128,9 @@ .removeClass('in') .attr('aria-hidden', true) .off('click.dismiss.bs.modal') + .off('mouseup.dismiss.bs.modal') + + this.$dialog.off('mousedown.dismiss.bs.modal') $.support.transition && this.$element.hasClass('fade') ? this.$element @@ -181,13 +191,18 @@ var doAnimate = $.support.transition && animate this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') - .prependTo(this.$element) - .on('click.dismiss.bs.modal', $.proxy(function (e) { - if (e.target !== e.currentTarget) return - this.options.backdrop == 'static' - ? this.$element[0].focus.call(this.$element[0]) - : this.hide.call(this) - }, this)) + .appendTo(this.$body) + + this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) { + if (this.ignoreBackdropClick) { + this.ignoreBackdropClick = false + return + } + if (e.target !== e.currentTarget) return + this.options.backdrop == 'static' + ? this.$element[0].focus() + : this.hide() + }, this)) if (doAnimate) this.$backdrop[0].offsetWidth // force reflow @@ -222,16 +237,9 @@ // 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 diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index d0973a30d..1397c596f 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -167,7 +167,7 @@ $(function () { assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom') $('.contents').click() assert.ok($('#modal-test').is(':visible'), 'modal visible') - $('#modal-test .modal-backdrop').click() + $('#modal-test').click() }) .on('hidden.bs.modal', function () { assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') @@ -222,7 +222,7 @@ $(function () { $('<div id="modal-test"><div class="contents"/></div>') .on('shown.bs.modal', function () { triggered = 0 - $('#modal-test .modal-backdrop').click() + $('#modal-test').click() }) .on('hide.bs.modal', function () { triggered += 1 diff --git a/js/tests/visual/modal.html b/js/tests/visual/modal.html index 0af79cc55..a6070d5a5 100644 --- a/js/tests/visual/modal.html +++ b/js/tests/visual/modal.html @@ -35,10 +35,43 @@ <p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</p> <h4>Popover in a modal</h4> - <p>This <a href="#" role="button" class="btn btn-default js-popover" title="" data-content="And here's some amazing content. It's very engaging. right?" data-original-title="A Title">button</a> should trigger a popover on click.</p> + <p>This <a href="#" role="button" class="btn btn-default js-popover" title="A Title" data-content="And here's some amazing content. It's very engaging. right?" data-placement="left">button</a> should trigger a popover on click.</p> <h4>Tooltips in a modal</h4> - <p><a href="#" class="js-tooltip" title="" data-original-title="Tooltip">This link</a> and <a href="#" class="js-tooltip" title="" data-original-title="Tooltip">that link</a> should have tooltips on hover.</p> + <p><a href="#" class="js-tooltip" title="Tooltip">This link</a> and <a href="#" class="js-tooltip" title="Tooltip">that link</a> should have tooltips on hover.</p> + + <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> + <div class="panel panel-default"> + <div class="panel-heading" role="tab" id="headingOne"> + <h4 class="panel-title"> + <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> + Collapsible Group Item #1 + </a> + </h4> + </div> + <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> + <div class="panel-body"> + Lorem ipsum + </div> + </div> + </div> + <div class="panel panel-default"> + <div class="panel-heading" role="tab" id="headingTwo"> + <h4 class="panel-title"> + <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> + Collapsible Group Item #2 + </a> + </h4> + </div> + <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo"> + <div class="panel-body"> + Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. + Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. + Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. + </div> + </div> + </div> + </div> <hr> @@ -74,6 +107,7 @@ <script src="../../modal.js"></script> <script src="../../tooltip.js"></script> <script src="../../popover.js"></script> +<script src="../../collapse.js"></script> <!-- JavaScript Test --> <script> diff --git a/less/modals.less b/less/modals.less index 032a497d6..1de622050 100644 --- a/less/modals.less +++ b/less/modals.less @@ -62,10 +62,12 @@ // Modal background .modal-backdrop { - position: absolute; + position: fixed; top: 0; right: 0; + bottom: 0; left: 0; + z-index: @zindex-modal-background; background-color: @modal-backdrop-bg; // Fade for backdrop &.fade { .opacity(0); } diff --git a/less/variables.less b/less/variables.less index a647983eb..b5fb9d02c 100644 --- a/less/variables.less +++ b/less/variables.less @@ -269,7 +269,8 @@ @zindex-popover: 1060; @zindex-tooltip: 1070; @zindex-navbar-fixed: 1030; -@zindex-modal: 1040; +@zindex-modal-background: 1040; +@zindex-modal: 1050; //== Media queries breakpoints |
