blob: 0889e11cacdf3f652bece5658815cfa9a63eb8a8 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
2 * Hint menu item based on MenuItem
3 */
Akrone51eaa32020-11-10 09:35:53 +01004"use strict";
5
Akron0b489ad2018-02-02 16:49:32 +01006define(['menu/item', 'util'], function (itemClass) {
Nils Diewald0e6992a2015-04-14 20:13:52 +00007 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +00008
9 /**
10 * Create new menu item object.
11 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000012 create : function (params) {
13 return Object.create(itemClass)
Akron65c74352016-09-02 17:23:39 +020014 .upgradeTo(this)
15 ._init(params);
Nils Diewald0e6992a2015-04-14 20:13:52 +000016 },
Nils Diewald47f366b2015-04-15 20:06:35 +000017
Nils Diewald7148c6f2015-05-04 15:07:53 +000018 // Initialize menu item object
Nils Diewald0e6992a2015-04-14 20:13:52 +000019 _init : function (params) {
20 if (params[0] === undefined ||
Akron65c74352016-09-02 17:23:39 +020021 params[1] === undefined)
22 throw new Error("Missing parameters");
Nils Diewald0e6992a2015-04-14 20:13:52 +000023
24 this._name = params[0];
25 this._action = params[1];
26 this._lcField = ' ' + this._name.toLowerCase();
27
28 if (params.length > 2) {
Akron65c74352016-09-02 17:23:39 +020029 this._desc = params[2];
30 this._lcField += " " + this._desc.toLowerCase();
Nils Diewald0e6992a2015-04-14 20:13:52 +000031 };
32
33 return this;
34 },
35
Nils Diewald7148c6f2015-05-04 15:07:53 +000036 /**
37 * Get or set the content of the item.
38 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000039 content : function (content) {
40 if (arguments.length === 1) {
Akron65c74352016-09-02 17:23:39 +020041 this._content = content;
Nils Diewald0e6992a2015-04-14 20:13:52 +000042 };
43 return this._content;
44 },
Akron52ed22d2018-07-11 17:05:19 +020045
Nils Diewald7148c6f2015-05-04 15:07:53 +000046 /**
47 * Override the click action
48 * of the menu item.
49 */
Nils Diewald47f366b2015-04-15 20:06:35 +000050 onclick : function (e) {
Nils Diewald0e6992a2015-04-14 20:13:52 +000051 var m = this.menu();
Akron02360e42016-06-07 13:41:12 +020052 // m.hide();
Nils Diewald0e6992a2015-04-14 20:13:52 +000053
Leo Repp57997402021-08-18 16:37:52 +020054 // Reset prefix and update the input field
55 m.reset(this._action);
Nils Diewald0e6992a2015-04-14 20:13:52 +000056
Nils Diewald47f366b2015-04-15 20:06:35 +000057 e.halt();
Akron95abaf42018-04-26 15:33:22 +020058
Akron02360e42016-06-07 13:41:12 +020059 // show alt
Leo Repp57997402021-08-18 16:37:52 +020060 m.hint().show(true);
Nils Diewald0e6992a2015-04-14 20:13:52 +000061 },
Nils Diewald47f366b2015-04-15 20:06:35 +000062
Nils Diewald7148c6f2015-05-04 15:07:53 +000063 /**
64 * The name of the menu entry.
65 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000066 name : function () {
67 return this._name;
68 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000069
70 /**
71 * The action (the string inserted on click)
72 * of the menu item.
73 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000074 action : function () {
75 return this._action;
76 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000077
78 /**
79 * The description of the menu item.
80 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000081 desc : function () {
82 return this._desc;
83 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000084
85 /**
86 * The associated dom element of the
87 * menu item.
88 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000089 element : function () {
90 // already defined
Akron24aa0052020-11-10 11:00:34 +010091 if (this._el !== undefined)
92 return this._el;
Nils Diewald0e6992a2015-04-14 20:13:52 +000093
94 // Create list item
95 var li = document.createElement("li");
96
97 if (this.onclick !== undefined) {
Akron65c74352016-09-02 17:23:39 +020098 li["onclick"] = this.onclick.bind(this);
Nils Diewald0e6992a2015-04-14 20:13:52 +000099 };
100
101 // Create title
102 var name = document.createElement("span");
Akron0b489ad2018-02-02 16:49:32 +0100103 name.addT(this._name);
Nils Diewald0e6992a2015-04-14 20:13:52 +0000104
105 li.appendChild(name);
106
107 // Create description
108 if (this._desc !== undefined) {
Akron65c74352016-09-02 17:23:39 +0200109 var desc = document.createElement("span");
110 desc.classList.add('desc');
Akron0b489ad2018-02-02 16:49:32 +0100111 desc.addT(this._desc);
Akron65c74352016-09-02 17:23:39 +0200112 li.appendChild(desc);
Nils Diewald0e6992a2015-04-14 20:13:52 +0000113 };
Akron24aa0052020-11-10 11:00:34 +0100114 return this._el = li;
Nils Diewald0e6992a2015-04-14 20:13:52 +0000115 }
116 };
117});