jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/playback/brightnessosd.js
2017-02-26 16:48:13 -05:00

1 line
2.5 KiB
JavaScript

define(["events","playbackManager","dom","browser","css!./iconosd","material-icons"],function(events,playbackManager,dom,browser){"use strict";function getOsdElementHtml(){var html="";return html+='<i class="md-icon iconOsdIcon">&#xE1AC;</i>',html+='<div class="iconOsdProgressOuter"><div class="iconOsdProgressInner brightnessOsdProgressInner"></div></div>'}function ensureOsdElement(){var elem=osdElement;elem||(enableAnimation=browser.supportsCssAnimation(),elem=document.createElement("div"),elem.classList.add("hide"),elem.classList.add("iconOsd"),elem.classList.add("iconOsd-hidden"),elem.classList.add("brightnessOsd"),elem.innerHTML=getOsdElementHtml(),iconElement=elem.querySelector("i"),progressElement=elem.querySelector(".iconOsdProgressInner"),document.body.appendChild(elem),osdElement=elem)}function onHideComplete(){this.classList.add("hide")}function showOsd(){clearHideTimeout();var elem=osdElement;dom.removeEventListener(elem,dom.whichTransitionEvent(),onHideComplete,{once:!0}),elem.classList.remove("hide"),void elem.offsetWidth,requestAnimationFrame(function(){elem.classList.remove("iconOsd-hidden"),hideTimeout=setTimeout(hideOsd,3e3)})}function clearHideTimeout(){hideTimeout&&(clearTimeout(hideTimeout),hideTimeout=null)}function hideOsd(){clearHideTimeout();var elem=osdElement;elem&&(enableAnimation?(void elem.offsetWidth,requestAnimationFrame(function(){elem.classList.add("iconOsd-hidden"),dom.addEventListener(elem,dom.whichTransitionEvent(),onHideComplete,{once:!0})})):onHideComplete.call(elem))}function updateElementsFromPlayer(brightness){iconElement&&(brightness>=80?iconElement.innerHTML="&#xE1AC;":brightness>=20?iconElement.innerHTML="&#xE1AE;":iconElement.innerHTML="&#xE1AD;"),progressElement&&(progressElement.style.width=(brightness||0)+"%")}function releaseCurrentPlayer(){var player=currentPlayer;player&&(events.off(player,"brightnesschange",onBrightnessChanged),events.off(player,"playbackstop",hideOsd),currentPlayer=null)}function onBrightnessChanged(e){var player=this;ensureOsdElement(),updateElementsFromPlayer(playbackManager.getBrightness(player)),showOsd()}function bindToPlayer(player){player!==currentPlayer&&(releaseCurrentPlayer(),currentPlayer=player,player&&(hideOsd(),events.on(player,"brightnesschange",onBrightnessChanged),events.on(player,"playbackstop",hideOsd)))}var currentPlayer,osdElement,iconElement,progressElement,enableAnimation,hideTimeout;events.on(playbackManager,"playerchange",function(){bindToPlayer(playbackManager.getCurrentPlayer())}),bindToPlayer(playbackManager.getCurrentPlayer())});