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