Skip to content

Instantly share code, notes, and snippets.

@krisdigital
Created January 10, 2014 22:06
Show Gist options
  • Save krisdigital/8363612 to your computer and use it in GitHub Desktop.
Save krisdigital/8363612 to your computer and use it in GitHub Desktop.
Several fixes for Bootstrap 3 Modals when using forms and iOS
//Modals, several fixes
$('.modal').on('show.bs.modal', function() {
$("#page input:not(:disabled), #page select:not(:disabled)").addClass('twerked').prop("disabled", true);
var measureScrollBar = function () {
var scrollDiv = document.createElement('div')
scrollDiv.style = 'width: 1px;height: 1px;overflow: scroll;position: absolute;top: -9999px;'
document.body.appendChild(scrollDiv)
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
document.body.removeChild(scrollDiv)
return scrollbarWidth
}
if( navigator.userAgent.match(/iPhone|iPad|iPod/i) ) {
$(this).css({
position: 'absolute',
marginTop: $(window).scrollTop() + 'px',
bottom: 'auto'
});
setTimeout( function() {
$('.modal-backdrop').css({
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: $(document).height() + 'px'
});
}, 0);
}
if (this.clientHeight <= window.innerHeight) return
var scrollbarWidth = measureScrollBar()
if (scrollbarWidth) $(document.body).css('padding-right', scrollbarWidth)
}).on('hidden.bs.modal', function () {
$("#page .twerked").removeClass('twerked').prop("disabled", false);
$(document.body).css('padding-right', 0)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment