1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
This commit is contained in:
Luke Pulverenti 2017-01-27 18:07:14 -05:00
parent 82bcca376f
commit 8a6884abef
494 changed files with 256 additions and 120180 deletions

View file

@ -1,179 +1 @@
define(['browser', 'dom', 'css!./emby-slider', 'registerElement', 'emby-input'], function (browser, dom) {
'use strict';
var EmbySliderPrototype = Object.create(HTMLInputElement.prototype);
var supportsNativeProgressStyle = browser.firefox || browser.edge || browser.msie;
var supportsValueSetOverride = false;
if (Object.getOwnPropertyDescriptor && Object.defineProperty) {
var descriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
// descriptor returning null in webos
if (descriptor && descriptor.configurable) {
supportsValueSetOverride = true;
}
}
function updateValues(range, backgroundLower, backgroundUpper) {
var value = range.value;
requestAnimationFrame(function () {
if (backgroundLower) {
var fraction = (value - range.min) / (range.max - range.min);
if (browser.noFlex) {
backgroundLower.style['-webkit-flex'] = fraction;
backgroundUpper.style['-webkit-flex'] = 1 - fraction;
backgroundLower.style['-webkit-box-flex'] = fraction;
backgroundUpper.style['-webkit-box-flex'] = 1 - fraction;
}
backgroundLower.style.flex = fraction;
backgroundUpper.style.flex = 1 - fraction;
}
});
}
function updateBubble(range, value, bubble, bubbleText) {
bubble.style.left = value + '%';
if (range.getBubbleHtml) {
value = range.getBubbleHtml(value);
} else {
if (range.getBubbleText) {
value = range.getBubbleText(value);
} else {
value = Math.round(value);
}
value = '<h1 class="sliderBubbleText">' + value + '</h1>';
}
bubble.innerHTML = value;
}
EmbySliderPrototype.attachedCallback = function () {
if (this.getAttribute('data-embyslider') === 'true') {
return;
}
this.setAttribute('data-embyslider', 'true');
this.classList.add('mdl-slider');
this.classList.add('mdl-js-slider');
if (browser.noFlex) {
this.classList.add('slider-no-webkit-thumb');
}
var containerElement = this.parentNode;
containerElement.classList.add('mdl-slider__container');
var htmlToInsert = '';
if (!supportsNativeProgressStyle) {
htmlToInsert += '<div class="mdl-slider__background-flex"><div class="mdl-slider__background-lower"></div><div class="mdl-slider__background-upper"></div></div>';
}
htmlToInsert += '<div class="sliderBubble hide"></div>';
containerElement.insertAdjacentHTML('beforeend', htmlToInsert);
var backgroundLower = containerElement.querySelector('.mdl-slider__background-lower');
var backgroundUpper = containerElement.querySelector('.mdl-slider__background-upper');
var sliderBubble = containerElement.querySelector('.sliderBubble');
var hasHideClass = sliderBubble.classList.contains('hide');
dom.addEventListener(this, 'input', function (e) {
this.dragging = true;
updateBubble(this, this.value, sliderBubble);
if (hasHideClass) {
sliderBubble.classList.remove('hide');
hasHideClass = false;
}
}, {
passive: true
});
dom.addEventListener(this, 'change', function () {
this.dragging = false;
updateValues(this, backgroundLower, backgroundUpper);
sliderBubble.classList.add('hide');
hasHideClass = true;
}, {
passive: true
});
// In firefox this feature disrupts the ability to move the slider
if (!browser.firefox) {
dom.addEventListener(this, 'mousemove', function (e) {
if (!this.dragging) {
var rect = this.getBoundingClientRect();
var clientX = e.clientX;
var bubbleValue = (clientX - rect.left) / rect.width;
bubbleValue *= 100;
updateBubble(this, bubbleValue, sliderBubble);
if (hasHideClass) {
sliderBubble.classList.remove('hide');
hasHideClass = false;
}
}
}, {
passive: true
});
dom.addEventListener(this, 'mouseleave', function () {
sliderBubble.classList.add('hide');
hasHideClass = true;
}, {
passive: true
});
}
if (!supportsNativeProgressStyle) {
if (supportsValueSetOverride) {
this.addEventListener('valueset', function () {
updateValues(this, backgroundLower, backgroundUpper);
});
} else {
startInterval(this, backgroundLower, backgroundUpper);
}
}
};
function startInterval(range, backgroundLower, backgroundUpper) {
var interval = range.interval;
if (interval) {
clearInterval(interval);
}
range.interval = setInterval(function () {
updateValues(range, backgroundLower, backgroundUpper);
}, 100);
}
EmbySliderPrototype.detachedCallback = function () {
var interval = this.interval;
if (interval) {
clearInterval(interval);
}
this.interval = null;
};
document.registerElement('emby-slider', {
prototype: EmbySliderPrototype,
extends: 'input'
});
});
define(["browser","dom","css!./emby-slider","registerElement","emby-input"],function(browser,dom){"use strict";function updateValues(range,backgroundLower,backgroundUpper){var value=range.value;requestAnimationFrame(function(){if(backgroundLower){var fraction=(value-range.min)/(range.max-range.min);browser.noFlex&&(backgroundLower.style["-webkit-flex"]=fraction,backgroundUpper.style["-webkit-flex"]=1-fraction,backgroundLower.style["-webkit-box-flex"]=fraction,backgroundUpper.style["-webkit-box-flex"]=1-fraction),backgroundLower.style.flex=fraction,backgroundUpper.style.flex=1-fraction}})}function updateBubble(range,value,bubble,bubbleText){bubble.style.left=value+"%",range.getBubbleHtml?value=range.getBubbleHtml(value):(value=range.getBubbleText?range.getBubbleText(value):Math.round(value),value='<h1 class="sliderBubbleText">'+value+"</h1>"),bubble.innerHTML=value}function startInterval(range,backgroundLower,backgroundUpper){var interval=range.interval;interval&&clearInterval(interval),range.interval=setInterval(function(){updateValues(range,backgroundLower,backgroundUpper)},100)}var EmbySliderPrototype=Object.create(HTMLInputElement.prototype),supportsNativeProgressStyle=browser.firefox||browser.edge||browser.msie,supportsValueSetOverride=!1;if(Object.getOwnPropertyDescriptor&&Object.defineProperty){var descriptor=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");descriptor&&descriptor.configurable&&(supportsValueSetOverride=!0)}EmbySliderPrototype.attachedCallback=function(){if("true"!==this.getAttribute("data-embyslider")){this.setAttribute("data-embyslider","true"),this.classList.add("mdl-slider"),this.classList.add("mdl-js-slider"),browser.noFlex&&this.classList.add("slider-no-webkit-thumb");var containerElement=this.parentNode;containerElement.classList.add("mdl-slider__container");var htmlToInsert="";supportsNativeProgressStyle||(htmlToInsert+='<div class="mdl-slider__background-flex"><div class="mdl-slider__background-lower"></div><div class="mdl-slider__background-upper"></div></div>'),htmlToInsert+='<div class="sliderBubble hide"></div>',containerElement.insertAdjacentHTML("beforeend",htmlToInsert);var backgroundLower=containerElement.querySelector(".mdl-slider__background-lower"),backgroundUpper=containerElement.querySelector(".mdl-slider__background-upper"),sliderBubble=containerElement.querySelector(".sliderBubble"),hasHideClass=sliderBubble.classList.contains("hide");dom.addEventListener(this,"input",function(e){this.dragging=!0,updateBubble(this,this.value,sliderBubble),hasHideClass&&(sliderBubble.classList.remove("hide"),hasHideClass=!1)},{passive:!0}),dom.addEventListener(this,"change",function(){this.dragging=!1,updateValues(this,backgroundLower,backgroundUpper),sliderBubble.classList.add("hide"),hasHideClass=!0},{passive:!0}),browser.firefox||(dom.addEventListener(this,"mousemove",function(e){if(!this.dragging){var rect=this.getBoundingClientRect(),clientX=e.clientX,bubbleValue=(clientX-rect.left)/rect.width;bubbleValue*=100,updateBubble(this,bubbleValue,sliderBubble),hasHideClass&&(sliderBubble.classList.remove("hide"),hasHideClass=!1)}},{passive:!0}),dom.addEventListener(this,"mouseleave",function(){sliderBubble.classList.add("hide"),hasHideClass=!0},{passive:!0})),supportsNativeProgressStyle||(supportsValueSetOverride?this.addEventListener("valueset",function(){updateValues(this,backgroundLower,backgroundUpper)}):startInterval(this,backgroundLower,backgroundUpper))}},EmbySliderPrototype.detachedCallback=function(){var interval=this.interval;interval&&clearInterval(interval),this.interval=null},document.registerElement("emby-slider",{prototype:EmbySliderPrototype,extends:"input"})});