Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | requirejs.config({ |
| 2 | baseUrl: '../js/src' |
| 3 | }); |
| 4 | |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 5 | require(['menu','menu/item', 'menu/prefix', 'menu/lengthField'], function (menuClass, itemClass, prefixClass, lengthFieldClass) { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 6 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 7 | var OwnMenuItemClass = { |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 8 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 9 | create : function (params) { |
| 10 | return Object.create(itemClass).upgradeTo(this)._init(params); |
| 11 | }, |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 12 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 13 | content : function (content) { |
| 14 | if (arguments.length === 1) { |
| 15 | this._content = content; |
| 16 | }; |
| 17 | return this._content; |
| 18 | }, |
| 19 | |
| 20 | // enter or click |
| 21 | onclick : function () { |
| 22 | console.log(this._name); |
| 23 | }, |
| 24 | |
| 25 | // right arrow |
| 26 | further : function () { |
| 27 | console.log("Further: " + this._name); |
| 28 | }, |
| 29 | _init : function (params) { |
| 30 | if (params[0] === undefined) |
| 31 | throw new Error("Missing parameters"); |
| 32 | |
| 33 | this._name = params[0]; |
| 34 | this._content = document.createTextNode(this._name); |
| 35 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 36 | |
| 37 | return this; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | var OwnPrefixClass = { |
| 42 | create : function () { |
| 43 | return Object.create(prefixClass) |
| 44 | .upgradeTo(this) |
| 45 | ._init(); |
| 46 | }, |
| 47 | onclick : function () { |
| 48 | console.log('Prefix: ' + this.value()); |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | var OwnMenu = { |
| 53 | create : function (params) { |
Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 54 | var obj = Object.create(menuClass) |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 55 | .upgradeTo(this) |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 56 | ._init(OwnMenuItemClass, OwnPrefixClass, lengthFieldClass, params); |
Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 57 | obj._firstActive = true; |
| 58 | return obj; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 59 | } |
| 60 | }; |
| 61 | |
| 62 | var menu = OwnMenu.create([ |
| 63 | ['Titel', 'title', 'string'], |
| 64 | ['Untertitel', 'subTitle', 'string'], |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 65 | ['Beschreibung', 'desc', 'string'], |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 66 | ['Veröffentlichungsdatum', 'pubDate', 'date'], |
| 67 | ['Länge', 'length', 'integer'], |
| 68 | ['Autor', 'author', 'string'], |
| 69 | ['Genre', 'genre', 'string'], |
| 70 | ['corpusID', 'corpusID', 'string'], |
| 71 | ['docID', 'docID', 'string'], |
| 72 | ['textID', 'textID', 'string'] |
| 73 | ]); |
| 74 | |
| 75 | document.getElementById('menu').appendChild(menu.element()); |
| 76 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 77 | menu.limit(3); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 78 | menu.show(0); // Make this a 3 |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 79 | menu.focus(); |
| 80 | }); |