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