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) { |
| 6 | var OwnMenuItemClass = { |
| 7 | create : function (params) { |
| 8 | return Object.create(itemClass).upgradeTo(this)._init(params); |
| 9 | }, |
| 10 | content : function (content) { |
| 11 | if (arguments.length === 1) { |
| 12 | this._content = content; |
| 13 | }; |
| 14 | return this._content; |
| 15 | }, |
| 16 | |
| 17 | // enter or click |
| 18 | onclick : function () { |
| 19 | console.log(this._name); |
| 20 | }, |
| 21 | |
| 22 | // right arrow |
| 23 | further : function () { |
| 24 | console.log("Further: " + this._name); |
| 25 | }, |
| 26 | _init : function (params) { |
| 27 | if (params[0] === undefined) |
| 28 | throw new Error("Missing parameters"); |
| 29 | |
| 30 | this._name = params[0]; |
| 31 | this._content = document.createTextNode(this._name); |
| 32 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 33 | |
| 34 | return this; |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | var OwnPrefixClass = { |
| 39 | create : function () { |
| 40 | return Object.create(prefixClass) |
| 41 | .upgradeTo(this) |
| 42 | ._init(); |
| 43 | }, |
| 44 | onclick : function () { |
| 45 | console.log('Prefix: ' + this.value()); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | var OwnMenu = { |
| 50 | create : function (params) { |
| 51 | return Object.create(menuClass) |
| 52 | .upgradeTo(this) |
| 53 | ._init(OwnMenuItemClass, OwnPrefixClass, params); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | var menu = OwnMenu.create([ |
| 58 | ['Titel', 'title', 'string'], |
| 59 | ['Untertitel', 'subTitle', 'string'], |
| 60 | ['Veröffentlichungsdatum', 'pubDate', 'date'], |
| 61 | ['Länge', 'length', 'integer'], |
| 62 | ['Autor', 'author', 'string'], |
| 63 | ['Genre', 'genre', 'string'], |
| 64 | ['corpusID', 'corpusID', 'string'], |
| 65 | ['docID', 'docID', 'string'], |
| 66 | ['textID', 'textID', 'string'] |
| 67 | ]); |
| 68 | |
| 69 | document.getElementById('menu').appendChild(menu.element()); |
| 70 | |
| 71 | menu.limit(3); |
| 72 | menu.show(''); |
| 73 | menu.focus(); |
| 74 | }); |