1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Revert emby-button and emby-tabs changes

This commit is contained in:
Bill Thornton 2020-09-08 16:08:09 -04:00 committed by vitorsemeano
parent 97699d513b
commit 85acdb3868
2 changed files with 200 additions and 208 deletions

View file

@ -1,3 +1,4 @@
import 'webcomponents.js/webcomponents-lite';
import { removeEventListener, addEventListener } from '../../scripts/dom'; import { removeEventListener, addEventListener } from '../../scripts/dom';
import layoutManager from '../../components/layoutManager'; import layoutManager from '../../components/layoutManager';
import shell from '../../scripts/shell'; import shell from '../../scripts/shell';
@ -5,61 +6,8 @@ import { appRouter } from '../../components/appRouter';
import { appHost } from '../../components/apphost'; import { appHost } from '../../components/apphost';
import './emby-button.css'; import './emby-button.css';
class EmbyButton extends HTMLButtonElement { const EmbyButtonPrototype = Object.create(HTMLButtonElement.prototype);
createdCallback() { const EmbyLinkButtonPrototype = Object.create(HTMLAnchorElement.prototype);
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');
}
}
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, {});
}
}
function onAnchorClick(e) { function onAnchorClick(e) {
const href = this.getAttribute('href') || ''; const href = this.getAttribute('href') || '';
@ -77,8 +25,50 @@ function onAnchorClick(e) {
} }
} }
customElements.define('emby-button', EmbyButton, { extends: 'button' }); EmbyButtonPrototype.createdCallback = function () {
if (this.classList.contains('emby-button')) {
return;
}
customElements.define('emby-linkbutton', EmbyLinkButton, { extends: 'a' }); 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');
}
};
export default EmbyButton; 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'
});
document.registerElement('emby-linkbutton', {
prototype: EmbyLinkButtonPrototype,
extends: 'a'
});
export default EmbyButtonPrototype;

View file

@ -1,12 +1,13 @@
import 'webcomponents.js/webcomponents-lite';
import dom from '../../scripts/dom'; import dom from '../../scripts/dom';
import scroller from '../../libraries/scroller'; import scroller from '../../libraries/scroller';
import browser from '../../scripts/browser'; import browser from '../../scripts/browser';
import focusManager from '../../components/focusManager'; import focusManager from '../../components/focusManager';
import 'webcomponents.js/webcomponents-lite';
import './emby-tabs.css'; import './emby-tabs.css';
import '../../assets/css/scrollstyles.css'; import '../../assets/css/scrollstyles.css';
/* eslint-disable indent */ /* eslint-disable indent */
const EmbyTabs = Object.create(HTMLDivElement.prototype);
const buttonClass = 'emby-tab-button'; const buttonClass = 'emby-tab-button';
const activeButtonClass = buttonClass + '-active'; const activeButtonClass = buttonClass + '-active';
@ -143,8 +144,7 @@ import '../../assets/css/scrollstyles.css';
} }
} }
class EmbyTabs extends HTMLDivElement { EmbyTabs.createdCallback = function () {
createdCallback() {
if (this.classList.contains('emby-tabs')) { if (this.classList.contains('emby-tabs')) {
return; return;
} }
@ -156,28 +156,28 @@ import '../../assets/css/scrollstyles.css';
}); });
dom.addEventListener(this, 'focusout', onFocusOut); dom.addEventListener(this, 'focusout', onFocusOut);
} };
focus() { EmbyTabs.focus = function onFocusIn() {
const selected = this.querySelector('.' + activeButtonClass); const selectedTab = this.querySelector('.' + activeButtonClass);
const lastFocused = this.querySelector('.lastFocused');
if (this.lastFocused) { if (lastFocused) {
focusManager.focus(this.lastFocused); focusManager.focus(lastFocused);
} else if (this.selectedTab) { } else if (selectedTab) {
focusManager.focus(this.selectedTab); focusManager.focus(selectedTab);
} else { } else {
focusManager.autoFocus(this); focusManager.autoFocus(this);
} }
} };
refresh() { EmbyTabs.refresh = function () {
if (this.scroller) { if (this.scroller) {
this.scroller.reload(); this.scroller.reload();
} }
} };
attachedCallback() { EmbyTabs.attachedCallback = function () {
console.warn(this);
initScroller(this); initScroller(this);
const current = this.querySelector('.' + activeButtonClass); const current = this.querySelector('.' + activeButtonClass);
@ -199,9 +199,9 @@ import '../../assets/css/scrollstyles.css';
this.readyFired = true; this.readyFired = true;
this.dispatchEvent(new CustomEvent('ready', {})); this.dispatchEvent(new CustomEvent('ready', {}));
} }
} };
detachedCallback() { EmbyTabs.detachedCallback = function () {
if (this.scroller) { if (this.scroller) {
this.scroller.destroy(); this.scroller.destroy();
this.scroller = null; this.scroller = null;
@ -210,13 +210,13 @@ import '../../assets/css/scrollstyles.css';
dom.removeEventListener(this, 'click', onClick, { dom.removeEventListener(this, 'click', onClick, {
passive: true passive: true
}); });
} };
getSelectedTabButton(elem) { function getSelectedTabButton(elem) {
return elem.querySelector('.' + activeButtonClass); return elem.querySelector('.' + activeButtonClass);
} }
selectedIndex(selected, triggerEvent) { EmbyTabs.selectedIndex = function (selected, triggerEvent) {
const tabs = this; const tabs = this;
if (selected == null) { if (selected == null) {
@ -249,9 +249,9 @@ import '../../assets/css/scrollstyles.css';
target: tabButtons[selected] target: tabButtons[selected]
}); });
} }
} };
getSibling(elem, method) { function getSibling(elem, method) {
let sibling = elem[method]; let sibling = elem[method];
while (sibling) { while (sibling) {
@ -267,37 +267,37 @@ import '../../assets/css/scrollstyles.css';
return null; return null;
} }
selectNext() { EmbyTabs.selectNext = function () {
const current = this.getSelectedTabButton(this); const current = getSelectedTabButton(this);
const sibling = this.getSibling(current, 'nextSibling'); const sibling = getSibling(current, 'nextSibling');
if (sibling) { if (sibling) {
onClick.call(this, { onClick.call(this, {
target: sibling target: sibling
}); });
} }
} };
selectPrevious() { EmbyTabs.selectPrevious = function () {
const current = this.getSelectedTabButton(this); const current = getSelectedTabButton(this);
const sibling = this.getSibling(current, 'previousSibling'); const sibling = getSibling(current, 'previousSibling');
if (sibling) { if (sibling) {
onClick.call(this, { onClick.call(this, {
target: sibling target: sibling
}); });
} }
} };
triggerBeforeTabChange(selected) { EmbyTabs.triggerBeforeTabChange = function (selected) {
const tabs = this; const tabs = this;
triggerBeforeTabChange(tabs, tabs.selectedIndex()); triggerBeforeTabChange(tabs, tabs.selectedIndex());
} };
triggerTabChange(selected) { EmbyTabs.triggerTabChange = function (selected) {
const tabs = this; const tabs = this;
tabs.dispatchEvent(new CustomEvent('tabchange', { tabs.dispatchEvent(new CustomEvent('tabchange', {
@ -305,9 +305,9 @@ import '../../assets/css/scrollstyles.css';
selectedTabIndex: tabs.selectedIndex() selectedTabIndex: tabs.selectedIndex()
} }
})); }));
} };
setTabEnabled(index, enabled) { EmbyTabs.setTabEnabled = function (index, enabled) {
const btn = this.querySelector('.emby-tab-button[data-index="' + index + '"]'); const btn = this.querySelector('.emby-tab-button[data-index="' + index + '"]');
if (enabled) { if (enabled) {
@ -315,9 +315,11 @@ import '../../assets/css/scrollstyles.css';
} else { } else {
btn.classList.remove('add'); btn.classList.remove('add');
} }
} };
}
customElements.define('emby-tabs', EmbyTabs, { extends: 'div' }); document.registerElement('emby-tabs', {
prototype: EmbyTabs,
extends: 'div'
});
/* eslint-enable indent */ /* eslint-enable indent */