diff --git a/index.html b/index.html index e1daae8..ff28f19 100644 --- a/index.html +++ b/index.html @@ -116,6 +116,16 @@

Long Modals


+
+

Fit, flow & Reposition

+
+  				  
+
+ +
+
+
+ @@ -280,6 +290,29 @@

A Very Long

+ + + diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index c125bd5..1df0e2d 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -104,6 +104,11 @@ var prop = this.options.height ? 'height' : 'max-height', value = this.options.height || this.options.maxHeight; + if (!value && this.$element.hasClass('modal-fit')){ + value = function(){return $(window).height() - 165} + prop = 'max-height'; + } + if (this.options.width){ this.$element.css('width', this.options.width); @@ -122,7 +127,8 @@ this.$element.find('.modal-body') .css('overflow', '') - .css(prop, ''); + .css('max-height', '') + .css('height', ''); var modalOverflow = $(window).height() - 10 < this.$element.height(); @@ -141,6 +147,9 @@ .css('margin-top', 0 - this.$element.height() / 2) .removeClass('modal-overflow'); } + + this.$element.data('modalheight',this.$element.height()); + this.$element.data('modalwidth',this.$element.width()); }, tab: function () { @@ -356,12 +365,18 @@ * ============== */ $(function () { - $(document).off('click.modal').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) { + $(document).off('click.modal').on('click.modal.data-api', '[data-toggle|="modal"]', function ( e ) { var $this = $(this), + toggle = $this.attr('data-toggle'), href = $this.attr('href'), $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))), //strip for ie7 option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()); + if (toggle!='modal'){ + if ($target.data('modal')) option = $target.data('modal').isShown? 'layout':'show'; + $target.toggleClass(toggle); + } + e.preventDefault(); $target .modal(option) diff --git a/js/bootstrap-modalmanager.js b/js/bootstrap-modalmanager.js index 1982975..7a891b7 100644 --- a/js/bootstrap-modalmanager.js +++ b/js/bootstrap-modalmanager.js @@ -49,6 +49,19 @@ } }, 10); }); + // listen to 'change' event, checking if modal-size changed and call 'layout'. + $(document).on('change.modal','.modal.modal-reposition',function(e){ + var $target = $(e.currentTarget) + , modal = $target.data('modal'); + if (modal && modal.isShown){ + setTimeout( + function(){ + if ($target.height()!=$target.data('modalheight') || $target.width()!=$target.data('modalwidth')) + modal.layout() + } + ,$target.data('repositionwait') || that.options.repositionWait || 300); + } + }); } },