I fixed this by hooking into the modal hidden/shown events. My amended script looks like this:
var login = function () {
var handleRegister = function () {
$("a, button").click(function (e) {
var target = $(this).data("target");
var type = $(this).data("type");
if (target && type) {
var visible = $(target).is(":visible");
if (!visible) {
var available_height = $(window).height() - $('.topbar').outerHeight();
var content = $('.modal-content', target);
content.height(available_height);
$('.modal').each(function () {
$(this).modal('hide'); // hide all existing modals
});
$(target).modal('show');
}
e.preventDefault();
}
});
$('.modal').on('hidden.bs.modal', function (e) {
$("body").removeClass("modal-open");
});
$('.modal').on('shown.bs.modal', function (e) {
$("body").addClass("modal-open");
});
}
return {
init: function () {
handleRegister();
}
}
}();
I am unsure why this works as I would expect that this is what would be happening in the modal script anyway. But it works, so hey ho.