Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Menu showing all key fields. |
| 3 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 4 | "use strict"; |
| 5 | |
| 6 | define([ |
| 7 | 'menu', |
| 8 | 'vc/item', |
| 9 | 'vc/prefix' |
| 10 | ], function ( |
| 11 | menuClass, |
| 12 | itemClass, |
| 13 | prefixClass) { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 14 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 15 | return { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 16 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 17 | create : function (params) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 18 | const obj = Object.create(menuClass) |
| 19 | .upgradeTo(this) |
| 20 | ._init(params, { |
| 21 | itemClass : itemClass, |
| 22 | prefixClass : prefixClass |
| 23 | }); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 24 | obj.limit(6); |
| 25 | |
| 26 | // This is only domspecific |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 27 | obj.element().addEventListener( |
| 28 | 'blur', function (e) { |
| 29 | this.menu.hide(); |
| 30 | } |
| 31 | ); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 32 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 33 | return obj; |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 34 | }, |
Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 35 | |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 36 | |
Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 37 | /** |
| 38 | * Register callback for click event. |
| 39 | */ |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 40 | released : function (cb) { |
| 41 | this._cb = cb; |
| 42 | }, |
Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 43 | |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 44 | |
Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 45 | /** |
| 46 | * A click event was released |
| 47 | */ |
| 48 | release : function (key, type) { |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 49 | if (this._cb !== undefined) |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 50 | this._cb(key, type); |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 51 | }, |
| 52 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 53 | |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 54 | /** |
| 55 | * Return a key type based on a key. |
| 56 | * This is a linear search, but should work okay for small |
| 57 | * VCs and small key lists. |
| 58 | */ |
| 59 | typeOf : function (key) { |
Akron | 678c26f | 2020-10-09 08:52:50 +0200 | [diff] [blame] | 60 | const found = this._items.find(i => i.key() === key); |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 61 | |
Akron | 678c26f | 2020-10-09 08:52:50 +0200 | [diff] [blame] | 62 | if (found) |
| 63 | return found.type(); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 64 | } |
| 65 | }; |
| 66 | }); |