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) { |
| 33 | this.active = true; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 34 | const e = this._el; |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 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; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 46 | this._el.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 () { |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 56 | return this._el; |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | }); |