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