blob: 6bcff44ddaf419e9515627d5492c53d10306f706 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001 /**
2 * Menu to choose from for tree views.
3 */
4define(['menu', 'match/treeitem'], function (menuClass, itemClass) {
5 "use strict";
6
7 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +00008
9 /**
10 * Create new menu object.
11 * Pass the match information object
12 * and the item parameters.
13 *
14 * @param info The match info object
15 * @param params The match menu items
16 * as an array of arrays.
17 */
Akroneaba63e2018-01-26 19:49:30 +010018 create : function (list) {
Nils Diewald0e6992a2015-04-14 20:13:52 +000019 var obj = Object.create(menuClass)
Akrond67d45b2017-05-18 21:47:38 +020020 .upgradeTo(this)
Akron0988d882017-11-10 16:13:12 +010021 ._init(list, {itemClass : itemClass});
Nils Diewald0e6992a2015-04-14 20:13:52 +000022 obj.limit(6);
Akroneaba63e2018-01-26 19:49:30 +010023
24 var e = obj.element();
Nils Diewald0e6992a2015-04-14 20:13:52 +000025
26 // This is only domspecific
Akroneaba63e2018-01-26 19:49:30 +010027 e.addEventListener('blur', function (e) {
Akrond67d45b2017-05-18 21:47:38 +020028 this.menu.hide();
Nils Diewald0e6992a2015-04-14 20:13:52 +000029 });
Akroneaba63e2018-01-26 19:49:30 +010030
31 e.setAttribute('id', 'treeMenu');
32
33 // Add menu to body
34 document.getElementsByTagName('body')[0].appendChild(e);
35
Nils Diewald0e6992a2015-04-14 20:13:52 +000036 return obj;
37 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000038
39 /**
40 * The match information object of the menu.
41 */
Akroneaba63e2018-01-26 19:49:30 +010042 info :function (infoVar) {
43 if (infoVar !== undefined)
44 this._info = infoVar;
45
Nils Diewald0e6992a2015-04-14 20:13:52 +000046 return this._info;
Akroneaba63e2018-01-26 19:49:30 +010047 },
48
49 // Attach menu to
50 attachTo : function (e) {
51 var bounding = e.getBoundingClientRect();
52 this._element.style.left = bounding.left + "px";
53 this._element.style.top = bounding.top + "px";
54 this.slider().reInit();
Nils Diewald0e6992a2015-04-14 20:13:52 +000055 }
56 };
57});