Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 1 | /** |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 2 | * Hint menu alert, positioned at the exact char. |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 3 | */ |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 4 | "use strict"; |
5 | |||||
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 6 | define(function () { |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 7 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 8 | return { |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 9 | |
10 | /** | ||||
11 | * Construct a new alert object | ||||
12 | */ | ||||
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 13 | create : function (msg) { |
14 | return Object.create(this)._init(msg); | ||||
15 | }, | ||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 16 | |
17 | // Init | ||||
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 18 | _init : function (msg) { |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 19 | const t = this; |
20 | t._type = 'alert'; | ||||
21 | t.active = false; | ||||
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 22 | t._el = document.createElement('div'); |
23 | t._el.style.display = 'none'; | ||||
24 | t._el.classList.add('alert', 'hint'); | ||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 25 | return t; |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 26 | }, |
27 | |||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 28 | |
29 | /** | ||||
30 | * Show alert. | ||||
31 | */ | ||||
32 | show : function (msg) { | ||||
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 33 | const e = this._el; |
Akron | be2f9a0 | 2025-01-14 09:36:55 +0100 | [diff] [blame^] | 34 | if (msg !== undefined) |
35 | e.textContent = msg; | ||||
36 | if (e.textContent == "") | ||||
37 | return; | ||||
38 | this.active = true; | ||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 39 | e.style.display = 'block'; |
40 | }, | ||||
41 | |||||
42 | |||||
43 | /** | ||||
44 | * Hide alert. | ||||
45 | */ | ||||
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 46 | hide : function () { |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 47 | if (!this.active) |
Akron | d30e200 | 2016-11-07 03:19:58 +0100 | [diff] [blame] | 48 | return false; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 49 | this._el.style.display = 'none'; |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 50 | this.active = false; |
51 | return true; | ||||
52 | }, | ||||
53 | |||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 54 | |
55 | /** | ||||
56 | * Get alert object. | ||||
57 | */ | ||||
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 58 | element : function () { |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 59 | return this._el; |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 60 | } |
61 | } | ||||
62 | }); |