Skip to content

Fit, flow & reposition #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
35 changes: 34 additions & 1 deletion index.html → demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,17 @@ <h3>Long Modals</h3>
</div>
<br />

</div>
<div class="reposition">
<h3>Fit, flow & Reposition</h3>
<pre class="pre-scrollable prettyprint linenums" data-source="#reposition">
</pre>
<div class="text-center">
<button class="demo btn btn-primary btn-large" data-toggle="modal" href="#reposition">View Demo</button>
</div>
</div>
<br />

</div>
</div>
</div>

Expand Down Expand Up @@ -280,6 +290,29 @@ <h3>A Very Long</h3>
</div>

<div id="ajax-modal" class="modal hide fade" tabindex="-1"></div>

<div id="reposition" class="modal hide fade modal-fit modal-reposition" tabindex="-1">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Fit, flow & reposition</h3>
</div>
<div class="modal-body">
<div>
<button class="btn" data-toggle="collapse" data-target="#showimg" onclick="$('#reposition').trigger('change.modal')">Click me</button>
</div>
<div id="showimg" class="collapse">
<div class="text-right">
<button class="btn" data-toggle="modal-fit" data-target="#reposition">Fit or flow</button>
</div>
<img style="height: 800px" src="http://i.imgur.com/KwPYo.jpg" />
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
<button type="button" data-dismiss="modal" class="btn btn-primary">Continue Task</button>
</div>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap.js"></script>
Expand Down
22 changes: 19 additions & 3 deletions js/bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the value 165 shouldn't be hardcoded if we're going to include the "contrain modal to window size" example from the docs. This wouldn't work quite right for all cases (i.e no header or footer, any font/padding style changes etc..)

Would be nice if we could compute the actual value. Something like windowHeight - headerHeight - footerHeight - marginBetweenModalAndWindow.

prop = 'max-height';
}

if (this.options.width){
this.$element.css('width', this.options.width);

Expand All @@ -122,11 +127,12 @@

this.$element.find('.modal-body')
.css('overflow', '')
.css(prop, '');
.css('max-height', '')
.css('height', '');

var modalOverflow = $(window).height() - 10 < this.$element.height();

if (value){
if (value && !this.$element.hasClass('modal-flow')){
this.$element.find('.modal-body')
.css('overflow', 'auto')
.css(prop, value);
Expand All @@ -141,6 +147,10 @@
.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 () {
Expand Down Expand Up @@ -356,12 +366,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)
Expand Down
13 changes: 13 additions & 0 deletions js/bootstrap-modalmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
},

Expand Down