Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Create virtual collections with a visual user interface. |
Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 3 | * This resembles the collection type objects of a KoralQuery |
| 4 | * "collection" object. |
| 5 | * |
| 6 | * KoralQuery v0.3 is expected. |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 7 | * |
| 8 | * @author Nils Diewald |
| 9 | */ |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 10 | /* |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 11 | * This replaces a previous version written by Mengfei Zhou |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 12 | */ |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 13 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 14 | /* |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 15 | TODO: Disable "and" or "or" in case it's followed |
| 16 | by an unspecified document |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 17 | TODO: Add "and"-method to root to add further constraints based on match- |
| 18 | input (like clicking on a pubDate timestamp in a match) |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 19 | TODO: Implement "persistence"-Option, |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 20 | injecting the current creation date stamp |
Nils Diewald | 709f52f | 2015-05-21 18:32:58 +0000 | [diff] [blame] | 21 | TODO: Implement vec-Type for document-id vectors |
| 22 | like docID in [1,2,3,4 ...] |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 23 | |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 24 | Error codes: |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 25 | 701: "JSON-LD group has no @type attribute" |
| 26 | 704: "Operation needs operand list" |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 27 | 802: "Match type is not supported by value type" |
| 28 | 804: "Unknown value type" |
| 29 | 805: "Value is invalid" |
| 30 | 806: "Value is not a valid date string" |
| 31 | 807: "Value is not a valid regular expression" |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 32 | 810: "Unknown document group operation" (like 711) |
| 33 | 811: "Document group expects operation" (like 703) |
| 34 | 812: "Operand not supported in document group" (like 744) |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 35 | 813: "Collection type is not supported" (like 713) |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 36 | 814: "Unknown rewrite operation" |
| 37 | 815: "Rewrite expects source" |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 38 | |
| 39 | Localization strings: |
| 40 | KorAP.Locale = { |
| 41 | EMPTY : '...', |
| 42 | AND : 'and', |
| 43 | OR : 'or', |
| 44 | DELETE : 'x' |
| 45 | } |
Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 46 | and various field names with the prefix 'VC_' |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 47 | */ |
| 48 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 49 | define([ |
| 50 | 'vc/unspecified', |
| 51 | 'vc/doc', |
| 52 | 'vc/docgroup', |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 53 | 'vc/menu', |
hebasta | 1c3ce0f | 2018-06-05 17:02:16 +0200 | [diff] [blame] | 54 | 'vc/statistic', |
Nils Diewald | 8750783 | 2015-05-01 23:36:41 +0000 | [diff] [blame] | 55 | 'datepicker', |
hebasta | 1c3ce0f | 2018-06-05 17:02:16 +0200 | [diff] [blame] | 56 | 'util', |
| 57 | ], function (unspecDocClass, docClass, docGroupClass, menuClass, statClass, dpClass) { |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 58 | "use strict"; |
| 59 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 60 | KorAP._validUnspecMatchRE = new RegExp("^(?:eq|ne|contains(?:not)?|excludes)$"); |
| 61 | KorAP._validStringMatchRE = new RegExp("^(?:eq|ne)$"); |
| 62 | KorAP._validTextMatchRE = KorAP._validUnspecMatchRE; |
| 63 | KorAP._validTextOnlyMatchRE = new RegExp("^(?:contains(?:not)?|excludes)$"); |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 64 | KorAP._overrideStyles = false; |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 65 | // KorAP._validDateMatchRE is defined in datepicker.js! |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 66 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 67 | const loc = KorAP.Locale; |
hebasta | c8fa078 | 2018-06-20 16:00:57 +0200 | [diff] [blame^] | 68 | loc.VC_SHOWSTAT = loc.VC_SHOWSTAT || 'Corpus Statistic'; |
| 69 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 70 | KorAP._vcKeyMenu = undefined; |
Nils Diewald | 8750783 | 2015-05-01 23:36:41 +0000 | [diff] [blame] | 71 | KorAP._vcDatePicker = dpClass.create(); |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 72 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 73 | // Create match menus .... |
| 74 | KorAP._vcMatchopMenu = { |
| 75 | 'string' : menuClass.create([ |
| 76 | ['eq', null], |
| 77 | ['ne', null] |
| 78 | ]), |
| 79 | 'text' : menuClass.create([ |
| 80 | ['eq', null], // Requires exact match |
| 81 | ['ne', null], |
| 82 | ['contains', null], // Requires token sequence match |
| 83 | ['containsnot', null] |
| 84 | ]), |
| 85 | 'date' : menuClass.create([ |
| 86 | ['eq', null], |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 87 | ['ne', null], |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 88 | ['geq', null], |
| 89 | ['leq', null] |
| 90 | ]), |
| 91 | 'regex' : menuClass.create([ |
| 92 | ['eq', null], |
| 93 | ['ne', null] |
| 94 | ]) |
| 95 | }; |
| 96 | |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 97 | /** |
| 98 | * Virtual Collection |
| 99 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 100 | return { |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * The JSON-LD type of the virtual collection |
| 104 | */ |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 105 | ldType : function () { |
| 106 | return null; |
| 107 | }, |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 108 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 109 | // Initialize virtual collection |
| 110 | _init : function (keyList) { |
| 111 | |
| 112 | // Inject localized css styles |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 113 | if (!KorAP._overrideStyles) { |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 114 | var sheet = KorAP.newStyleSheet(); |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 115 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 116 | // Add css rule for OR operations |
| 117 | sheet.insertRule( |
| 118 | '.vc .docGroup[data-operation=or] > .doc::before,' + |
| 119 | '.vc .docGroup[data-operation=or] > .docGroup::before ' + |
| 120 | '{ content: "' + loc.OR + '" }', |
| 121 | 0 |
| 122 | ); |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 123 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 124 | // Add css rule for AND operations |
| 125 | sheet.insertRule( |
| 126 | '.vc .docGroup[data-operation=and] > .doc::before,' + |
| 127 | '.vc .docGroup[data-operation=and] > .docGroup::before ' + |
| 128 | '{ content: "' + loc.AND + '" }', |
| 129 | 1 |
| 130 | ); |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 131 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 132 | KorAP._overrideStyles = true; |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 135 | // Create key menu |
| 136 | KorAP._vcKeyMenu = menuClass.create(keyList); |
| 137 | KorAP._vcKeyMenu.limit(6); |
| 138 | |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 139 | return this; |
| 140 | }, |
| 141 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 142 | /** |
| 143 | * Create a new virtual collection. |
| 144 | */ |
| 145 | create : function (keyList) { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 146 | var obj = Object.create(this)._init(keyList); |
| 147 | obj._root = unspecDocClass.create(obj); |
| 148 | return obj; |
Nils Diewald | 4019bd2 | 2015-01-08 19:57:50 +0000 | [diff] [blame] | 149 | }, |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 150 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 151 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 152 | /** |
| 153 | * Create and render a new virtual collection |
| 154 | * based on a KoralQuery collection document |
| 155 | */ |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 156 | fromJson : function (json) { |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 157 | if (json !== undefined) { |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 158 | // Parse root document |
| 159 | if (json['@type'] == 'koral:doc') { |
| 160 | this._root = docClass.create(this, json); |
| 161 | } |
| 162 | // parse root group |
| 163 | else if (json['@type'] == 'koral:docGroup') { |
| 164 | this._root = docGroupClass.create(this, json); |
| 165 | } |
| 166 | // Unknown collection type |
| 167 | else { |
| 168 | KorAP.log(813, "Collection type is not supported"); |
| 169 | return; |
| 170 | }; |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | else { |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 174 | // Add unspecified object |
| 175 | this._root = unspecDocClass.create(this); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
Nils Diewald | 8e7182e | 2015-01-08 15:02:07 +0000 | [diff] [blame] | 178 | // Init element and update |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 179 | this.update(); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 180 | |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 181 | return this; |
| 182 | }, |
| 183 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 184 | |
Akron | 04671e7 | 2017-05-11 20:47:32 +0200 | [diff] [blame] | 185 | // Check if the virtual corpus contains a rewrite |
| 186 | // This is a class method |
| 187 | checkRewrite : function (json) { |
| 188 | |
| 189 | // There is a rewrite attribute |
| 190 | if (json['rewrites'] !== undefined) { |
| 191 | return true; |
| 192 | } |
| 193 | |
| 194 | // There is a group to check for rewrites |
| 195 | else if (json['@type'] === 'koral:docGroup') { |
| 196 | var ops = json['operands']; |
| 197 | if (ops === undefined) |
| 198 | return false; |
| 199 | |
| 200 | for (var i in ops) { |
| 201 | |
| 202 | // "this" is the class |
| 203 | if (this.checkRewrite(ops[i])) { |
| 204 | return true; |
| 205 | }; |
| 206 | }; |
| 207 | }; |
| 208 | return false; |
| 209 | }, |
| 210 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 211 | /** |
| 212 | * Clean the virtual document to uspecified doc. |
| 213 | */ |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 214 | clean : function () { |
| 215 | if (this._root.ldType() !== "non") { |
Akron | 04671e7 | 2017-05-11 20:47:32 +0200 | [diff] [blame] | 216 | this._root.destroy(); |
| 217 | this.root(unspecDocClass.create(this)); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 218 | }; |
| 219 | return this; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 220 | }, |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 221 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 222 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 223 | /** |
| 224 | * Get or set the root object of the |
| 225 | * virtual collection. |
| 226 | */ |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 227 | root : function (obj) { |
Nils Diewald | 8e7182e | 2015-01-08 15:02:07 +0000 | [diff] [blame] | 228 | if (arguments.length === 1) { |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 229 | var e = this.element(); |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 230 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 231 | if (e.firstChild !== null) { |
| 232 | if (e.firstChild !== obj.element()) { |
| 233 | e.replaceChild(obj.element(), e.firstChild); |
| 234 | }; |
| 235 | } |
Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 236 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 237 | // Append root element |
| 238 | else { |
| 239 | e.appendChild(obj.element()); |
| 240 | }; |
Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 241 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 242 | // Update parent child relations |
| 243 | this._root = obj; |
| 244 | obj.parent(this); |
Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 245 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 246 | this.update(); |
Nils Diewald | 8e7182e | 2015-01-08 15:02:07 +0000 | [diff] [blame] | 247 | }; |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 248 | return this._root; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 249 | }, |
Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 250 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 251 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 252 | /** |
| 253 | * Get the element associated with the virtual collection |
| 254 | */ |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 255 | element : function () { |
Akron | 12971a0 | 2018-01-03 16:38:10 +0100 | [diff] [blame] | 256 | if (this._element !== undefined) { |
| 257 | return this._element; |
| 258 | }; |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 259 | |
| 260 | this._element = document.createElement('div'); |
| 261 | this._element.setAttribute('class', 'vc'); |
Nils Diewald | 8e7182e | 2015-01-08 15:02:07 +0000 | [diff] [blame] | 262 | |
Nils Diewald | 8f6b610 | 2015-01-08 18:25:33 +0000 | [diff] [blame] | 263 | // Initialize root |
| 264 | this._element.appendChild(this._root.element()); |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 265 | |
hebasta | c8fa078 | 2018-06-20 16:00:57 +0200 | [diff] [blame^] | 266 | //Add corpus statistic button |
| 267 | if(!(this._root.element().classList.contains('unspecified'))){ |
| 268 | this.addStatBut(); |
| 269 | } |
| 270 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 271 | return this._element; |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 272 | }, |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 273 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 274 | |
| 275 | /** |
| 276 | * Update the whole object based on the underlying |
| 277 | * data structure |
| 278 | */ |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 279 | update : function () { |
| 280 | this._root.update(); |
| 281 | return this; |
| 282 | }, |
| 283 | |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 284 | /** |
| 285 | * Make the vc persistant by injecting the current timestamp |
| 286 | * as a creation date limit criterion. |
| 287 | */ |
| 288 | makePersistant : function () { |
Akron | 12971a0 | 2018-01-03 16:38:10 +0100 | [diff] [blame] | 289 | // this.root().wrapOnRoot('and'); |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 290 | var todayStr = KorAP._vcDatePicker.today(); |
| 291 | var doc = docClass.create(); |
| 292 | var root = this.root(); |
| 293 | |
| 294 | if (root.ldType() === 'docGroup' && |
Akron | 12971a0 | 2018-01-03 16:38:10 +0100 | [diff] [blame] | 295 | root.operation === 'and') { |
| 296 | root.append(cond); |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 297 | } |
| 298 | else { |
Akron | 12971a0 | 2018-01-03 16:38:10 +0100 | [diff] [blame] | 299 | root.wrapOnRoot('and'); |
| 300 | root.append(doc); |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | doc.key("creationDate"); |
| 304 | doc.type("date"); |
| 305 | doc.matchop("leq"); |
| 306 | doc.value(todayStr); |
| 307 | |
| 308 | /* |
| 309 | { |
| 310 | "@type" : "koral:doc", |
| 311 | "key" : "creationDate", |
| 312 | "type" : "type:date", |
| 313 | "match" : "match:leq", |
| 314 | "value" : todayStr |
| 315 | } |
| 316 | this.root().append(cond); |
| 317 | */ |
| 318 | this.update(); |
| 319 | }, |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 320 | |
| 321 | /** |
| 322 | * Get the generated json string |
| 323 | */ |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 324 | toJson : function () { |
| 325 | return this._root.toJson(); |
| 326 | }, |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 327 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 328 | |
| 329 | /** |
| 330 | * Get the generated query string |
| 331 | */ |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 332 | toQuery : function () { |
| 333 | return this._root.toQuery(); |
hebasta | 1c3ce0f | 2018-06-05 17:02:16 +0200 | [diff] [blame] | 334 | }, |
| 335 | |
hebasta | c8fa078 | 2018-06-20 16:00:57 +0200 | [diff] [blame^] | 336 | |
| 337 | /** |
| 338 | * Adds Corpus Statistic Button |
| 339 | **/ |
| 340 | addStatBut : function(){ |
hebasta | 1c3ce0f | 2018-06-05 17:02:16 +0200 | [diff] [blame] | 341 | |
hebasta | c8fa078 | 2018-06-20 16:00:57 +0200 | [diff] [blame^] | 342 | //add div element 'corpStat' with id 'dCorpStat' |
| 343 | var dv = this._element.addE('div'); |
| 344 | dv.id = "dCorpStat"; |
| 345 | |
| 346 | //add button |
| 347 | var bu = dv.addE('div'); |
| 348 | bu.classList.add('bottom', 'button-single'); |
| 349 | var stat = bu.addE('span'); |
| 350 | stat.addT('Statistics'); |
| 351 | //localize the buttons title attribute |
| 352 | stat.setAttribute('title', loc.VC_SHOWSTAT); |
| 353 | stat.classList.add('statistic'); |
| 354 | |
| 355 | /* |
| 356 | * In ECMAScript Language Specification this is set incorrectly for inner functions, |
| 357 | * therefore thatelement and that is defined. |
| 358 | */ |
| 359 | var thatelement = this._element; |
| 360 | var that = this; |
| 361 | |
| 362 | //show corpus statistic if button is clicked |
| 363 | stat.addEventListener('click', function(e){ |
| 364 | e.halt(); |
| 365 | statClass.showCorpStat(thatelement, that); |
| 366 | }); |
| 367 | |
| 368 | } |
| 369 | |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 370 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 371 | }); |