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

78 lines
2.3 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';
/* eslint-disable indent */
2018-10-23 01:05:09 +03:00
function addNotificationEvent(instance, name, handler) {
const localHandler = handler.bind(instance);
2020-09-08 02:05:02 -04:00
Events.on(serverNotifications, name, localHandler);
instance[name] = localHandler;
2018-10-23 01:05:09 +03:00
}
function removeNotificationEvent(instance, name) {
const handler = instance[name];
if (handler) {
2020-09-08 02:05:02 -04:00
Events.off(serverNotifications, name, handler);
instance[name] = null;
}
2018-10-23 01:05:09 +03:00
}
function onRefreshProgress(e, apiClient, info) {
const indicator = this;
if (!indicator.itemId) {
indicator.itemId = dom.parentWithAttribute(indicator, 'data-id').getAttribute('data-id');
}
if (info.ItemId === indicator.itemId) {
const progress = parseFloat(info.Progress);
if (progress && progress < 100) {
this.classList.remove('hide');
} else {
this.classList.add('hide');
}
this.setAttribute('data-progress', progress);
2018-10-23 01:05:09 +03:00
}
}
2020-07-17 10:33:31 +02:00
const EmbyItemRefreshIndicatorPrototype = Object.create(EmbyProgressRing);
EmbyItemRefreshIndicatorPrototype.createdCallback = function () {
// base method
if (EmbyProgressRing.createdCallback) {
EmbyProgressRing.createdCallback.call(this);
}
addNotificationEvent(this, 'RefreshProgress', onRefreshProgress);
};
EmbyItemRefreshIndicatorPrototype.attachedCallback = function () {
// base method
if (EmbyProgressRing.attachedCallback) {
EmbyProgressRing.attachedCallback.call(this);
}
};
EmbyItemRefreshIndicatorPrototype.detachedCallback = function () {
// base method
if (EmbyProgressRing.detachedCallback) {
EmbyProgressRing.detachedCallback.call(this);
}
removeNotificationEvent(this, 'RefreshProgress');
this.itemId = null;
};
document.registerElement('emby-itemrefreshindicator', {
2018-10-23 01:05:09 +03:00
prototype: EmbyItemRefreshIndicatorPrototype,
extends: 'div'
});
/* eslint-enable indent */