1+ /* global */
2+
13import { Character } from "./Character.js" ;
24import { Utils } from "./Utils.js" ;
35
@@ -8,7 +10,7 @@ import {Utils} from "./Utils.js";
810// a) sets the title using pMenuItem.innerText = "xyz"
911// b) arranges the visibility using pMenuItem.style.display = true/false
1012// 2: the callback function
11- // called when the menu item is selected: (pClickEvent ) => { ... }
13+ // called when the menu item is selected: () => { ... }
1214// all menu items are re-validated when the menu pops up
1315// when all menu items are invisible, the menu-button must be made invisible
1416// since this can happen at any time, this cannot be done when the menu is shown
@@ -18,6 +20,8 @@ import {Utils} from "./Utils.js";
1820// the menu. when at least one item is visible, the menu is visible
1921// remember to call verifyApp() when that is potentially the case
2022
23+ // superclass for DropDownMenuRadio, DropDownMenuCheckBox and DropDownMenuCmd
24+
2125export class DropDownMenu {
2226
2327 // Creates an empty dropdown menu
@@ -70,19 +74,20 @@ export class DropDownMenu {
7074 let visibleCount = 0 ;
7175 if ( this . menuDropdownContent ) {
7276 for ( const chld of this . menuDropdownContent . children ) {
73- const verifyCallBack = chld . verifyCallBack ;
74- if ( verifyCallBack ) {
75- const title = verifyCallBack ( chld ) ;
77+ const titleCallBack = chld . _titleCallBack ;
78+ if ( titleCallBack ) {
79+ const title = titleCallBack ( this , chld ) ;
7680 if ( title === null ) {
7781 chld . style . display = "none" ;
7882 continue ;
7983 }
80- chld . innerText = DropDownMenu . _sanitizeMenuItemTitle ( title ) ;
84+ chld . innerHTML = DropDownMenu . _sanitizeMenuItemTitle ( title ) ;
8185 chld . style . removeProperty ( "display" ) ;
8286 }
8387 visibleCount += 1 ;
8488 }
8589 }
90+
8691 // hide the menu when it has no visible menu-items
8792 const displayVisible = this . menuDropdown . tagName === "TD" ? "table-cell" : "inline-block" ;
8893 const displayInvisible = "none" ;
@@ -102,32 +107,33 @@ export class DropDownMenu {
102107 // function is called each time the menu opens
103108 // This allows dynamic menuitem titles (use menuitem.innerText)
104109 // or visibility (use menuitem.style.display = "none"/"inline-block")
105- addMenuItem ( pTitle , pCallBack , pValue ) {
110+ addMenuItem ( pValue , pTitle , pCallBack ) {
106111 const button = Utils . createDiv ( "run-command-button" , "..." ) ;
107112 if ( pValue ) {
108113 button . _value = pValue ;
109114 }
110115 if ( typeof pTitle === "string" ) {
111116 button . innerText = DropDownMenu . _sanitizeMenuItemTitle ( pTitle ) ;
112117 } else {
113- button . verifyCallBack = pTitle ;
118+ button . _titleCallBack = pTitle ;
114119 }
115120 button . addEventListener ( "click" , ( pClickEvent ) => {
116121 pClickEvent . target . parentElement . style . display = "none" ;
117122 window . setTimeout ( ( ) => {
118123 pClickEvent . target . parentElement . style . display = "" ;
119124 } , 500 ) ;
120- this . _callback ( pClickEvent , pCallBack , pValue ) ;
125+ this . _callback ( pCallBack , pValue ) ;
121126 pClickEvent . stopPropagation ( ) ;
122127 } ) ;
123128 this . menuDropdownContent . appendChild ( button ) ;
124129 this . verifyAll ( ) ;
125130 return button ;
126131 }
127132
128- _callback ( pClickEvent , pCallBack , pValue ) {
133+ _callback ( pCallBack , pValue ) {
129134 this . _value = pValue ;
130- pCallBack ( pClickEvent ) ;
135+ pCallBack ( this , pValue ) ;
136+ this . verifyAll ( ) ;
131137 }
132138
133139 setTitle ( pTitle ) {
@@ -140,18 +146,4 @@ export class DropDownMenu {
140146 pTitle += Character . BLACK_DOWN_POINTING_TRIANGLE ;
141147 this . menuButton . innerText = DropDownMenu . _sanitizeMenuItemTitle ( pTitle ) ;
142148 }
143-
144- __showMenu ( ) {
145- this . menuDropdown . style . display = "inline-block" ;
146- }
147-
148- __hideMenu ( ) {
149- this . menuDropdown . style . display = "none" ;
150- }
151-
152- clearMenu ( ) {
153- while ( this . menuDropdownContent . firstChild ) {
154- this . menuDropdownContent . removeChild ( this . menuDropdownContent . firstChild ) ;
155- }
156- }
157149}
0 commit comments