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'], |
| 63 | ['Veröffentlichungsdatum', 'pubDate', 'date'], |
| 64 | ['Länge', 'length', 'integer'], |
| 65 | ['Autor', 'author', 'string'], |
| 66 | ['Genre', 'genre', 'string'], |
| 67 | ['corpusID', 'corpusID', 'string'], |
| 68 | ['docID', 'docID', 'string'], |
| 69 | ['textID', 'textID', 'string'] |
| 70 | ]); |
| 71 | |
| 72 | document.getElementById('menu').appendChild(menu.element()); |
| 73 | |
| 74 | menu.limit(3); |
| 75 | menu.show(''); |
| 76 | menu.focus(); |
| 77 | }); |