From 637a72f710f74b8a05bdd649d6cb4de166f33e7f Mon Sep 17 00:00:00 2001 From: Yaremenko Dmitry Date: Tue, 1 Jan 2013 16:57:19 +0200 Subject: [PATCH 1/2] centering modal element using css, without javascript --- css/bootstrap-modal.css | 34 ++++++++++++++++++++++++++-------- js/bootstrap-modal.js | 11 +---------- js/bootstrap-modalmanager.js | 5 ++--- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/css/bootstrap-modal.css b/css/bootstrap-modal.css index b1d2899..520da9e 100644 --- a/css/bootstrap-modal.css +++ b/css/bootstrap-modal.css @@ -36,14 +36,34 @@ left: 0; right: 0; overflow: auto; + text-align: center; +} + +.modal-scrollable .modal { + text-align: left; +} + +.modal-scrollable:after { + content: ""; + height: 100%; + width: 0; + display: inline-block; + vertical-align: middle; } .modal { outline: none; - position: absolute; - margin-top: 0; - top: 50%; + position: relative; + margin: 0; + width: auto; + top: auto; + left: auto; + right: auto; + bottom: auto; overflow: visible; /* allow content to popup out (i.e tooltips) */ + display: inline-block; + vertical-align: middle; + min-width: 530px; } .modal.fade { @@ -55,7 +75,7 @@ } .modal.fade.in { - top: 50%; + top: 0; } .modal-body { @@ -91,8 +111,7 @@ } .modal.container { - width: 940px; - margin-left: -470px; + max-width: 940px; } /* Modal Overflow */ @@ -118,8 +137,7 @@ @media (min-width: 1200px) { .modal.container { - width: 1170px; - margin-left: -585px; + max-width: 1170px; } } diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 5a40400..e1a6d70 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -65,15 +65,6 @@ if (this.options.width){ this.$element.css('width', this.options.width); - - var that = this; - this.$element.css('margin-left', function () { - if (/%/ig.test(that.options.width)){ - return -(parseInt(that.options.width) / 2) + '%'; - } else { - return -($(this).width() / 2) + 'px'; - } - }); } var prop = this.options.height ? 'height' : 'max-height'; @@ -352,4 +343,4 @@ }); }); -}(window.jQuery); \ No newline at end of file +}(window.jQuery); diff --git a/js/bootstrap-modalmanager.js b/js/bootstrap-modalmanager.js index 4a865f5..91c614b 100644 --- a/js/bootstrap-modalmanager.js +++ b/js/bootstrap-modalmanager.js @@ -71,12 +71,11 @@ if (transition) { modal.$element[0].style.display = 'run-in'; modal.$element[0].offsetWidth; - modal.$element.one($.support.transition.end, function () { modal.$element[0].style.display = 'block' }); + modal.$element.one($.support.transition.end, function () { modal.$element.show(); /*modal.$element[0].style.display = 'block' */}); } modal.$element .toggleClass('modal-overflow', modalOverflow) - .css('margin-top', modalOverflow ? 0 : 0 - modal.$element.height()/2) .addClass('in') .attr('aria-hidden', false); @@ -367,4 +366,4 @@ $.fn.modalmanager.Constructor = ModalManager -}(jQuery); \ No newline at end of file +}(jQuery); From b9bd41870a8848e14c54e517b8e6600e4f0181cb Mon Sep 17 00:00:00 2001 From: Yaremenko Dmitry Date: Wed, 9 Jan 2013 20:36:12 +0200 Subject: [PATCH 2/2] removed setting display to run-in, which causes troubles in chrome --- js/bootstrap-modalmanager.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/bootstrap-modalmanager.js b/js/bootstrap-modalmanager.js index 91c614b..7d676d0 100644 --- a/js/bootstrap-modalmanager.js +++ b/js/bootstrap-modalmanager.js @@ -69,9 +69,8 @@ modal.$element.show(); if (transition) { - modal.$element[0].style.display = 'run-in'; modal.$element[0].offsetWidth; - modal.$element.one($.support.transition.end, function () { modal.$element.show(); /*modal.$element[0].style.display = 'block' */}); + modal.$element.one($.support.transition.end, function () { modal.$element.show(); }); } modal.$element