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; | ||||
22 | t._element = document.createElement('div'); | ||||
23 | t._element.style.display = 'none'; | ||||
24 | t._element.classList.add('alert', 'hint'); | ||||
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) { | ||||
33 | this.active = true; | ||||
34 | const e = this._element; | ||||
35 | e.textContent = msg; | ||||
36 | e.style.display = 'block'; | ||||
37 | }, | ||||
38 | |||||
39 | |||||
40 | /** | ||||
41 | * Hide alert. | ||||
42 | */ | ||||
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 43 | hide : function () { |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 44 | if (!this.active) |
Akron | d30e200 | 2016-11-07 03:19:58 +0100 | [diff] [blame] | 45 | return false; |
46 | this._element.style.display = 'none'; | ||||
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 47 | this.active = false; |
48 | return true; | ||||
49 | }, | ||||
50 | |||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame^] | 51 | |
52 | /** | ||||
53 | * Get alert object. | ||||
54 | */ | ||||
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 55 | element : function () { |
56 | return this._element; | ||||
57 | } | ||||
58 | } | ||||
59 | }); |