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

85 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import { removeEventListener, addEventListener } from '../../scripts/dom';
import layoutManager from '../../components/layoutManager';
import shell from '../../scripts/shell';
2020-08-16 20:24:45 +02:00
import { appRouter } from '../../components/appRouter';
import { appHost } from '../../components/apphost';
2020-08-14 08:46:34 +02:00
import './emby-button.css';
2020-08-16 20:24:45 +02:00
class EmbyButton extends HTMLButtonElement {
createdCallback() {
if (this.classList.contains('emby-button')) {
return;
}
2020-09-08 15:43:19 -04:00
this.classList.add('emby-button');
2020-08-16 20:24:45 +02:00
// 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');
}
}
attachedCallback() {
if (this.tagName === 'A') {
removeEventListener(this, 'click', onAnchorClick, {});
addEventListener(this, 'click', onAnchorClick, {});
if (this.getAttribute('data-autohide') === 'true') {
if (appHost.supports('externallinks')) {
this.classList.remove('hide');
} else {
this.classList.add('hide');
}
}
}
}
detachedCallback() {
removeEventListener(this, 'click', onAnchorClick, {});
}
}
class EmbyLinkButton extends HTMLAnchorElement {
attachedCallback() {
if (this.tagName === 'A') {
removeEventListener(this, 'click', onAnchorClick, {});
addEventListener(this, 'click', onAnchorClick, {});
if (this.getAttribute('data-autohide') === 'true') {
if (appHost.supports('externallinks')) {
this.classList.remove('hide');
} else {
this.classList.add('hide');
}
}
}
}
detachedCallback() {
removeEventListener(this, 'click', onAnchorClick, {});
}
}
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-08-16 20:24:45 +02:00
customElements.define('emby-button', EmbyButton, { extends: 'button' });
2020-08-16 20:24:45 +02:00
customElements.define('emby-linkbutton', EmbyLinkButton, { extends: 'a' });
2020-08-16 20:24:45 +02:00
export default EmbyButton;