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