jellyfish-web/src/elements/emby-progressbar/emby-progressbar.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-04-13 13:09:01 +02:00
2023-04-19 01:56:05 -04:00
const ProgressBarPrototype = Object.create(HTMLDivElement.prototype);
2020-04-13 13:09:01 +02:00
2023-04-19 01:56:05 -04:00
function onAutoTimeProgress() {
const start = parseInt(this.getAttribute('data-starttime'), 10);
const end = parseInt(this.getAttribute('data-endtime'), 10);
2020-04-13 13:09:01 +02:00
2023-04-19 01:56:05 -04:00
const now = new Date().getTime();
const total = end - start;
let pct = 100 * ((now - start) / total);
2020-04-13 13:09:01 +02:00
2023-04-19 01:56:05 -04:00
pct = Math.min(100, pct);
pct = Math.max(0, pct);
2020-04-13 13:09:01 +02:00
2023-04-19 01:56:05 -04:00
const itemProgressBarForeground = this.querySelector('.itemProgressBarForeground');
itemProgressBarForeground.style.width = pct + '%';
}
ProgressBarPrototype.attachedCallback = function () {
if (this.timeInterval) {
clearInterval(this.timeInterval);
}
if (this.getAttribute('data-automode') === 'time') {
this.timeInterval = setInterval(onAutoTimeProgress.bind(this), 60000);
2020-04-13 13:09:01 +02:00
}
2023-04-19 01:56:05 -04:00
};
ProgressBarPrototype.detachedCallback = function () {
if (this.timeInterval) {
clearInterval(this.timeInterval);
this.timeInterval = null;
}
};
document.registerElement('emby-progressbar', {
prototype: ProgressBarPrototype,
extends: 'div'
});
2020-04-13 13:09:01 +02:00