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