Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1 | /** |
| 2 | * API/ skeleton/ base class for an item contained within a container. |
| 3 | * Here we see which functions container supports for containerItems. |
| 4 | * |
| 5 | * @author Leo Repp |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | //"use strict"; |
| 10 | |
| 11 | define({ |
| 12 | |
| 13 | /** |
| 14 | * API for an item contained within a container |
| 15 | */ |
| 16 | create : function () { |
| 17 | return Object.create(this); //._init(); |
| 18 | }, |
| 19 | |
| 20 | /** |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 21 | * Check or set if the item is active |
| 22 | * |
| 23 | * @param {boolean|null} State of activity |
| 24 | */ |
| 25 | active : function (bool) { |
| 26 | const cl = this.element().classList; |
| 27 | if (bool === undefined) return cl.contains("active"); |
| 28 | else if (bool) cl.add("active"); |
| 29 | else cl.remove("active"); //allows for setting it to inactive if not (equal to undefined or truthy) |
| 30 | }, |
| 31 | |
| 32 | /** |
| 33 | * Get/create the document element of the container item. Can be overwritten. Standard class: li |
| 34 | */ |
| 35 | element : function () { |
| 36 | // already defined |
| 37 | if (this._el !== undefined) return this._el; |
| 38 | |
| 39 | // Create list item |
| 40 | const li = document.createElement("li"); |
| 41 | |
| 42 | // Connect action |
| 43 | if (this["onclick"] !== undefined) { |
| 44 | li["onclick"] = this.onclick.bind(this); |
| 45 | }; |
| 46 | return this._el = li; |
| 47 | }, |
| 48 | |
| 49 | /** |
| 50 | * Expected to be overwritten |
| 51 | * @returns whether the item is currently an option to be selected, or if it should just be skipped |
| 52 | */ |
| 53 | isSelectable : function () { |
| 54 | return true; |
| 55 | }, |
| 56 | |
| 57 | /** |
| 58 | * API skeleton for reading letters. Expected to be overwritten. |
| 59 | * @param {String} letter The letter to be read |
| 60 | */ |
| 61 | add : function (letter) {}, |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * API skeleton for clearing whole contents. Expected to be overwritten. |
| 66 | */ |
| 67 | clear : function () {}, |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * API skeleton method for execution. Expected to be overwritten. |
| 72 | * @param {Event} event Event passed down by menu. |
| 73 | */ |
| 74 | onclick : function (e) {}, |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * API skeleton method for when backspace is pressed. Expected to be overwritten. |
| 79 | */ |
| 80 | chop : function () {}, |
| 81 | |
| 82 | /** |
| 83 | * API skeleton method for pressing "right". Expected to be overwritten. |
| 84 | * @param {Event} event Event passed down by menu. |
| 85 | */ |
| 86 | further : function (e) {}, |
| 87 | |
| 88 | /** |
| 89 | * Return menu list. This._menu gets written by the container class |
| 90 | */ |
| 91 | menu : function () { |
| 92 | return this._menu; |
| 93 | } |
| 94 | |
Akron | b7a005a | 2021-09-21 17:43:02 +0200 | [diff] [blame] | 95 | }); |