1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/elements/emby-itemrefreshindicator/emby-itemrefreshindicator.js

75 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import EmbyProgressRing from '../emby-progressring/emby-progressring';
import dom from '../../scripts/dom';
import serverNotifications from '../../scripts/serverNotifications';
import Events from '../../utils/events.ts';
2020-09-08 02:43:56 -04:00
import 'webcomponents.js/webcomponents-lite';
2023-04-19 01:56:05 -04:00
function addNotificationEvent(instance, name, handler) {
const localHandler = handler.bind(instance);
Events.on(serverNotifications, name, localHandler);
instance[name] = localHandler;
}
function removeNotificationEvent(instance, name) {
const handler = instance[name];
if (handler) {
Events.off(serverNotifications, name, handler);
instance[name] = null;
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function onRefreshProgress(e, apiClient, info) {
const indicator = this;
if (!indicator.itemId) {
indicator.itemId = dom.parentWithAttribute(indicator, 'data-id').getAttribute('data-id');
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
if (info.ItemId === indicator.itemId) {
const progress = parseFloat(info.Progress);
2023-04-19 01:56:05 -04:00
if (progress && progress < 100) {
this.classList.remove('hide');
} else {
this.classList.add('hide');
}
2023-04-19 01:56:05 -04:00
this.setAttribute('data-progress', progress);
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
}
2023-04-19 01:56:05 -04:00
const EmbyItemRefreshIndicatorPrototype = Object.create(EmbyProgressRing);
2023-04-19 01:56:05 -04:00
EmbyItemRefreshIndicatorPrototype.createdCallback = function () {
// base method
if (EmbyProgressRing.createdCallback) {
EmbyProgressRing.createdCallback.call(this);
}
2023-04-19 01:56:05 -04:00
addNotificationEvent(this, 'RefreshProgress', onRefreshProgress);
};
2023-04-19 01:56:05 -04:00
EmbyItemRefreshIndicatorPrototype.attachedCallback = function () {
// base method
if (EmbyProgressRing.attachedCallback) {
EmbyProgressRing.attachedCallback.call(this);
}
};
2023-04-19 01:56:05 -04:00
EmbyItemRefreshIndicatorPrototype.detachedCallback = function () {
// base method
if (EmbyProgressRing.detachedCallback) {
EmbyProgressRing.detachedCallback.call(this);
}
2023-04-19 01:56:05 -04:00
removeNotificationEvent(this, 'RefreshProgress');
this.itemId = null;
};
2023-04-19 01:56:05 -04:00
document.registerElement('emby-itemrefreshindicator', {
prototype: EmbyItemRefreshIndicatorPrototype,
extends: 'div'
});