@@ -5,7 +5,7 @@ import { i18n } from "../localization";
5
5
* Gets the title bar for a modal dialog.
6
6
* @param {string } messageId Localized message identifier.
7
7
* @param {object } [messageParameters] Localized message parameters
8
- * @param {() => void } onClose Function invoked by close button.
8
+ * @param {() => void } onClose Function invoked by the close button.
9
9
* @returns {JQuery<HTMLElement> } Dialog title bar.
10
10
*/
11
11
function getDialogTitleBar ( messageId , messageParameters , onClose ) {
@@ -31,31 +31,34 @@ function getDialogTitleBar(messageId, messageParameters, onClose) {
31
31
32
32
/**
33
33
* Initializes a modal dialog from an HTML dialog element.
34
- * @param {JQuery.Selector|null } buttonSelector JQuery selector for the activation element.
34
+ * @param {JQuery.Selector|null } activationSelector JQuery selector for the activation element.
35
35
* @param {JQuery.Selector } dialogSelector JQuery selector for the dialog element.
36
36
* @param {string } messageId Localized message identifier.
37
37
* @param {object } [messageParameters] Localized message parameters
38
- * @param {() => void } [onClose] Function invoked by close button .
38
+ * @param {() => void } [onClose] Function invoked when the dialog is closed .
39
39
* @returns {HTMLDialogElement } HTML dialog element.
40
40
*/
41
- export function initializeModalDialog ( buttonSelector , dialogSelector , messageId , messageParameters , onClose ) {
42
- // Get dialog elements
41
+ export function initializeModalDialog ( activationSelector , dialogSelector , messageId , messageParameters , onClose ) {
42
+ // Get dialog references
43
43
const dialog = $ ( dialogSelector ) ;
44
44
const dialogElement = dialog . get ( 0 ) ;
45
45
const dialogContainerElement = dialog . children ( ) . first ( ) . get ( 0 ) ;
46
46
// Add dialog title bar
47
47
dialog . prepend (
48
48
getDialogTitleBar ( messageId , messageParameters , ( ) => {
49
49
dialogElement . close ( ) ;
50
- onClose && onClose ( ) ;
51
50
} ) ,
52
51
) ;
53
- // Handle button click
54
- $ ( buttonSelector ) . on ( "click" , ( ) => {
52
+ // Handle close event
53
+ dialogElement . addEventListener ( "close" , ( ) => {
54
+ onClose && onClose ( ) ;
55
+ } ) ;
56
+ // Handle activation button click
57
+ $ ( activationSelector ) . on ( "click" , ( ) => {
55
58
dialogElement . showModal ( ) ;
56
59
// Reset any previous scrolling
57
60
dialogContainerElement . scroll ( 0 , 0 ) ;
58
61
} ) ;
59
- // Return dialog
62
+ // Return dialog element
60
63
return dialogElement ;
61
64
}
0 commit comments