12345678 |
- /**
- * what-input - A global utility for tracking the current input method (mouse, keyboard or touch).
- * @version v5.1.4
- * @link https://github.com/ten1seven/what-input
- * @license MIT
- */
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("whatInput",[],t):"object"==typeof exports?exports.whatInput=t():e.whatInput=t()}(this,function(){return function(n){var o={};function i(e){if(o[e])return o[e].exports;var t=o[e]={exports:{},id:e,loaded:!1};return n[e].call(t.exports,t,t.exports,i),t.loaded=!0,t.exports}return i.m=n,i.c=o,i.p="",i(0)}([function(e,t){"use strict";e.exports=function(){if("undefined"==typeof document||"undefined"==typeof window)return{ask:function(){return"initial"},element:function(){return null},ignoreKeys:function(){},specificKeys:function(){},registerOnChange:function(){},unRegisterOnChange:function(){}};var t=document.documentElement,n=null,s="initial",a=s;try{window.sessionStorage.getItem("what-input")&&(s=window.sessionStorage.getItem("what-input")),window.sessionStorage.getItem("what-intent")&&(a=window.sessionStorage.getItem("what-intent"))}catch(e){}var o=null,d=["input","select","textarea"],i=[],c=[16,17,18,91,93],w=[],f={keydown:"keyboard",keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch",touchend:"touch"},p=!1,r=!1,u={x:null,y:null},l={2:"touch",3:"touch",4:"mouse"},h=!1;try{var e=Object.defineProperty({},"passive",{get:function(){h=!0}});window.addEventListener("test",null,e)}catch(e){}var m=function(){var e=!!h&&{passive:!0};window.PointerEvent?(window.addEventListener("pointerdown",v),window.addEventListener("pointermove",g)):window.MSPointerEvent?(window.addEventListener("MSPointerDown",v),window.addEventListener("MSPointerMove",g)):(window.addEventListener("mousedown",v),window.addEventListener("mousemove",g),"ontouchstart"in window&&(window.addEventListener("touchstart",x,e),window.addEventListener("touchend",v))),window.addEventListener(b(),g,e),window.addEventListener("keydown",x),window.addEventListener("keyup",x),window.addEventListener("focusin",E),window.addEventListener("focusout",L)},v=function(e){if(!p){var t=e.which,n=f[e.type];"pointer"===n&&(n=S(e));var o=!w.length&&-1===c.indexOf(t),i=w.length&&-1!==w.indexOf(t),r="keyboard"===n&&t&&(o||i)||"mouse"===n||"touch"===n;if(s!==n&&r){s=n;try{window.sessionStorage.setItem("what-input",s)}catch(e){}y("input")}if(a!==n&&r){var u=document.activeElement;if(u&&u.nodeName&&-1===d.indexOf(u.nodeName.toLowerCase())){a=n;try{window.sessionStorage.setItem("what-intent",a)}catch(e){}y("intent")}}}},y=function(e){t.setAttribute("data-what"+e,"input"===e?s:a),I(e)},g=function(e){if(O(e),!p&&!r){var t=f[e.type];if("pointer"===t&&(t=S(e)),a!==t){a=t;try{window.sessionStorage.setItem("what-intent",a)}catch(e){}y("intent")}}},E=function(e){e.target.nodeName?(n=e.target.nodeName.toLowerCase(),t.setAttribute("data-whatelement",n),e.target.classList&&e.target.classList.length&&t.setAttribute("data-whatclasses",e.target.classList.toString().replace(" ",","))):L()},L=function(){n=null,t.removeAttribute("data-whatelement"),t.removeAttribute("data-whatclasses")},x=function(e){v(e),window.clearTimeout(o),p=!0,o=window.setTimeout(function(){p=!1},120)},S=function(e){return"number"==typeof e.pointerType?l[e.pointerType]:"pen"===e.pointerType?"touch":e.pointerType},b=function(){return"onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll"},I=function(e){for(var t=0,n=i.length;t<n;t++)i[t].type===e&&i[t].fn.call(void 0,"input"===e?s:a)},O=function(e){u.x!==e.screenX||u.y!==e.screenY?(r=!1,u.x=e.screenX,u.y=e.screenY):r=!0};return"addEventListener"in window&&Array.prototype.indexOf&&(f[b()]="mouse",m(),y("input"),y("intent")),{ask:function(e){return"intent"===e?a:s},element:function(){return n},ignoreKeys:function(e){c=e},specificKeys:function(e){w=e},registerOnChange:function(e,t){i.push({fn:e,type:t||"input"})},unRegisterOnChange:function(e){var t=function(e){for(var t=0,n=i.length;t<n;t++)if(i[t].fn===e)return t}(e);(t||0===t)&&i.splice(t,1)}}}()}])});
- //# sourceMappingURL=maps/what-input.min.js.map
|