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