1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | import NonModalBaseDialog from './NonModalBaseDialog.js'; |
26 | import DockableBaseDialogMover from './DockableBaseDialogMover.js'; |
27 | import theConfig from '../../data/Config.js'; |
28 | import BaseContextMenu from '../../contextMenus/baseContextMenu/BaseContextMenu.js'; |
29 | import { ZERO } from '../../main/Constants.js'; |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | class DockableBaseDialog extends NonModalBaseDialog { |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | #dialogX; |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | #dialogY; |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | #mouseLeaveTimerId; |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | #dockableBaseDialogMover; |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | #lastMouseEventTimestamp; |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | #isShow; |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | static get #MOUSE_EVENT_MAX_DELAY ( ) { return 100; } |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | static get #MIN_MOUSE_LEAVE_TIMEOUT ( ) { return 1500; } |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | #hideContent ( ) { |
103 | if ( this.mover.dialogDocked ) { |
104 | if ( BaseContextMenu.isActive ) { |
105 | this.#mouseLeaveTimerId = setTimeout ( |
106 | ( ) => { this.#hideContent ( ); }, |
107 | Math.max ( DockableBaseDialog.#MIN_MOUSE_LEAVE_TIMEOUT, theConfig.dockableBaseDialog.timeout ) |
108 | ); |
109 | } |
110 | else { |
111 | this.mover.dialogHTMLElement.classList.add ( |
112 | 'TravelNotes-DockableBaseDialog-HiddenContent' |
113 | ); |
114 | } |
115 | } |
116 | } |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | #mouseEnterDialogEL ( mouseEvent ) { |
124 | this.#lastMouseEventTimestamp = mouseEvent.timeStamp; |
125 | if ( this.#mouseLeaveTimerId ) { |
126 | clearTimeout ( this.#mouseLeaveTimerId ); |
127 | this.#mouseLeaveTimerId = null; |
128 | } |
129 | if ( this.mover.dialogDocked ) { |
130 | this.mover.dialogHTMLElement.classList.remove ( 'TravelNotes-DockableBaseDialog-HiddenContent' ); |
131 | } |
132 | } |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | #mouseLeaveDialogEL ( ) { |
139 | if ( this.mover.dialogDocked ) { |
140 | this.#mouseLeaveTimerId = setTimeout ( |
141 | ( ) => { this.#hideContent ( ); }, |
142 | Math.max ( DockableBaseDialog.#MIN_MOUSE_LEAVE_TIMEOUT, theConfig.dockableBaseDialog.timeout ) |
143 | ); |
144 | } |
145 | } |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | #topBarClickEL ( clickEvent ) { |
153 | clickEvent.preventDefault ( ); |
154 | if ( DockableBaseDialog.#MOUSE_EVENT_MAX_DELAY > clickEvent.timeStamp - this.#lastMouseEventTimestamp ) { |
155 | return; |
156 | } |
157 | if ( this.mover.dialogDocked ) { |
158 | this.mover.dialogHTMLElement.classList.toggle ( 'TravelNotes-DockableBaseDialog-HiddenContent' ); |
159 | } |
160 | } |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | constructor ( dialogX, dialogY ) { |
169 | super ( ); |
170 | this.#dialogX = dialogX; |
171 | this.#dialogY = dialogY; |
172 | this.#mouseLeaveTimerId = null; |
173 | this.#dockableBaseDialogMover = null; |
174 | this.#lastMouseEventTimestamp = ZERO; |
175 | this.#isShow = false; |
176 | } |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | get mover ( ) { |
185 | return this.#dockableBaseDialogMover ? |
186 | this.#dockableBaseDialogMover : |
187 | this.#dockableBaseDialogMover = new DockableBaseDialogMover ( ); |
188 | } |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | onCancel ( ) { |
195 | super.onCancel ( ); |
196 | this.#isShow = false; |
197 | if ( this.#dockableBaseDialogMover ) { |
198 | this.#dockableBaseDialogMover = null; |
199 | } |
200 | } |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | show ( ) { |
207 | if ( this.#isShow ) { |
208 | return; |
209 | } |
210 | super.show ( ); |
211 | this.addCssClass ( 'TravelNotes-DockableBaseDialog' ); |
212 | this.updateContent ( ); |
213 | if ( null !== this.#dialogX && null !== this.#dialogY ) { |
214 | this.mover.moveDialogTo ( this.#dialogX, this.#dialogY ); |
215 | this.#dialogX = null; |
216 | this.#dialogY = null; |
217 | } |
218 | else { |
219 | this.mover.moveDialogToLastPosition ( ); |
220 | } |
221 | this.mover.dialogHTMLElement.addEventListener ( |
222 | 'mouseenter', |
223 | mouseEvent => this.#mouseEnterDialogEL ( mouseEvent ), |
224 | false |
225 | ); |
226 | |
227 | if ( theConfig.dockableBaseDialog.hideOnMouseLeave ) { |
228 | this.mover.dialogHTMLElement.addEventListener ( |
229 | 'mouseleave', |
230 | ( ) => this.#mouseLeaveDialogEL ( ), |
231 | false |
232 | ); |
233 | } |
234 | |
235 | this.mover.topBarHTMLElement.addEventListener ( |
236 | 'click', |
237 | clickEvent => this.#topBarClickEL ( clickEvent ), |
238 | false |
239 | ); |
240 | |
241 | if ( this.mover.dialogDocked ) { |
242 | this.mover.dialogHTMLElement.classList.add ( 'TravelNotes-DockableBaseDialog-HiddenContent' ); |
243 | } |
244 | this.#isShow = true; |
245 | } |
246 | |
247 | } |
248 | |
249 | export default DockableBaseDialog; |
250 | |
251 | |
252 | |