blob: f142890a3e5aaff63d86e3f1f16fd3dd2bbaf96b [file] [log] [blame]
Akron00cd4d12016-05-31 21:01:11 +02001/**
Akronda5bd3a2020-10-16 17:37:49 +02002 * Hint menu alert, positioned at the exact char.
Akron00cd4d12016-05-31 21:01:11 +02003 */
Akronda5bd3a2020-10-16 17:37:49 +02004"use strict";
5
Akron00cd4d12016-05-31 21:01:11 +02006define(function () {
Akronda5bd3a2020-10-16 17:37:49 +02007
Akron00cd4d12016-05-31 21:01:11 +02008 return {
Akronda5bd3a2020-10-16 17:37:49 +02009
10 /**
11 * Construct a new alert object
12 */
Akron00cd4d12016-05-31 21:01:11 +020013 create : function (msg) {
14 return Object.create(this)._init(msg);
15 },
Akronda5bd3a2020-10-16 17:37:49 +020016
17 // Init
Akron00cd4d12016-05-31 21:01:11 +020018 _init : function (msg) {
Akronda5bd3a2020-10-16 17:37:49 +020019 const t = this;
20 t._type = 'alert';
21 t.active = false;
Akron24aa0052020-11-10 11:00:34 +010022 t._el = document.createElement('div');
23 t._el.style.display = 'none';
24 t._el.classList.add('alert', 'hint');
Akronda5bd3a2020-10-16 17:37:49 +020025 return t;
Akron00cd4d12016-05-31 21:01:11 +020026 },
27
Akronda5bd3a2020-10-16 17:37:49 +020028
29 /**
30 * Show alert.
31 */
32 show : function (msg) {
Akron24aa0052020-11-10 11:00:34 +010033 const e = this._el;
Akronbe2f9a02025-01-14 09:36:55 +010034 if (msg !== undefined)
35 e.textContent = msg;
36 if (e.textContent == "")
37 return;
38 this.active = true;
Akronda5bd3a2020-10-16 17:37:49 +020039 e.style.display = 'block';
40 },
41
42
43 /**
44 * Hide alert.
45 */
Akron02360e42016-06-07 13:41:12 +020046 hide : function () {
Akron00cd4d12016-05-31 21:01:11 +020047 if (!this.active)
Akrond30e2002016-11-07 03:19:58 +010048 return false;
Akron24aa0052020-11-10 11:00:34 +010049 this._el.style.display = 'none';
Akron00cd4d12016-05-31 21:01:11 +020050 this.active = false;
51 return true;
52 },
53
Akronda5bd3a2020-10-16 17:37:49 +020054
55 /**
56 * Get alert object.
57 */
Akron00cd4d12016-05-31 21:01:11 +020058 element : function () {
Akron24aa0052020-11-10 11:00:34 +010059 return this._el;
Akron00cd4d12016-05-31 21:01:11 +020060 }
61 }
62});