Reputation: 319
I've got a nice implementation of, curtesy of Kyle, for a Blazor component for a bootstrap modal dialog here: How to use Bootstrap modal in Blazor client app? But I would like to extend this solution to make the modal draggable & resizable.
The best approach (to avoid re-inventing the wheel) seems to be to use the JQuery UI draggable()/resizeable() functions. I've got this link to a demonstration of how to do this in pure Javascript: DRAG AND RESIZE BOOTSTRAP MODAL that essentially calls the resizeable and draggable functions on the modal divs
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<script type="text/javascript">
$('.modal-content').resizable({
//alsoResize: ".modal-dialog",
minHeight: 300,
minWidth: 300
});
$('.modal-dialog').draggable();
</script>
I've tried adding this script to my _Host.cshtml page but it has no effect. Any advice on how to merge the blazor component solution with the jquery UI solution would be much appreciated
David
Upvotes: 3
Views: 2196
Reputation: 319
The answer is to explicitly call a javascript function in the OnAfterRenderAsync override to apply the JQuery UI functions to the modal divs.
E.g.
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jsRuntime.InvokeVoidAsync("setModalDraggableAndResizable");
await base.OnAfterRenderAsync(firstRender);
}
where setModalDraggableAndResizable
is a javascript function in the _Hosts.cshtml:
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<script type="text/javascript">
function setModalDraggableAndResizable() {
$('.modal-content').resizable({
//alsoResize: ".modal-dialog",
minHeight: 300,
minWidth: 300
});
$('.modal-dialog').draggable();
}
</script>
And the modal is now draggable and resizable...
Upvotes: 3