Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 1 | /** |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 2 | * Get information on matches, |
| 3 | * generate annotation tables and trees. |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 4 | * |
| 5 | * @author Nils Diewald |
| 6 | */ |
| 7 | /* |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 8 | * - Highlight (at least mark as bold) the match |
| 9 | * - Scroll to match vertically per default |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 10 | * - A click on a table field and a tree node should at the field description to the fragments list. |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 11 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 12 | define([ |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 13 | 'match/info', // rename to anno |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 14 | 'match/treemenu', |
| 15 | 'util' |
| 16 | ], function (infoClass,matchTreeMenuClass) { //, refClass) { |
Nils Diewald | 4f6521a | 2015-03-20 21:30:13 +0000 | [diff] [blame] | 17 | |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 18 | // Localization values |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 19 | var loc = KorAP.Locale; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 20 | loc.ADDTREE = loc.ADDTREE || 'Add tree view'; |
| 21 | loc.SHOWINFO = loc.SHOWINFO || 'Show information'; |
| 22 | loc.CLOSE = loc.CLOSE || 'Close'; |
| 23 | loc.SHOW_META = loc.SHOW_META || 'Show metadata'; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 24 | |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 25 | // 'corpusID', 'docID', 'textID' |
| 26 | var _matchTerms = ['textSigle', 'matchID', 'available']; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Match object |
| 30 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 31 | return { |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Create a new annotation object. |
| 35 | * Expects an array of available foundry/layer=type terms. |
| 36 | * Supported types are 'spans', 'tokens' and 'rels'. |
| 37 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 38 | create : function (match) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 39 | return Object.create(this)._init(match); |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 40 | }, |
| 41 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 42 | |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 43 | /** |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 44 | * Initialize match. |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 45 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 46 | _init : function (match) { |
| 47 | this._element = null; |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 48 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 49 | // No match defined |
| 50 | if (arguments.length < 1 || |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 51 | match === null || |
| 52 | match === undefined) { |
| 53 | throw new Error('Missing parameters'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 54 | } |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 55 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 56 | // Match defined as a node |
| 57 | else if (match instanceof Node) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 58 | this._element = match; |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 59 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 60 | // Circular reference !! |
| 61 | match["_match"] = this; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 62 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 63 | /* |
| 64 | this.corpusID = match.getAttribute('data-corpus-id'), |
| 65 | this.docID = match.getAttribute('data-doc-id'), |
| 66 | this.textID = match.getAttribute('data-text-id'), |
| 67 | */ |
| 68 | if (match.hasAttribute('data-text-sigle')) { |
| 69 | this.textSigle = match.getAttribute('data-text-sigle') |
| 70 | } |
| 71 | else { |
| 72 | this.textSigle = match.getAttribute('data-corpus-id') + |
| 73 | '/' + |
| 74 | match.getAttribute('data-doc-id') + |
| 75 | '/' + |
| 76 | match.getAttribute('data-text-id'); |
| 77 | }; |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 78 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 79 | this.matchID = match.getAttribute('data-match-id'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 80 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 81 | // List of available annotations |
| 82 | this.available = match.getAttribute('data-available-info').split(' '); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // Match as an object |
| 86 | else { |
| 87 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 88 | // Iterate over allowed match terms |
| 89 | for (var i in _matchTerms) { |
| 90 | var term = _matchTerms[i]; |
| 91 | this[term] = match[term] !== undefined ? match[term] : undefined; |
| 92 | }; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 93 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 94 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 95 | this._avail = { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 96 | tokens : [], |
| 97 | spans : [], |
| 98 | rels : [] |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 99 | }; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 100 | |
| 101 | // Iterate over info layers |
| 102 | for (var i = 0; i < this.available.length; i++) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 103 | var term = this.available[i]; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 104 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 105 | // Create info layer objects |
| 106 | try { |
| 107 | var layer = require('match/infolayer').create(term); |
| 108 | this._avail[layer.type].push(layer); |
| 109 | } |
| 110 | catch (e) { |
| 111 | continue; |
| 112 | }; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 113 | }; |
Akron | 3a4a08e | 2017-05-23 22:34:18 +0200 | [diff] [blame] | 114 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 115 | return this; |
| 116 | }, |
| 117 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 118 | /** |
| 119 | * Return a list of parseable tree annotations. |
| 120 | */ |
| 121 | getSpans : function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 122 | return this._avail.spans; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 123 | }, |
| 124 | |
| 125 | |
| 126 | /** |
| 127 | * Return a list of parseable token annotations. |
| 128 | */ |
| 129 | getTokens : function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 130 | return this._avail.tokens; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 131 | }, |
| 132 | |
| 133 | |
| 134 | /** |
| 135 | * Return a list of parseable relation annotations. |
| 136 | */ |
| 137 | getRels : function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 138 | return this._avail.rels; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 139 | }, |
| 140 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 141 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 142 | /** |
| 143 | * Open match |
| 144 | */ |
| 145 | open : function () { |
| 146 | |
| 147 | // Add actions unless it's already activated |
| 148 | var element = this._element; |
| 149 | |
| 150 | // There is an element to open |
| 151 | if (this._element === undefined || this._element === null) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 152 | return false; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 153 | |
| 154 | // The element is already opened |
| 155 | if (element.classList.contains('active')) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 156 | return false; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 157 | |
| 158 | // Add active class to element |
| 159 | element.classList.add('active'); |
| 160 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 161 | // Already there |
| 162 | if (element.classList.contains('action')) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 163 | return true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 164 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 165 | // Create action buttons |
| 166 | var ul = document.createElement('ul'); |
| 167 | ul.classList.add('action', 'right'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 168 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 169 | element.appendChild(ul); |
| 170 | element.classList.add('action'); |
| 171 | |
| 172 | // Todo: Open in new frame |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 173 | |
| 174 | // Add close button |
| 175 | var close = document.createElement('li'); |
| 176 | close.appendChild(document.createElement('span')) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 177 | .appendChild(document.createTextNode(loc.CLOSE)); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 178 | close.classList.add('close'); |
| 179 | close.setAttribute('title', loc.CLOSE); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 180 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 181 | // Add info button |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 182 | /* |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 183 | var info = document.createElement('li'); |
| 184 | info.appendChild(document.createElement('span')) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 185 | .appendChild(document.createTextNode(loc.SHOWINFO)); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 186 | info.classList.add('info'); |
| 187 | info.setAttribute('title', loc.SHOWINFO); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 188 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 189 | |
| 190 | var that = this; |
| 191 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 192 | // Add meta button |
| 193 | var refLine = element.querySelector("p.ref"); |
| 194 | |
| 195 | // There is a reference line |
Akron | 0490535 | 2018-01-24 02:06:32 +0100 | [diff] [blame] | 196 | if (refLine) { |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 197 | |
| 198 | // Temporary |
| 199 | var ops = document.createElement('div'); |
Akron | d4b000b | 2018-01-28 18:33:14 +0100 | [diff] [blame^] | 200 | ops.classList.add('action', 'bottom', 'button-group'); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 201 | |
| 202 | var meta = document.createElement('span'); |
| 203 | ops.appendChild(meta); |
| 204 | meta.appendChild(document.createTextNode('+ Meta')); |
| 205 | meta.setAttribute('title', loc.SHOW_META); |
| 206 | meta.classList.add('meta'); |
| 207 | |
| 208 | var info = document.createElement('span'); |
| 209 | ops.appendChild(info); |
| 210 | info.appendChild(document.createTextNode('+ Anno')); |
| 211 | info.setAttribute('title', loc.SHOWINFO); |
| 212 | info.classList.add('info'); |
| 213 | |
| 214 | var tree = document.createElement('span'); |
| 215 | ops.appendChild(tree); |
| 216 | tree.appendChild(document.createTextNode('+ Tree')); |
| 217 | tree.setAttribute('title', loc.ADDTREE); |
| 218 | tree.classList.add('tree'); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 219 | |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 220 | refLine.insertBefore( |
| 221 | ops, |
| 222 | refLine.firstChild |
| 223 | ); |
| 224 | |
| 225 | /* |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 226 | var meta = document.createElement('span'); |
| 227 | meta.appendChild( |
Akron | 0490535 | 2018-01-24 02:06:32 +0100 | [diff] [blame] | 228 | document.createElement('span') |
| 229 | ).appendChild( |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 230 | document.createTextNode(loc.SHOW_META) |
| 231 | ); |
| 232 | meta.setAttribute('title', loc.SHOW_META); |
| 233 | meta.classList.add('meta'); |
| 234 | refLine.insertBefore( |
| 235 | meta, |
| 236 | refLine.firstChild |
| 237 | ); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 238 | */ |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 239 | |
| 240 | meta.addEventListener( |
| 241 | 'click', function (e) { |
| 242 | e.halt(); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 243 | that.info().addMeta(); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 244 | } |
| 245 | ); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 246 | |
| 247 | // Add information, unless it already exists |
| 248 | info.addEventListener( |
| 249 | 'click', function (e) { |
| 250 | e.halt(); |
| 251 | that.info().addTable(); |
| 252 | } |
| 253 | ); |
| 254 | |
| 255 | tree.addEventListener( |
| 256 | 'click', function (e) { |
| 257 | e.halt(); |
| 258 | |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 259 | if (KorAP.TreeMenu === undefined) { |
| 260 | KorAP.TreeMenu = matchTreeMenuClass.create([]); |
| 261 | }; |
| 262 | |
| 263 | var tm = KorAP.TreeMenu; |
| 264 | |
| 265 | // Reread list |
| 266 | tm.info(that.info()); |
| 267 | tm.readItems(that.treeMenuList()); |
| 268 | tm.attachTo(this); |
| 269 | |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 270 | // Not yet initialized |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 271 | /* |
| 272 | if (that._treemenu === undefined) { |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 273 | that._treemenu = that.initTreeMenu(); |
| 274 | |
| 275 | // TODO: |
| 276 | // Do not add the tree menu to the button! |
| 277 | // Only reposition a global treemenu element there, |
| 278 | // that is positioned below the annotation helper! |
| 279 | this.appendChild(that._treemenu.element()); |
| 280 | }; |
| 281 | var tm = that._treemenu; |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 282 | */ |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 283 | tm.show(); |
| 284 | tm.focus(); |
| 285 | } |
| 286 | ); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 287 | }; |
| 288 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 289 | // Close match |
| 290 | close.addEventListener('click', function (e) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 291 | e.halt(); |
| 292 | that.close() |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 293 | }); |
| 294 | |
| 295 | // Add information, unless it already exists |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 296 | /* |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 297 | info.addEventListener('click', function (e) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 298 | e.halt(); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 299 | that.info().addTable(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 300 | }); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 301 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 302 | |
| 303 | ul.appendChild(close); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 304 | // ul.appendChild(info); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 305 | |
| 306 | return true; |
| 307 | }, |
| 308 | |
Akron | 8c468a1 | 2016-11-13 23:57:41 +0100 | [diff] [blame] | 309 | |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 310 | // Todo: Test toggle |
| 311 | toggle : function () { |
| 312 | if (this._element.classList.contains('active')) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 313 | this.close(); |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 314 | else |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 315 | this.open(); |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 316 | }, |
| 317 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 318 | |
Nils Diewald | 8bc7e41 | 2015-03-19 22:08:27 +0000 | [diff] [blame] | 319 | /** |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 320 | * Close info view |
| 321 | */ |
| 322 | close : function () { |
| 323 | this._element.classList.remove('active'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 324 | /* if (this._info !== undefined) { |
| 325 | * this._info.destroy(); |
| 326 | * }; |
| 327 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 328 | }, |
| 329 | |
| 330 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 331 | /** |
| 332 | * Get and open associated match info. |
| 333 | */ |
| 334 | info : function () { |
| 335 | |
| 336 | // Create match info |
| 337 | if (this._info === undefined) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 338 | this._info = infoClass.create(this); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 339 | |
| 340 | // There is an element to append |
| 341 | if (this._element === undefined || |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 342 | this._element === null) |
| 343 | return this._info; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 344 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 345 | // Info is already activated |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 346 | if (this._info._element !== undefined) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 347 | return this._info; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 348 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 349 | /* |
| 350 | this.element().appendChild( |
| 351 | this._info.element() |
| 352 | ); |
| 353 | */ |
| 354 | var refLine = this._element.querySelector("p.ref"); |
| 355 | this._element.insertBefore( |
| 356 | this._info.element(), |
| 357 | refLine |
| 358 | ); |
| 359 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 360 | return this._info; |
| 361 | }, |
| 362 | |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 363 | |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 364 | treeMenuList : function () { |
| 365 | |
| 366 | if (this._menuList) |
| 367 | return this._menuList; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 368 | |
| 369 | // Join spans and relations |
| 370 | var treeLayers = [] |
| 371 | var spans = this.getSpans(); |
| 372 | var rels = this.getRels(); |
| 373 | var i; |
| 374 | for (i in spans) { |
| 375 | treeLayers.push(spans[i]); |
| 376 | }; |
| 377 | for (i in rels) { |
| 378 | treeLayers.push(rels[i]); |
| 379 | }; |
| 380 | |
| 381 | // Get spans |
| 382 | treeLayers = treeLayers.sort( |
| 383 | function (a, b) { |
| 384 | if (a.foundry < b.foundry) { |
| 385 | return -1; |
| 386 | } |
| 387 | else if (a.foundry > b.foundry) { |
| 388 | return 1; |
| 389 | } |
| 390 | else if (a.layer < b.layer) { |
| 391 | return -1; |
| 392 | } |
| 393 | else if (a.layer > b.layer) { |
| 394 | return 1; |
| 395 | }; |
| 396 | return 0; |
| 397 | }); |
| 398 | |
| 399 | var menuList = []; |
| 400 | |
| 401 | // Show tree views |
| 402 | for (var i = 0; i < treeLayers.length; i++) { |
| 403 | var span = treeLayers[i]; |
| 404 | |
| 405 | // Add foundry/layer to menu list |
| 406 | menuList.push([ |
| 407 | span.foundry + '/' + span.layer, |
| 408 | span.foundry, |
| 409 | span.layer, |
| 410 | span.type |
| 411 | ]); |
| 412 | }; |
| 413 | |
| 414 | // Create tree menu |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 415 | this._menuList = menuList; |
| 416 | return menuList; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 417 | /* |
| 418 | var span = document.createElement('p'); |
| 419 | span.classList.add('addtree'); |
| 420 | span.appendChild(document.createTextNode(loc.ADDTREE)); |
| 421 | var treeElement = treemenu.element(); |
| 422 | span.appendChild(treeElement); |
| 423 | |
| 424 | span.addEventListener('click', function (e) { |
| 425 | treemenu.show(); |
| 426 | treemenu.focus(); |
| 427 | }); |
| 428 | */ |
| 429 | }, |
| 430 | |
| 431 | |
| 432 | /** |
| 433 | * Get tree menu. |
| 434 | * There is only one menu rendered |
| 435 | * - no matter how many trees exist |
| 436 | */ |
| 437 | /* |
| 438 | treeMenu : function (list) { |
| 439 | if (this._treeMenu !== undefined) |
| 440 | return this._treeMenu; |
| 441 | |
| 442 | return this._treeMenu = matchTreeMenuClass.create(this, list); |
| 443 | }, |
| 444 | */ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 445 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 446 | /** |
| 447 | * Get match element. |
| 448 | */ |
| 449 | element : function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 450 | return this._element; // May be null |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 451 | } |
| 452 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 453 | }); |