PageSourceSearch

https://havit.blazor.eu/_content/Havit.Blazor.Components.Web.Bootstrap/HxModal.20e5swp7tp.js

js blazor.eu collected 2026-09-24 22:59:56 UTC 3,538 bytes, 119 lines download raw bytes

1export function show(element, hxModalDotnetObjectReference, closeOnEscape, subscribeToHideEvent) {
2	if (window.modalElement) {
3		const previousModal = bootstrap.Modal.getInstance(window.modalElement);
4		if (previousModal) {
5			previousModal.hide();
6		}
7	}
8
9	if (!element) {
10		return;
11	}
12
13	// Remove old listeners to prevent duplicates when show() is called multiple times
14	element.removeEventListener('hide.bs.modal', handleModalHide);
15	element.removeEventListener('hidden.bs.modal', handleModalHidden);
16	element.removeEventListener('shown.bs.modal', handleModalShown);
17
18	element.hxModalDotnetObjectReference = hxModalDotnetObjectReference;
19	if (subscribeToHideEvent) {
20		element.addEventListener('hide.bs.modal', handleModalHide);
21	}
22	element.addEventListener('hidden.bs.modal', handleModalHidden);
23	element.addEventListener('shown.bs.modal', handleModalShown);
24	window.modalElement = element;
25
26	let modal = bootstrap.Modal.getInstance(element);
27	if (!modal) {
28		modal = new bootstrap.Modal(element, {
29			keyboard: closeOnEscape
30		});
31	}
32	modal.show();
33}
34
35export function hide(element) {
36	if (!element) {
37		return;
38	}
39	element.hxModalHiding = true;
40	const modal = bootstrap.Modal.getInstance(element);
41	if (modal) {
42		modal.hide();
43	}
44}
45
46function handleModalShown(event) {
47	event.target.hxModalDotnetObjectReference.invokeMethodAsync('HxModal_HandleModalShown');
48}
49
50async function handleModalHide(event) {
51	const modalInstance = bootstrap.Modal.getInstance(event.target);
52
53	if (modalInstance.hidePreventionDisabled || event.target.hxModalDisposing) {
54		modalInstance.hidePreventionDisabled = false;
55		return;
56	}
57
58    event.preventDefault();
59
60	const cancel = await event.target.hxModalDotnetObjectReference.invokeMethodAsync('HxModal_HandleModalHide');
61    if (!cancel) {
62		modalInstance.hidePreventionDisabled = true;
63		event.target.hxModalHiding = true;
64		modalInstance.hide();
65    }
66}
67
68function handleModalHidden(event) {
69	event.target.hxModalHiding = false;
70
71	if (event.target === window.modalElement) {
72		window.modalElement = null;
73	}
74
75	if (event.target.hxModalDisposing) {
76		// fix for #110 where the dispose() gets called while the modal is still in hiding-transition
77		dispose(event.target, false);
78		return;
79	}
80
81	event.target.hxModalDotnetObjectReference.invokeMethodAsync('HxModal_HandleModalHidden');
82}
83
84export function dispose(element, opened) {
85	if (!element) {
86		return;
87	}
88
89	element.hxModalDisposing = true;
90
91	if (element.hxModalHiding) {
92		// fix for #110 where the dispose() gets called while the modal is still in hiding-transition
93		return;
94	}
95
96	if (opened) {
97		// #110 Scrolling not working when modal is removed (even if disposed is called)
98		// Compensates https://github.com/twbs/bootstrap/issues/36397,
99		// where the o.dispose() does not reset the ScrollBarHelper() and the scrolling remains deactivated.
100		// The dispose() is re-called from hidden.bs.modal event handler.
101		// Remove when the issue is fixed.
102		hide(element);
103		return;
104	}
105
106	element.removeEventListener('hide.bs.modal', handleModalHide);
107	element.removeEventListener('hidden.bs.modal', handleModalHidden);
108	element.removeEventListener('shown.bs.modal', handleModalShown);
109	element.hxModalDotnetObjectReference = null;
110
111	const modal = bootstrap.Modal.getInstance(element);
112	if (modal) {
113		modal.dispose();
114	}
115
116	if (element === window.modalElement) { // another modal might be already open
117		window.modalElement = null;
118	}
119}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.