vendor: 5,506 bytes, lines 1-201
1 2/** 3 * what-input - A global utility for tracking the current input method (mouse, keyboard or touch). 4 * @version v4.2.0 5 * @link https://github.com/ten1seven/what-input 6 * @license MIT 7 */ 8(function webpackUniversalModuleDefinition(root, factory) { 9 if(typeof exports === 'object' && typeof module === 'object') 10 module.exports = factory(); 11 else if(typeof define === 'function' && define.amd) 12 define("whatInput", [], factory); 13 else if(typeof exports === 'object') 14 exports["whatInput"] = factory(); 15 else 16 root["whatInput"] = factory(); 17})(this, function() { 18return /******/ (function(modules) { // webpackBootstrap 19/******/ // The module cache 20/******/ var installedModules = {}; 21 22/******/ // The require function 23/******/ function __webpack_require__(moduleId) { 24 25/******/ // Check if module is in cache 26/******/ if(installedModules[moduleId]) 27/******/ return installedModules[moduleId].exports; 28 29/******/ // Create a new module (and put it into the cache) 30/******/ var module = installedModules[moduleId] = { 31/******/ exports: {}, 32/******/ id: moduleId, 33/******/ loaded: false 34/******/ }; 35 36/******/ // Execute the module function 37/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 38 39/******/ // Flag the module as loaded 40/******/ module.loaded = true; 41 42/******/ // Return the exports of the module 43/******/ return module.exports; 44/******/ } 45 46 47/******/ // expose the modules object (__webpack_modules__) 48/******/ __webpack_require__.m = modules; 49 50/******/ // expose the module cache 51/******/ __webpack_require__.c = installedModules; 52 53/******/ // __webpack_public_path__ 54/******/ __webpack_require__.p = ""; 55 56/******/ // Load entry module and return exports 57/******/ return __webpack_require__(0); 58/******/ }) 59/************************************************************************/ 60/******/ ([ 61/* 0 */ 62/***/ (function(module, exports) { 63 64 'use strict'; 65 66 module.exports = function () { 67 /* 68 * variables 69 */ 70 71 // last used input type 72 var currentInput = 'initial'; 73 74 // last used input intent 75 var currentIntent = null; 76 77 // cache document.documentElement 78 var doc = document.documentElement; 79 80 // form input types 81 var formInputs = ['input', 'select', 'textarea']; 82 83 var functionList = []; 84 85 // list of modifier keys commonly used with the mouse and 86 // can be safely ignored to prevent false keyboard detection 87 var ignoreMap = [16, // shift 88 17, // control 89 18, // alt 90 91, // Windows key / left Apple cmd 91 93 // Windows menu / right Apple cmd 92 ]; 93 94 // list of keys for which we change intent even for form inputs 95 var changeIntentMap = [9 // tab 96 ]; 97 98 // mapping of events to input types 99 var inputMap = { 100 keydown: 'keyboard', 101 mousedown: 'mouse', 102 mousemove: 'mouse', 103 MSPointerDown: 'pointer', 104 MSPointerMove: 'pointer', 105 pointerdown: 'pointer', 106 pointermove: 'pointer', 107 touchstart: 'touch' 108 }; 109 110 // array of all used input types 111 var inputTypes = []; 112 113 // boolean: true if touch buffer is active 114 var isBuffering = false; 115 116 // boolean: true if the page is being scrolled 117 var isScrolling = false; 118 119 // store current mouse position 120 var mousePos = { 121 x: null, 122 y: null 123 }; 124 125 // map of IE 10 pointer events 126 var pointerMap = { 127 2: 'touch', 128 3: 'touch', // treat pen like touch 129 4: 'mouse' 130 }; 131 132 var supportsPassive = false; 133 134 try { 135 var opts = Object.defineProperty({}, 'passive', { 136 get: function get() { 137 supportsPassive = true; 138 } 139 }); 140 141 window.addEventListener('test', null, opts); 142 } catch (e) {} 143 144 /* 145 * set up 146 */ 147 148 var setUp = function setUp() { 149 // add correct mouse wheel event mapping to `inputMap` 150 inputMap[detectWheel()] = 'mouse'; 151 152 addListeners(); 153 setInput(); 154 }; 155 156 /* 157 * events 158 */ 159 160 var addListeners = function addListeners() { 161 // `pointermove`, `MSPointerMove`, `mousemove` and mouse wheel event binding 162 // can only demonstrate potential, but not actual, interaction 163 // and are treated separately 164 165 // pointer events (mouse, pen, touch) 166 if (window.PointerEvent) { 167 doc.addEventListener('pointerdown', updateInput); 168 doc.addEventListener('pointermove', setIntent); 169 } else if (window.MSPointerEvent) { 170 doc.addEventListener('MSPointerDown', updateInput); 171 doc.addEventListener('MSPointerMove', setIntent); 172 } else { 173 // mouse events 174 doc.addEventListener('mousedown', updateInput); 175 doc.addEventListener('mousemove', setIntent); 176 177 // touch events 178 if ('ontouchstart' in window) { 179 doc.addEventListener('touchstart', touchBuffer); 180 doc.addEventListener('touchend', touchBuffer); 181 } 182 } 183 184 // mouse wheel 185 doc.addEventListener(detectWheel(), setIntent, supportsPassive ? { passive: true } : false); 186 187 // keyboard events 188 doc.addEventListener('keydown', updateInput); 189 }; 190 191 // checks conditions before updating new input 192 var updateInput = function updateInput(event) { 193 // only execute if the touch buffer timer isn't running 194 if (!isBuffering) { 195 var eventKey = event.which; 196 var value = inputMap[event.type]; 197 if (value === 'pointer') value = pointerType(event); 198 199 if (currentInput !== value || currentIntent !== value) { 200 var activeElem = document.activeElement; 201 var activeInput = false;
202 var notFormInput = activeElem && activeElem.nodeName && formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1; 203 204 if (notFormInput || changeIntentMap.indexOf(eventKey) !== -1) { 205 activeInput = true; 206 } 207 208 if (value === 'touch' || 209 // ignore mouse modifier keys 210 value === 'mouse' || 211 // don't switch if the current element is a form input 212 value === 'keyboard' && eventKey && activeInput && ignoreMap.indexOf(eventKey) === -1) { 213 // set the current and catch-all variable 214 currentInput = currentIntent = value; 215 216 setInput(); 217 } 218 } 219 } 220 }; 221 222 // updates the doc and `inputTypes` array with new input 223 var setInput = function setInput() { 224 doc.setAttribute('data-whatinput', currentInput); 225 doc.setAttribute('data-whatintent', currentInput); 226 227 if (inputTypes.indexOf(currentInput) === -1) { 228 inputTypes.push(currentInput); 229 doc.className += ' whatinput-types-' + currentInput; 230 } 231 232 fireFunctions('input'); 233 }; 234 235 // updates input intent for `mousemove` and `pointermove` 236 var setIntent = function setIntent(event) { 237 // test to see if `mousemove` happened relative to the screen 238 // to detect scrolling versus mousemove 239 if (mousePos['x'] !== event.screenX || mousePos['y'] !== event.screenY) { 240 isScrolling = false; 241 242 mousePos['x'] = event.screenX; 243 mousePos['y'] = event.screenY; 244 } else { 245 isScrolling = true; 246 } 247 248 // only execute if the touch buffer timer isn't running 249 // or scrolling isn't happening 250 if (!isBuffering && !isScrolling) { 251 var value = inputMap[event.type]; 252 if (value === 'pointer') value = pointerType(event); 253 254 if (currentIntent !== value) { 255 currentIntent = value; 256 257 doc.setAttribute('data-whatintent', currentIntent); 258 259 fireFunctions('intent'); 260 } 261 } 262 }; 263 264 // buffers touch events because they frequently also fire mouse events 265 var touchBuffer = function touchBuffer(event) { 266 if (event.type === 'touchstart') { 267 isBuffering = false; 268 269 // set the current input 270 updateInput(event); 271 } else { 272 isBuffering = true; 273 } 274 }; 275 276 var fireFunctions = function fireFunctions(type) { 277 for (var i = 0, len = functionList.length; i < len; i++) { 278 if (functionList[i].type === type) { 279 functionList[i].function.call(undefined, currentIntent); 280 } 281 } 282 }; 283 284 /* 285 * utilities 286 */ 287 288 var pointerType = function pointerType(event) { 289 if (typeof event.pointerType === 'number') { 290 return pointerMap[event.pointerType]; 291 } else { 292 // treat pen like touch 293 return event.pointerType === 'pen' ? 'touch' : event.pointerType; 294 } 295 }; 296 297 // detect version of mouse wheel event to use 298 // via https://developer.mozilla.org/en-US/docs/Web/Events/wheel 299 var detectWheel = function detectWheel() { 300 var wheelType = void 0; 301 302 // Modern browsers support "wheel" 303 if ('onwheel' in document.createElement('div')) { 304 wheelType = 'wheel'; 305 } else { 306 // Webkit and IE support at least "mousewheel" 307 // or assume that remaining browsers are older Firefox 308 wheelType = document.onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll'; 309 } 310 311 return wheelType; 312 }; 313 314 /* 315 * init 316 */ 317 318 // don't start script unless browser cuts the mustard 319 // (also passes if polyfills are used) 320 if ('addEventListener' in window && Array.prototype.indexOf) { 321 setUp(); 322 } 323 324 /* 325 * api 326 */ 327 328 return { 329 // returns string: the current input type 330 // opt: 'loose'|'strict' 331 // 'strict' (default): returns the same value as the `data-whatinput` attribute 332 // 'loose': includes `data-whatintent` value if it's more current than `data-whatinput` 333 ask: function ask(opt) { 334 return opt === 'loose' ? currentIntent : currentInput; 335 }, 336 337 // returns array: all the detected input types 338 types: function types() { 339 return inputTypes; 340 }, 341 342 // overwrites ignored keys with provided array 343 ignoreKeys: function ignoreKeys(arr) { 344 ignoreMap = arr; 345 }, 346 347 // attach functions to input and intent "events" 348 // funct: function to fire on change 349 // eventType: 'input'|'intent' 350 onChange: function onChange(funct, eventType) { 351 functionList.push({ 352 function: funct, 353 type: eventType 354 }); 355 } 356 }; 357 }(); 358 359/***/ }) 360/******/ ]) 361}); 362; 363 364 365
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.