Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 1 | /** |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 2 | * Hint menu for Kalamar. |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 3 | * Based on menu object. |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 4 | * |
| 5 | * @author Nils Diewald |
| 6 | */ |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 7 | /* |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 8 | * TODO: Check for cnx/syn= |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 9 | * TODO: List can be shown when prefix is like 'base/s=pcorenlp/' |
| 10 | * TODO: Sometimes the drop-down box down vanish when list is shown |
| 11 | * TODO: Create should expect an input text field |
| 12 | * TODO: Embed only one single menu (not multiple) |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 13 | * By holding the current menu in _active |
| 14 | * TODO: show() should accept a context field (especially for no-context fields, |
| 15 | * like fragments) |
| 16 | * TODO: Improve context analyzer from hint! |
| 17 | * TODO: Marked annotations should be addable to "fragments" |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 18 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 19 | define([ |
| 20 | 'hint/input', |
| 21 | 'hint/menu', |
| 22 | 'hint/contextanalyzer', |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 23 | 'hint/alert', |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 24 | 'util' |
| 25 | ], function (inputClass, |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 26 | menuClass, |
| 27 | analyzerClass, |
| 28 | alertClass) { |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 29 | "use strict"; |
| 30 | |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 31 | /** |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 32 | * Return keycode based on event |
| 33 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 34 | |
| 35 | // Initialize hint array |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * KorAP.Hint.create({ |
| 39 | * inputField : node, |
| 40 | * context : context regex |
| 41 | * }); |
| 42 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 43 | return { |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 44 | |
| 45 | // Some variables |
| 46 | // _firstTry : true, |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 47 | // active : false, |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 48 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 49 | /** |
| 50 | * Create new hint helper. |
| 51 | */ |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 52 | create : function (param) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 53 | return Object.create(this)._init(param); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 54 | }, |
| 55 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 56 | // Initialize hint helper |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 57 | _init : function (param) { |
| 58 | param = param || {}; |
| 59 | |
| 60 | // Holds all menus per prefix context |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 61 | this._menu = {}; |
| 62 | this._alert = alertClass.create(); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 63 | this._active = null; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 64 | |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 65 | // No annotation helper available |
| 66 | if (!KorAP.annotationHelper) { |
| 67 | console.log("No annotationhelper defined"); |
| 68 | return; |
| 69 | }; |
Akron | fac1647 | 2018-07-26 16:47:21 +0200 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * @define {regex} Regular expression for context |
| 73 | */ |
| 74 | KorAP.context = KorAP.context || |
| 75 | "(?:^|[^-_a-zA-Z0-9])" + // Anchor |
| 76 | "((?:[-_a-zA-Z0-9]+?)\/" + // Foundry |
| 77 | "(?:" + |
| 78 | "(?:[-_a-zA-Z0-9]+?)=" + // Layer |
| 79 | "(?:"+ |
| 80 | "(?:[^:=\/ ]+?):|" + // Key |
| 81 | "(?:[^-=\/ ]+?)-" + // Node |
| 82 | ")?" + |
| 83 | ")?" + |
| 84 | ")$"; |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 85 | |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 86 | // Get input field |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 87 | var qfield = param["inputField"] || document.getElementById("q-field"); |
| 88 | if (!qfield) |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 89 | return null; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 90 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 91 | // Create input field |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 92 | this._inputField = inputClass.create(qfield); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 93 | |
| 94 | var inputFieldElement = this._inputField.element(); |
| 95 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 96 | var c = this._inputField.container(); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 97 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 98 | // create alert |
| 99 | c.appendChild(this._alert.element()); |
| 100 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 101 | var that = this; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 102 | |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 103 | this._inputField.container().addEventListener('click', function (e) { |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 104 | if (!this.classList.contains('active')) { |
| 105 | that.show(false); |
| 106 | }; |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 107 | }); |
| 108 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 109 | var _down = function (e) { |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 110 | var code = _codeFromEvent(e); |
| 111 | if (code === 40) { |
| 112 | this.show(false); |
| 113 | e.halt(); |
| 114 | }; |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 115 | }; |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 116 | |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 117 | // Move infobox |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 118 | inputFieldElement.addEventListener("keyup", this.update.bind(this)); |
| 119 | inputFieldElement.addEventListener("click", this.update.bind(this)); |
| 120 | |
| 121 | // Add event listener for key pressed down |
| 122 | inputFieldElement.addEventListener( |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 123 | "keydown", _down.bind(this), false |
| 124 | ); |
| 125 | |
| 126 | // Add touch events |
| 127 | inputFieldElement.addEventListener( |
| 128 | 'touchstart', |
| 129 | this._touch.bind(this), |
| 130 | false |
| 131 | ); |
| 132 | inputFieldElement.addEventListener( |
| 133 | 'touchend', |
| 134 | this._touch.bind(this), |
| 135 | false |
| 136 | ); |
| 137 | inputFieldElement.addEventListener( |
| 138 | 'touchmove', |
| 139 | this._touch.bind(this), |
| 140 | false |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 141 | ); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 142 | |
| 143 | // Set Analyzer for context |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 144 | this._analyzer = analyzerClass.create( |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 145 | param["context"] || KorAP.context |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 146 | ); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 147 | return this; |
| 148 | }, |
| 149 | |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * Return the input field attached to the hint helper. |
| 153 | */ |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 154 | inputField : function () { |
| 155 | return this._inputField; |
| 156 | }, |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 157 | |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * Altert at a specific character position. |
| 161 | */ |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 162 | alert : function (charPos, msg) { |
| 163 | |
| 164 | if (arguments.length === 0) |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 165 | return this._alert; |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 166 | |
| 167 | // Do not alert if already alerted! |
| 168 | if (this._alert.active) |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 169 | return false; |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 170 | |
| 171 | // Move to the correct position |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 172 | this._inputField.moveto(charPos); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 173 | |
| 174 | // Set container to active (aka hide the hint helper button) |
| 175 | |
| 176 | this._alert.show(msg); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 177 | this.active(this._alert); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 178 | return true; |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 179 | }, |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 180 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 181 | _unshowAlert : function () { |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 182 | this._alert.hide(); |
| 183 | this.active(null); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 184 | }, |
| 185 | |
| 186 | update : function () { |
| 187 | this._inputField.update(); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 188 | if (this._alert.hide()) |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 189 | this.active(null); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 190 | }, |
| 191 | |
| 192 | |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 193 | /** |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 194 | * Return hint menu and probably init based on an action |
| 195 | */ |
| 196 | menu : function (action) { |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 197 | if (this._menu[action] === undefined) { |
| 198 | |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 199 | // No matching hint menu |
| 200 | if (KorAP.annotationHelper[action] === undefined) |
| 201 | return; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 202 | |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 203 | // Create matching hint menu |
| 204 | this._menu[action] = menuClass.create( |
| 205 | this, action, KorAP.annotationHelper[action] |
| 206 | ); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | // Return matching hint menu |
| 210 | return this._menu[action]; |
| 211 | }, |
| 212 | |
| 213 | /** |
| 214 | * Get the correct menu based on the context |
| 215 | */ |
| 216 | contextMenu : function (ifContext) { |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 217 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 218 | // Get context (aka left text) |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 219 | var context = this._inputField.context(); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 220 | |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 221 | if (context === undefined || context.length === 0) { |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 222 | return ifContext ? undefined : this.menu("-"); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 223 | }; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 224 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 225 | // Get context (aka left text matching regex) |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 226 | context = this._analyzer.test(context); |
Akron | ee9ef4a | 2016-06-03 12:50:08 +0200 | [diff] [blame] | 227 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 228 | if (context === undefined || context.length == 0) { |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 229 | return ifContext ? undefined : this.menu("-"); |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 230 | }; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 231 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 232 | return this.menu(context) || (ifContext ? undefined : this.menu('-')); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 233 | }, |
| 234 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 235 | /** |
| 236 | * Activate a certain menu. |
| 237 | * If a menu is passed, the menu will be activated. |
| 238 | * If null is passed, the active menu will be deactivated. |
| 239 | * If nothing is passed, returns the active menu. |
| 240 | */ |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 241 | active : function (obj) { |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 242 | |
| 243 | // A menu or null was passed |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 244 | if (arguments.length === 1) { |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 245 | var c = this._inputField.container(); |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 246 | |
| 247 | // Make the menu active |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 248 | if (obj !== null) { |
| 249 | c.classList.add('active'); |
| 250 | this._active = obj; |
| 251 | } |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 252 | |
| 253 | // Make the menu inactive |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 254 | else { |
| 255 | c.classList.remove('active'); |
| 256 | this._active = null; |
| 257 | } |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 258 | }; |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 259 | |
| 260 | // Return |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 261 | return this._active; |
| 262 | }, |
| 263 | |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 264 | |
| 265 | /** |
Akron | 308db38 | 2016-05-30 22:34:07 +0200 | [diff] [blame] | 266 | * Show the menu. |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 267 | * Remove all old menus. |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 268 | * |
| 269 | * @param {boolean} Boolean value to indicate if context |
| 270 | * is necessary (true) or if the main context should |
| 271 | * be shown if context fails. |
| 272 | * |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 273 | */ |
| 274 | show : function (ifContext) { |
| 275 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 276 | // Remove the active object |
| 277 | this._unshow(); |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 278 | |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 279 | // Get the menu |
| 280 | var menu; |
| 281 | if (menu = this.contextMenu(ifContext)) { |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 282 | this.active(menu); |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 283 | |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 284 | var c = this._inputField.container(); |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 285 | c.appendChild(menu.element()); |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 286 | |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 287 | menu.show(); |
| 288 | menu.focus(); |
| 289 | // Focus on input field |
| 290 | // this.inputField.element.focus(); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 291 | } |
| 292 | else { |
| 293 | this._inputField.element().focus(); |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 294 | }; |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 295 | }, |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 296 | |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 297 | // This will get the context of the field |
| 298 | getContext : function () {}, |
| 299 | |
Akron | 8eaeb2e | 2016-08-29 18:26:28 +0200 | [diff] [blame] | 300 | /** |
| 301 | * Deactivate the current menu and focus on the input field. |
| 302 | */ |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 303 | unshow_old : function () { |
Akron | 02360e4 | 2016-06-07 13:41:12 +0200 | [diff] [blame] | 304 | this.active(null); |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 305 | this.inputField().element().focus(); |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 306 | }, |
| 307 | |
| 308 | /** |
| 309 | * Deactivate the current menu and focus on the input field. |
| 310 | */ |
| 311 | unshow : function () { |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 312 | this._unshow(); |
| 313 | this._inputField.element().focus(); |
| 314 | }, |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 315 | |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 316 | |
| 317 | // Catch touch events |
| 318 | _touch : function (e) { |
| 319 | |
| 320 | if (e.type === 'touchstart') { |
| 321 | var t = e.touches[0]; |
| 322 | this._lastTouch = t.clientY; |
| 323 | } |
| 324 | else if (e.type === 'touchend') { |
| 325 | this._lastTouch = undefined; |
| 326 | } |
| 327 | else if (e.type == 'touchmove') { |
| 328 | var t = e.touches[0]; |
| 329 | if ((this._lastTouch + 10) < t.clientY) { |
| 330 | this.show(); |
| 331 | this._lastTouch = undefined; |
| 332 | }; |
| 333 | e.halt(); |
| 334 | } |
| 335 | }, |
| 336 | |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 337 | |
| 338 | _unshow : function () { |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 339 | if (this.active() !== null) { |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 340 | // var act = this.active(); |
Akron | e39cc86 | 2018-04-25 15:16:11 +0200 | [diff] [blame] | 341 | |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 342 | // This does not work for alert currently! |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 343 | //if (act._type !== 'alert') { |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 344 | if (!this._alert.active) { |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 345 | |
| 346 | // This does not work for webkit! |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 347 | var c = this._inputField.container(); |
Akron | e39cc86 | 2018-04-25 15:16:11 +0200 | [diff] [blame] | 348 | c.removeChild(this._active.element()); |
Akron | c14cbfc | 2018-08-31 13:15:55 +0200 | [diff] [blame^] | 349 | } |
Akron | 1a5a587 | 2016-09-05 20:17:14 +0200 | [diff] [blame] | 350 | else { |
| 351 | this._unshowAlert(); |
| 352 | }; |
| 353 | |
Akron | 65c7435 | 2016-09-02 17:23:39 +0200 | [diff] [blame] | 354 | // this._active.hide(); |
| 355 | this.active(null); |
| 356 | }; |
Nils Diewald | 19ccee9 | 2014-12-08 11:30:08 +0000 | [diff] [blame] | 357 | } |
| 358 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 359 | }); |