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

80 lines
2.4 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';
/* eslint-disable indent */
const EmbyButtonPrototype = Object.create(HTMLButtonElement.prototype);
const EmbyLinkButtonPrototype = Object.create(HTMLAnchorElement.prototype);
2018-10-23 01:05:09 +03:00
function onAnchorClick(e) {
const href = this.getAttribute('href') || '';
if (href !== '#') {
if (this.getAttribute('target')) {
2019-03-19 17:03:11 -07:00
if (!appHost.supports('targetblank')) {
e.preventDefault();
shell.openUrl(href);
}
} else {
appRouter.handleAnchorClick(e);
}
} else {
e.preventDefault();
}
2018-10-23 01:05:09 +03:00
}
EmbyButtonPrototype.createdCallback = function () {
if (this.classList.contains('emby-button')) {
return;
}
this.classList.add('emby-button');
2019-09-11 15:35:37 -07:00
// TODO replace all instances of element-showfocus with this method
if (layoutManager.tv) {
2019-09-06 22:33:15 -07:00
// handles all special css for tv layout
2019-09-11 15:35:37 -07:00
// this method utilizes class chaining
2019-09-06 22:33:15 -07:00
this.classList.add('show-focus');
}
};
EmbyButtonPrototype.attachedCallback = function () {
if (this.tagName === 'A') {
2019-09-06 22:33:15 -07:00
dom.removeEventListener(this, 'click', onAnchorClick, {});
dom.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 () {
2019-09-06 22:33:15 -07:00
dom.removeEventListener(this, 'click', onAnchorClick, {});
};
EmbyLinkButtonPrototype.createdCallback = EmbyButtonPrototype.createdCallback;
EmbyLinkButtonPrototype.attachedCallback = EmbyButtonPrototype.attachedCallback;
document.registerElement('emby-button', {
2018-10-23 01:05:09 +03:00
prototype: EmbyButtonPrototype,
extends: 'button'
});
document.registerElement('emby-linkbutton', {
2018-10-23 01:05:09 +03:00
prototype: EmbyLinkButtonPrototype,
extends: 'a'
});
export default EmbyButtonPrototype;
/* eslint-enable indent */