2020-09-08 16:08:09 -04:00
|
|
|
import 'webcomponents.js/webcomponents-lite';
|
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';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-09-08 16:08:09 -04:00
|
|
|
const EmbyButtonPrototype = Object.create(HTMLButtonElement.prototype);
|
|
|
|
const EmbyLinkButtonPrototype = Object.create(HTMLAnchorElement.prototype);
|
2020-07-15 11:41:59 +01:00
|
|
|
|
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);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-17 17:02:49 +01:00
|
|
|
appRouter.handleAnchorClick(e);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
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
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-09-08 16:08:09 -04:00
|
|
|
EmbyButtonPrototype.createdCallback = function () {
|
|
|
|
if (this.classList.contains('emby-button')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
EmbyButtonPrototype.attachedCallback = function () {
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
EmbyButtonPrototype.detachedCallback = function () {
|
|
|
|
removeEventListener(this, 'click', onAnchorClick, {});
|
|
|
|
};
|
|
|
|
|
|
|
|
EmbyLinkButtonPrototype.createdCallback = EmbyButtonPrototype.createdCallback;
|
|
|
|
EmbyLinkButtonPrototype.attachedCallback = EmbyButtonPrototype.attachedCallback;
|
|
|
|
|
|
|
|
document.registerElement('emby-button', {
|
|
|
|
prototype: EmbyButtonPrototype,
|
|
|
|
extends: 'button'
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-09-08 16:08:09 -04:00
|
|
|
document.registerElement('emby-linkbutton', {
|
|
|
|
prototype: EmbyLinkButtonPrototype,
|
|
|
|
extends: 'a'
|
|
|
|
});
|
2020-07-15 11:41:59 +01:00
|
|
|
|
2020-09-08 16:08:09 -04:00
|
|
|
export default EmbyButtonPrototype;
|