Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Information about a match. |
| 3 | */ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 4 | define([ |
| 5 | 'match/infolayer', |
| 6 | 'match/table', |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 7 | 'match/treehierarchy', |
| 8 | 'match/treearc', |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 9 | 'match/meta', |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 10 | 'util' |
| 11 | ], function (infoLayerClass, |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 12 | matchTableClass, |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 13 | matchTreeHierarchyClass, |
| 14 | matchTreeArcClass, |
Akron | b6685bb | 2018-02-04 00:44:47 +0100 | [diff] [blame] | 15 | matchMetaClass) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 16 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 17 | // Override |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 18 | KorAP.API.getMatchInfo = KorAP.API.getMatchInfo || function () { |
| 19 | KorAP.log(0, 'KorAP.API.getMatchInfo() not implemented') |
| 20 | return {}; |
| 21 | }; |
| 22 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 23 | const loc = KorAP.Locale; |
| 24 | const d = document; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 25 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 26 | return { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Create new match object |
| 30 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 31 | create : function (match) { |
| 32 | return Object.create(this)._init(match); |
| 33 | }, |
| 34 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 35 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 36 | /** |
| 37 | * Initialize object |
| 38 | */ |
| 39 | _init : function (match) { |
| 40 | this._match = match; |
| 41 | this.opened = false; |
| 42 | return this; |
| 43 | }, |
| 44 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 45 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 46 | /** |
| 47 | * Get match object |
| 48 | */ |
| 49 | match : function () { |
| 50 | return this._match; |
| 51 | }, |
| 52 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Open the information view, |
| 56 | * if closed, otherwise close. |
| 57 | */ |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 58 | /* |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 59 | toggle : function () { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 60 | |
Akron | 08b82d6 | 2016-12-05 15:06:05 +0100 | [diff] [blame] | 61 | var elem = this._match.element(); |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 62 | |
| 63 | if (this.opened == true) { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 64 | elem.removeChild( |
| 65 | this.element() |
| 66 | ); |
| 67 | this.opened = false; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 68 | } |
| 69 | else { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 70 | // Append element to match |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 71 | elem.appendChild( |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 72 | this.element() |
| 73 | ); |
| 74 | this.opened = true; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | return this.opened; |
| 78 | }, |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 79 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 80 | |
| 81 | |
| 82 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 83 | * Retrieve and parse snippet for table |
| 84 | * representation |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 85 | */ |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 86 | getTableData : function (tokens, cb) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 87 | var focus = []; |
| 88 | |
| 89 | // Get all tokens |
| 90 | if (tokens === undefined) { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 91 | focus = this._match.getTokens(); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // Get only some tokens |
| 95 | else { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 96 | |
| 97 | // Push newly to focus array |
| 98 | for (var i = 0; i < tokens.length; i++) { |
| 99 | var term = tokens[i]; |
| 100 | try { |
| 101 | // Create info layer objects |
| 102 | var layer = infoLayerClass.create(term); |
| 103 | layer.type = "tokens"; |
| 104 | focus.push(layer); |
| 105 | } |
| 106 | catch (e) { |
| 107 | continue; |
| 108 | }; |
| 109 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | // No tokens chosen |
| 113 | if (focus.length == 0) |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 114 | cb(null); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 115 | |
| 116 | // Get info (may be cached) |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 117 | KorAP.API.getMatchInfo( |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 118 | this._match, |
| 119 | { 'spans' : false, 'layer' : focus }, |
| 120 | |
| 121 | // Callback for retrieval |
| 122 | function (matchResponse) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 123 | |
Akron | 515851a | 2017-05-02 12:53:17 +0200 | [diff] [blame] | 124 | if (matchResponse === undefined) |
| 125 | cb(null); |
| 126 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 127 | // Get snippet from match info |
| 128 | if (matchResponse["snippet"] !== undefined) { |
| 129 | this._table = matchTableClass.create(matchResponse["snippet"]); |
| 130 | cb(this._table); |
| 131 | }; |
| 132 | }.bind(this) |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 133 | ); |
| 134 | |
| 135 | /* |
| 136 | // Todo: Store the table as a hash of the focus |
| 137 | return null; |
| 138 | */ |
| 139 | }, |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 140 | |
| 141 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 142 | getMetaData : function (metaInfo, cb) { |
| 143 | // ... |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 144 | }, |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 145 | |
| 146 | |
| 147 | /** |
| 148 | * Retrieve and parse snippet for tree representation |
| 149 | */ |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 150 | getTreeData : function (foundry, layer, type, cb) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 151 | var focus = []; |
| 152 | |
| 153 | // TODO: Support and cache multiple trees |
| 154 | KorAP.API.getMatchInfo( |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 155 | this._match, { |
| 156 | 'spans' : true, |
| 157 | 'foundry' : foundry, |
| 158 | 'layer' : layer |
| 159 | }, |
| 160 | function (matchResponse) { |
| 161 | // Get snippet from match info |
| 162 | if (matchResponse["snippet"] !== undefined) { |
| 163 | // Todo: This should be cached somehow |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 164 | |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 165 | if (type === "spans") { |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 166 | cb(matchTreeHierarchyClass.create(matchResponse["snippet"])); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 167 | } |
| 168 | else if (type === "rels") { |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 169 | cb(matchTreeArcClass.create(matchResponse["snippet"])); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | // Unknown tree type |
| 173 | else { |
| 174 | cb(null); |
| 175 | }; |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 176 | } |
| 177 | else { |
| 178 | cb(null); |
| 179 | }; |
| 180 | }.bind(this) |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 181 | ); |
| 182 | }, |
| 183 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 184 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 185 | /** |
| 186 | * Destroy this match information view. |
| 187 | */ |
| 188 | destroy : function () { |
| 189 | |
| 190 | // Remove circular reference |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 191 | /* |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 192 | if (this._treeMenu !== undefined) |
Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 193 | delete this._treeMenu["info"]; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 194 | |
| 195 | this._treeMenu.destroy(); |
| 196 | this._treeMenu = undefined; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 197 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 198 | this._match = undefined; |
Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 199 | this._matchCreator = undefined; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 200 | // Element destroy |
| 201 | }, |
| 202 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 203 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 204 | /** |
| 205 | * Add a new tree view to the list |
| 206 | */ |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 207 | showTree : function (foundry, layer, type, cb) { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 208 | var matchtree = d.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 209 | matchtree.classList.add('matchtree', 'loading'); |
| 210 | |
| 211 | this.element().appendChild(matchtree); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 212 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 213 | // Add title line |
| 214 | var h6 = matchtree.addE('h6'); |
| 215 | h6.addE('span').addT(foundry); |
| 216 | h6.addE('span').addT(layer); |
| 217 | |
| 218 | var tree = matchtree.addE('div'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 219 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 220 | // Add close action button |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 221 | var actions = this._addButton('close', matchtree, function (e) { |
| 222 | this.parentNode.removeChild(this); |
| 223 | e.halt(); |
| 224 | }); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 225 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 226 | // tree.classList.add('loading'); // alternatively |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 227 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 228 | // Get tree data async |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 229 | this.getTreeData(foundry, layer, type, function (treeObj) { |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 230 | matchtree.classList.remove('loading'); |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 231 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 232 | // Something went wrong - probably log!!! |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 233 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 234 | if (treeObj === null) { |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 235 | tree.addT('No data available.'); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 236 | } |
| 237 | else { |
| 238 | tree.appendChild(treeObj.element()); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 239 | treeObj.show(); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 240 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 241 | // Reposition the view to the center |
| 242 | // (This may in a future release be a reposition |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 243 | // to move the root to the actual match) |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 244 | |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 245 | // This is currently not supported by relations |
| 246 | if (type === "spans") { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 247 | var dl = d.createElement('li'); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 248 | dl.className = 'download'; |
| 249 | dl.addEventListener( |
| 250 | 'click', function (e) { |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 251 | var a = treeObj.downloadLink(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 252 | d.body.appendChild(a); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 253 | a.click(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 254 | d.body.removeChild(a) |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 255 | e.halt(); |
| 256 | } |
| 257 | ); |
| 258 | |
| 259 | actions.appendChild(dl); |
| 260 | }; |
| 261 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 262 | treeObj.center(); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | if (cb !== undefined) |
| 266 | cb(treeObj); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 267 | }); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 268 | matchtree.classList.remove('loading'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 269 | }, |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 270 | |
| 271 | |
Akron | e767969 | 2018-01-26 12:06:33 +0100 | [diff] [blame] | 272 | // Add meta information to match |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 273 | showMeta : function () { |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 274 | var metaTable = document.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 275 | metaTable.classList.add('metatable', 'loading'); |
| 276 | this.element().appendChild(metaTable); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 277 | |
| 278 | // TODO: This is part of the getMeta! |
| 279 | var metaInfo = this._match.element().getAttribute('data-info'); |
| 280 | |
| 281 | if (metaInfo) |
| 282 | metaInfo = JSON.parse(metaInfo); |
| 283 | |
| 284 | // There is metainfo |
| 285 | if (metaInfo) { |
| 286 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 287 | // Load data |
| 288 | metaTable.classList.remove('loading'); |
| 289 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 290 | // Add metainfo to matchview |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 291 | var metaElem = matchMetaClass.create(this._match).element(metaInfo); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 292 | metaTable.appendChild(metaElem); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 293 | |
| 294 | // Add button |
| 295 | this._addButton('close', metaTable, function (e) { |
| 296 | this.parentNode.removeChild(this); |
| 297 | e.halt(); |
| 298 | }); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 299 | }; |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 300 | |
| 301 | // Load data |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 302 | metaTable.classList.remove('loading'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 303 | }, |
| 304 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 305 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 306 | // Add table |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 307 | showTable : function () { |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 308 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 309 | // Append default table |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 310 | var matchtable = d.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 311 | matchtable.classList.add('matchtable', 'loading'); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 312 | var info = this.element(); |
| 313 | info.appendChild(matchtable); |
| 314 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 315 | |
Akron | b6685bb | 2018-02-04 00:44:47 +0100 | [diff] [blame] | 316 | // TODO: |
| 317 | // Create try-catch-exception-handling |
| 318 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 319 | // Create the table asynchronous |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 320 | this.getTableData(undefined, function (table) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 321 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 322 | // Load data |
| 323 | matchtable.classList.remove('loading'); |
| 324 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 325 | if (table !== null) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 326 | matchtable.appendChild(table.element()); |
| 327 | }; |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 328 | |
| 329 | // Load data |
| 330 | matchtable.classList.remove('loading'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 331 | }); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 332 | |
| 333 | // Add button |
| 334 | this._addButton('close', matchtable, function (e) { |
| 335 | this.parentNode.removeChild(this); |
| 336 | e.halt(); |
| 337 | }); |
| 338 | |
| 339 | // Load data |
| 340 | matchtable.classList.remove('loading'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 341 | }, |
| 342 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 343 | // Add action button |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 344 | _addButton : function (buttonType, element, cb) { |
| 345 | // TODO: Unless existent |
| 346 | var actions = document.createElement('ul'); |
| 347 | actions.classList.add('action', 'image'); |
| 348 | var b = actions.addE('li'); |
| 349 | b.className = buttonType; |
| 350 | b.addE('span').addT(buttonType); |
| 351 | b.addEventListener( |
| 352 | 'click', cb.bind(element) |
| 353 | ); |
| 354 | |
| 355 | element.appendChild(actions); |
| 356 | return actions; |
| 357 | }, |
| 358 | |
| 359 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 360 | /** |
| 361 | * Create match information view. |
| 362 | */ |
| 363 | element : function () { |
| 364 | |
| 365 | if (this._element !== undefined) |
| 366 | return this._element; |
| 367 | |
| 368 | // Create info table |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 369 | var info = d.createElement('div'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 370 | info.classList.add('matchinfo'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 371 | |
| 372 | this._element = info; |
| 373 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 374 | return this._element; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 375 | } |
| 376 | }; |
| 377 | }); |