jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/input/mouse.js
Luke Pulverenti 8a6884abef minify
2017-01-27 18:07:14 -05:00

1 line
1.5 KiB
JavaScript

define(["inputManager","focusManager","browser","layoutManager","events","dom"],function(inputmanager,focusManager,browser,layoutManager,events,dom){"use strict";function mouseIdleTime(){return(new Date).getTime()-lastMouseInputTime}function notifyApp(){inputmanager.notifyMouseMove()}function onMouseEnter(e){var parent=focusManager.focusableParent(e.target);parent&&focusManager.focus(e.target)}function enableFocusWithMouse(){return!!layoutManager.tv&&(!!browser.xboxOne||!!browser.tv)}function initMouseFocus(){dom.removeEventListener(document,"mouseenter",onMouseEnter,{capture:!0,passive:!0}),enableFocusWithMouse()&&dom.addEventListener(document,"mouseenter",onMouseEnter,{capture:!0,passive:!0})}var isMouseIdle,lastMouseMoveData,self={},lastMouseInputTime=(new Date).getTime();return dom.addEventListener(document,"mousemove",function(e){var eventX=e.screenX,eventY=e.screenY;if("undefined"!=typeof eventX||"undefined"!=typeof eventY){var obj=lastMouseMoveData;return obj?void(Math.abs(eventX-obj.x)<10&&Math.abs(eventY-obj.y)<10||(obj.x=eventX,obj.y=eventY,lastMouseInputTime=(new Date).getTime(),notifyApp(),isMouseIdle&&(isMouseIdle=!1,document.body.classList.remove("mouseIdle"),events.trigger(self,"mouseactive")))):void(lastMouseMoveData={x:eventX,y:eventY})}},{passive:!0}),initMouseFocus(),events.on(layoutManager,"modechange",initMouseFocus),setInterval(function(){mouseIdleTime()>=5e3&&(isMouseIdle=!0,document.body.classList.add("mouseIdle"),events.trigger(self,"mouseidle"))},5e3),self});