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 |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 19 | const 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' |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 26 | const _matchTerms = ['textSigle', 'matchID', 'available']; |
| 27 | |
| 28 | const d = document; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Match object |
| 32 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 33 | return { |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Create a new annotation object. |
| 37 | * Expects an array of available foundry/layer=type terms. |
| 38 | * Supported types are 'spans', 'tokens' and 'rels'. |
| 39 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 40 | create : function (match) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 41 | return Object.create(this)._init(match); |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 42 | }, |
| 43 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 44 | |
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 | * Initialize match. |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 47 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 48 | _init : function (match) { |
| 49 | this._element = null; |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 50 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 51 | // No match defined |
| 52 | if (arguments.length < 1 || |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 53 | match === null || |
| 54 | match === undefined) { |
| 55 | throw new Error('Missing parameters'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 56 | } |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 57 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 58 | // Match defined as a node |
| 59 | else if (match instanceof Node) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 60 | this._element = match; |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 61 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 62 | // Circular reference !! |
| 63 | match["_match"] = this; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 64 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 65 | /* |
| 66 | this.corpusID = match.getAttribute('data-corpus-id'), |
| 67 | this.docID = match.getAttribute('data-doc-id'), |
| 68 | this.textID = match.getAttribute('data-text-id'), |
| 69 | */ |
| 70 | if (match.hasAttribute('data-text-sigle')) { |
| 71 | this.textSigle = match.getAttribute('data-text-sigle') |
| 72 | } |
| 73 | else { |
| 74 | this.textSigle = match.getAttribute('data-corpus-id') + |
| 75 | '/' + |
| 76 | match.getAttribute('data-doc-id') + |
| 77 | '/' + |
| 78 | match.getAttribute('data-text-id'); |
| 79 | }; |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 80 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 81 | this.matchID = match.getAttribute('data-match-id'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 82 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 83 | // List of available annotations |
| 84 | this.available = match.getAttribute('data-available-info').split(' '); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | // Match as an object |
| 88 | else { |
| 89 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 90 | // Iterate over allowed match terms |
| 91 | for (var i in _matchTerms) { |
| 92 | var term = _matchTerms[i]; |
| 93 | this[term] = match[term] !== undefined ? match[term] : undefined; |
| 94 | }; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 95 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 96 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 97 | this._avail = { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 98 | tokens : [], |
| 99 | spans : [], |
| 100 | rels : [] |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 101 | }; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 102 | |
| 103 | // Iterate over info layers |
| 104 | for (var i = 0; i < this.available.length; i++) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 105 | var term = this.available[i]; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 106 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 107 | // Create info layer objects |
| 108 | try { |
| 109 | var layer = require('match/infolayer').create(term); |
| 110 | this._avail[layer.type].push(layer); |
| 111 | } |
| 112 | catch (e) { |
| 113 | continue; |
| 114 | }; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 115 | }; |
Akron | 3a4a08e | 2017-05-23 22:34:18 +0200 | [diff] [blame] | 116 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 117 | return this; |
| 118 | }, |
| 119 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 120 | /** |
| 121 | * Return a list of parseable tree annotations. |
| 122 | */ |
| 123 | getSpans : function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 124 | return this._avail.spans; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 125 | }, |
| 126 | |
| 127 | |
| 128 | /** |
| 129 | * Return a list of parseable token annotations. |
| 130 | */ |
| 131 | getTokens : function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 132 | return this._avail.tokens; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 133 | }, |
| 134 | |
| 135 | |
| 136 | /** |
| 137 | * Return a list of parseable relation annotations. |
| 138 | */ |
| 139 | getRels : function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 140 | return this._avail.rels; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 141 | }, |
| 142 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 143 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 144 | /** |
| 145 | * Open match |
| 146 | */ |
| 147 | open : function () { |
| 148 | |
| 149 | // Add actions unless it's already activated |
| 150 | var element = this._element; |
| 151 | |
| 152 | // There is an element to open |
| 153 | if (this._element === undefined || this._element === null) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 154 | return false; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 155 | |
| 156 | // The element is already opened |
| 157 | if (element.classList.contains('active')) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 158 | return false; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 159 | |
| 160 | // Add active class to element |
| 161 | element.classList.add('active'); |
| 162 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 163 | // Already there |
| 164 | if (element.classList.contains('action')) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 165 | return true; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 166 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 167 | // Create action buttons |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 168 | var ul = d.createElement('ul'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 169 | ul.classList.add('action', 'right'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 170 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 171 | element.appendChild(ul); |
| 172 | element.classList.add('action'); |
| 173 | |
| 174 | // Todo: Open in new frame |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 175 | |
| 176 | // Add close button |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 177 | var close = d.createElement('li'); |
| 178 | close.addE('span').addT(loc.CLOSE); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 179 | close.classList.add('close'); |
| 180 | close.setAttribute('title', loc.CLOSE); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 181 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 182 | var that = this; |
| 183 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 184 | // Add meta button |
| 185 | var refLine = element.querySelector("p.ref"); |
| 186 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 187 | // No reference found |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 188 | if (!refLine) |
| 189 | return; |
| 190 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 191 | var ops = d.createElement('div'); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 192 | ops.classList.add('action', 'bottom', 'button-group'); |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 193 | |
| 194 | /* |
| 195 | Temporarily disabled |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 196 | var meta = ops.addE('span'); |
| 197 | meta.addT('Meta'); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 198 | meta.setAttribute('title', loc.SHOW_META); |
| 199 | meta.classList.add('meta'); |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 200 | */ |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 201 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 202 | // TODO: Rename anno |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 203 | var info = ops.addE('span'); |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 204 | info.addT(loc.SHOWINFO); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 205 | info.setAttribute('title', loc.SHOWINFO); |
| 206 | info.classList.add('info'); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 207 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 208 | var tree = ops.addE('span'); |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 209 | tree.addT(loc.ADDTREE); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 210 | tree.setAttribute('title', loc.ADDTREE); |
| 211 | tree.classList.add('tree'); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 212 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 213 | // Insert before reference line |
| 214 | refLine.insertBefore( |
| 215 | ops, |
| 216 | refLine.firstChild |
| 217 | ); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 218 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 219 | // Click on meta - add meta (unless already there) |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 220 | /* |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 221 | meta.addEventListener( |
| 222 | 'click', function (e) { |
| 223 | e.halt(); |
| 224 | that.info().showMeta(); |
| 225 | } |
| 226 | ); |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 227 | */ |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 228 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 229 | // Click on token annotations - add token annotations (unless already there) |
| 230 | info.addEventListener( |
| 231 | 'click', function (e) { |
| 232 | e.halt(); |
| 233 | that.info().showTable(); |
| 234 | } |
| 235 | ); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 236 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 237 | // Click to show tree menu |
| 238 | tree.addEventListener( |
| 239 | 'click', function (e) { |
| 240 | e.halt(); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 241 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 242 | if (KorAP.TreeMenu === undefined) { |
| 243 | KorAP.TreeMenu = matchTreeMenuClass.create([]); |
| 244 | }; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 245 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 246 | var tm = KorAP.TreeMenu; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 247 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 248 | // Reread list |
| 249 | tm.info(that.info()); |
| 250 | tm.readItems(that.treeMenuList()); |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 251 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 252 | // Reposition and show menu |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 253 | tm.show(); |
Akron | c6967d7 | 2018-02-05 18:39:39 +0100 | [diff] [blame] | 254 | tm.attachTo(this); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 255 | tm.focus(); |
| 256 | } |
| 257 | ); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 258 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 259 | // Close match |
| 260 | close.addEventListener('click', function (e) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 261 | e.halt(); |
| 262 | that.close() |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 263 | }); |
| 264 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 265 | ul.appendChild(close); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 266 | |
| 267 | return true; |
| 268 | }, |
| 269 | |
Akron | 8c468a1 | 2016-11-13 23:57:41 +0100 | [diff] [blame] | 270 | |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 271 | // Todo: Test toggle |
| 272 | toggle : function () { |
| 273 | if (this._element.classList.contains('active')) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 274 | this.close(); |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 275 | else |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 276 | this.open(); |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 277 | }, |
| 278 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 279 | |
Nils Diewald | 8bc7e41 | 2015-03-19 22:08:27 +0000 | [diff] [blame] | 280 | /** |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 281 | * Close info view |
| 282 | */ |
| 283 | close : function () { |
| 284 | this._element.classList.remove('active'); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 285 | /* |
| 286 | if (this._info !== undefined) { |
| 287 | this._info.destroy(); |
| 288 | }; |
| 289 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 290 | }, |
| 291 | |
| 292 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 293 | /** |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 294 | * Get and open associated match infos. |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 295 | */ |
| 296 | info : function () { |
| 297 | |
| 298 | // Create match info |
| 299 | if (this._info === undefined) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 300 | this._info = infoClass.create(this); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 301 | |
| 302 | // There is an element to append |
| 303 | if (this._element === undefined || |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 304 | this._element === null) |
| 305 | return this._info; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 306 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 307 | // Info is already activated |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 308 | if (this._info._element !== undefined) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 309 | return this._info; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 310 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 311 | var refLine = this._element.querySelector("p.ref"); |
| 312 | this._element.insertBefore( |
| 313 | this._info.element(), |
| 314 | refLine |
| 315 | ); |
| 316 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 317 | return this._info; |
| 318 | }, |
| 319 | |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 320 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 321 | // Return tree menu list |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 322 | treeMenuList : function () { |
| 323 | |
| 324 | if (this._menuList) |
| 325 | return this._menuList; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 326 | |
| 327 | // Join spans and relations |
| 328 | var treeLayers = [] |
| 329 | var spans = this.getSpans(); |
| 330 | var rels = this.getRels(); |
| 331 | var i; |
| 332 | for (i in spans) { |
| 333 | treeLayers.push(spans[i]); |
| 334 | }; |
| 335 | for (i in rels) { |
| 336 | treeLayers.push(rels[i]); |
| 337 | }; |
| 338 | |
| 339 | // Get spans |
| 340 | treeLayers = treeLayers.sort( |
| 341 | function (a, b) { |
| 342 | if (a.foundry < b.foundry) { |
| 343 | return -1; |
| 344 | } |
| 345 | else if (a.foundry > b.foundry) { |
| 346 | return 1; |
| 347 | } |
| 348 | else if (a.layer < b.layer) { |
| 349 | return -1; |
| 350 | } |
| 351 | else if (a.layer > b.layer) { |
| 352 | return 1; |
| 353 | }; |
| 354 | return 0; |
| 355 | }); |
| 356 | |
| 357 | var menuList = []; |
| 358 | |
| 359 | // Show tree views |
| 360 | for (var i = 0; i < treeLayers.length; i++) { |
| 361 | var span = treeLayers[i]; |
| 362 | |
| 363 | // Add foundry/layer to menu list |
| 364 | menuList.push([ |
| 365 | span.foundry + '/' + span.layer, |
| 366 | span.foundry, |
| 367 | span.layer, |
| 368 | span.type |
| 369 | ]); |
| 370 | }; |
| 371 | |
| 372 | // Create tree menu |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 373 | this._menuList = menuList; |
| 374 | return menuList; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 375 | }, |
| 376 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 377 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 378 | /** |
| 379 | * Get match element. |
| 380 | */ |
| 381 | element : function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 382 | return this._element; // May be null |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 383 | } |
| 384 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 385 | }); |