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-button/emby-button.js

76 lines
2.2 KiB
JavaScript
Raw Normal View History

import browser from 'browser';
import dom from 'dom';
import layoutManager from 'layoutManager';
import shell from 'shell';
import appRouter from 'appRouter';
import appHost from 'apphost';
import 'css!./emby-button';
import 'registerElement';
2020-07-17 17:02:49 +01:00
const EmbyButtonPrototype = Object.create(HTMLButtonElement.prototype);
const EmbyLinkButtonPrototype = Object.create(HTMLAnchorElement.prototype);
2020-07-17 17:02:49 +01:00
function onAnchorClick(e) {
const href = this.getAttribute('href') || '';
if (href !== '#') {
if (this.getAttribute('target')) {
if (!appHost.supports('targetblank')) {
e.preventDefault();
shell.openUrl(href);
}
} else {
2020-07-17 17:02:49 +01:00
appRouter.handleAnchorClick(e);
}
2020-07-17 17:02:49 +01:00
} else {
e.preventDefault();
2018-10-23 01:05:09 +03:00
}
2020-07-17 17:02:49 +01:00
}
2020-07-17 17:02:49 +01:00
EmbyButtonPrototype.createdCallback = function () {
if (this.classList.contains('emby-button')) {
return;
}
2020-07-17 17:02:49 +01:00
this.classList.add('emby-button');
// TODO replace all instances of element-showfocus with this method
if (layoutManager.tv) {
// handles all special css for tv layout
// this method utilizes class chaining
this.classList.add('show-focus');
}
};
2020-07-17 17:02:49 +01:00
EmbyButtonPrototype.attachedCallback = function () {
if (this.tagName === 'A') {
dom.removeEventListener(this, 'click', onAnchorClick, {});
dom.addEventListener(this, 'click', onAnchorClick, {});
2020-07-17 17:02:49 +01:00
if (this.getAttribute('data-autohide') === 'true') {
if (appHost.supports('externallinks')) {
this.classList.remove('hide');
} else {
this.classList.add('hide');
}
}
2020-07-17 17:02:49 +01:00
}
};
2020-07-17 17:02:49 +01:00
EmbyButtonPrototype.detachedCallback = function () {
dom.removeEventListener(this, 'click', onAnchorClick, {});
};
2020-07-17 17:02:49 +01:00
EmbyLinkButtonPrototype.createdCallback = EmbyButtonPrototype.createdCallback;
EmbyLinkButtonPrototype.attachedCallback = EmbyButtonPrototype.attachedCallback;
2020-07-17 17:02:49 +01:00
document.registerElement('emby-button', {
prototype: EmbyButtonPrototype,
extends: 'button'
});
2020-07-17 17:02:49 +01:00
document.registerElement('emby-linkbutton', {
prototype: EmbyLinkButtonPrototype,
extends: 'a'
});
2020-07-17 17:02:49 +01:00
export default EmbyButtonPrototype;