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

update variable declerations

This commit is contained in:
Cameron 2020-07-11 09:52:35 +01:00
parent 5a1e01c650
commit e31cae5af8
3 changed files with 54 additions and 57 deletions

View file

@ -8,14 +8,14 @@ import EmbyButtonPrototype from 'emby-button';
function addNotificationEvent(instance, name, handler) { function addNotificationEvent(instance, name, handler) {
var localHandler = handler.bind(instance); const localHandler = handler.bind(instance);
events.on(serverNotifications, name, localHandler); events.on(serverNotifications, name, localHandler);
instance[name] = localHandler; instance[name] = localHandler;
} }
function removeNotificationEvent(instance, name) { function removeNotificationEvent(instance, name) {
var handler = instance[name]; const handler = instance[name];
if (handler) { if (handler) {
events.off(serverNotifications, name, handler); events.off(serverNotifications, name, handler);
instance[name] = null; instance[name] = null;
@ -29,13 +29,13 @@ import EmbyButtonPrototype from 'emby-button';
function onClick(e) { function onClick(e) {
var button = this; const button = this;
var id = button.getAttribute('data-id'); const id = button.getAttribute('data-id');
var serverId = button.getAttribute('data-serverid'); const serverId = button.getAttribute('data-serverid');
var apiClient = connectionManager.getApiClient(serverId); const apiClient = connectionManager.getApiClient(serverId);
var likes = this.getAttribute('data-likes'); let likes = this.getAttribute('data-likes');
var isFavorite = this.getAttribute('data-isfavorite') === 'true'; const isFavorite = this.getAttribute('data-isfavorite') === 'true';
if (likes === 'true') { if (likes === 'true') {
likes = true; likes = true;
} else if (likes === 'false') { } else if (likes === 'false') {
@ -52,7 +52,7 @@ import EmbyButtonPrototype from 'emby-button';
function onUserDataChanged(e, apiClient, userData) { function onUserDataChanged(e, apiClient, userData) {
var button = this; const button = this;
if (userData.ItemId === button.getAttribute('data-id')) { if (userData.ItemId === button.getAttribute('data-id')) {
@ -62,7 +62,7 @@ import EmbyButtonPrototype from 'emby-button';
function setState(button, likes, isFavorite, updateAttribute) { function setState(button, likes, isFavorite, updateAttribute) {
var icon = button.querySelector('.material-icons'); const icon = button.querySelector('.material-icons');
if (isFavorite) { if (isFavorite) {
@ -111,7 +111,7 @@ import EmbyButtonPrototype from 'emby-button';
function setTitle(button) { function setTitle(button) {
button.title = globalize.translate('Favorite'); button.title = globalize.translate('Favorite');
var text = button.querySelector('.button-text'); const text = button.querySelector('.button-text');
if (text) { if (text) {
text.innerHTML = button.title; text.innerHTML = button.title;
} }
@ -131,7 +131,7 @@ import EmbyButtonPrototype from 'emby-button';
addNotificationEvent(button, 'UserDataChanged', onUserDataChanged); addNotificationEvent(button, 'UserDataChanged', onUserDataChanged);
} }
var EmbyRatingButtonPrototype = Object.create(EmbyButtonPrototype); const EmbyRatingButtonPrototype = Object.create(EmbyButtonPrototype);
EmbyRatingButtonPrototype.createdCallback = function () { EmbyRatingButtonPrototype.createdCallback = function () {
@ -148,12 +148,12 @@ import EmbyButtonPrototype from 'emby-button';
EmbyButtonPrototype.attachedCallback.call(this); EmbyButtonPrototype.attachedCallback.call(this);
} }
var itemId = this.getAttribute('data-id'); const itemId = this.getAttribute('data-id');
var serverId = this.getAttribute('data-serverid'); const serverId = this.getAttribute('data-serverid');
if (itemId && serverId) { if (itemId && serverId) {
var likes = this.getAttribute('data-likes'); let likes = this.getAttribute('data-likes');
var isFavorite = this.getAttribute('data-isfavorite') === 'true'; const isFavorite = this.getAttribute('data-isfavorite') === 'true';
if (likes === 'true') { if (likes === 'true') {
likes = true; likes = true;
} else if (likes === 'false') { } else if (likes === 'false') {
@ -186,7 +186,7 @@ import EmbyButtonPrototype from 'emby-button';
this.setAttribute('data-id', item.Id); this.setAttribute('data-id', item.Id);
this.setAttribute('data-serverid', item.ServerId); this.setAttribute('data-serverid', item.ServerId);
var userData = item.UserData || {}; const userData = item.UserData || {};
setState(this, userData.Likes, userData.IsFavorite); setState(this, userData.Likes, userData.IsFavorite);
bindEvents(this); bindEvents(this);

View file

@ -6,13 +6,13 @@ import 'paper-icon-button-light';
/* eslint-disable indent */ /* eslint-disable indent */
var EmbyScrollButtonsPrototype = Object.create(HTMLDivElement.prototype); const EmbyScrollButtonsPrototype = Object.create(HTMLDivElement.prototype);
EmbyScrollButtonsPrototype.createdCallback = function () {}; EmbyScrollButtonsPrototype.createdCallback = function () {};
function getScrollButtonHtml(direction) { function getScrollButtonHtml(direction) {
var html = ''; let html = '';
var icon = direction === 'left' ? 'chevron_left' : 'chevron_right'; const icon = direction === 'left' ? 'chevron_left' : 'chevron_right';
html += '<button type="button" is="paper-icon-button-light" data-ripple="false" data-direction="' + direction + '" class="emby-scrollbuttons-button">'; html += '<button type="button" is="paper-icon-button-light" data-ripple="false" data-direction="' + direction + '" class="emby-scrollbuttons-button">';
html += '<span class="material-icons ' + icon + '"></span>'; html += '<span class="material-icons ' + icon + '"></span>';
@ -50,7 +50,7 @@ import 'paper-icon-button-light';
scrollButtons.scrollButtonsLeft.disabled = true; scrollButtons.scrollButtonsLeft.disabled = true;
} }
var scrollPosEnd = scrollPos + scrollSize; const scrollPosEnd = scrollPos + scrollSize;
if (scrollWidth > 0 && scrollPosEnd >= scrollWidth) { if (scrollWidth > 0 && scrollPosEnd >= scrollWidth) {
scrollButtons.scrollButtonsRight.disabled = true; scrollButtons.scrollButtonsRight.disabled = true;
} else { } else {
@ -59,18 +59,18 @@ import 'paper-icon-button-light';
} }
function onScroll(e) { function onScroll(e) {
var scrollButtons = this; const scrollButtons = this;
var scroller = this.scroller; const scroller = this.scroller;
var scrollSize = getScrollSize(scroller); const scrollSize = getScrollSize(scroller);
var scrollPos = getScrollPosition(scroller); const scrollPos = getScrollPosition(scroller);
var scrollWidth = getScrollWidth(scroller); const scrollWidth = getScrollWidth(scroller);
updateScrollButtons(scrollButtons, scrollSize, scrollPos, scrollWidth); updateScrollButtons(scrollButtons, scrollSize, scrollPos, scrollWidth);
} }
function getStyleValue(style, name) { function getStyleValue(style, name) {
var value = style.getPropertyValue(name); let value = style.getPropertyValue(name);
if (!value) { if (!value) {
return 0; return 0;
} }
@ -89,20 +89,20 @@ import 'paper-icon-button-light';
} }
function getScrollSize(elem) { function getScrollSize(elem) {
var scrollSize = elem.offsetWidth; let scrollSize = elem.offsetWidth;
var style = window.getComputedStyle(elem, null); let style = window.getComputedStyle(elem, null);
var paddingLeft = getStyleValue(style, 'padding-left'); let paddingLeft = getStyleValue(style, 'padding-left');
if (paddingLeft) { if (paddingLeft) {
scrollSize -= paddingLeft; scrollSize -= paddingLeft;
} }
var paddingRight = getStyleValue(style, 'padding-right'); let paddingRight = getStyleValue(style, 'padding-right');
if (paddingRight) { if (paddingRight) {
scrollSize -= paddingRight; scrollSize -= paddingRight;
} }
var slider = elem.getScrollSlider(); const slider = elem.getScrollSlider();
style = window.getComputedStyle(slider, null); style = window.getComputedStyle(slider, null);
paddingLeft = getStyleValue(style, 'padding-left'); paddingLeft = getStyleValue(style, 'padding-left');
@ -119,14 +119,14 @@ import 'paper-icon-button-light';
} }
function onScrollButtonClick(e) { function onScrollButtonClick(e) {
var scroller = this.parentNode.nextSibling; let scroller = this.parentNode.nextSibling;
var direction = this.getAttribute('data-direction'); const direction = this.getAttribute('data-direction');
var scrollSize = getScrollSize(scroller); const scrollSize = getScrollSize(scroller);
var scrollPos = getScrollPosition(scroller); const scrollPos = getScrollPosition(scroller);
var scrollWidth = getScrollWidth(scroller); const scrollWidth = getScrollWidth(scroller);
var newPos; let newPos;
if (direction === 'left') { if (direction === 'left') {
newPos = Math.max(0, scrollPos - scrollSize); newPos = Math.max(0, scrollPos - scrollSize);
} else { } else {
@ -137,21 +137,21 @@ import 'paper-icon-button-light';
} }
EmbyScrollButtonsPrototype.attachedCallback = function () { EmbyScrollButtonsPrototype.attachedCallback = function () {
var scroller = this.nextSibling; const scroller = this.nextSibling;
this.scroller = scroller; this.scroller = scroller;
var parent = this.parentNode; const parent = this.parentNode;
parent.classList.add('emby-scroller-container'); parent.classList.add('emby-scroller-container');
this.innerHTML = getScrollButtonHtml('left') + getScrollButtonHtml('right'); this.innerHTML = getScrollButtonHtml('left') + getScrollButtonHtml('right');
var buttons = this.querySelectorAll('.emby-scrollbuttons-button'); const buttons = this.querySelectorAll('.emby-scrollbuttons-button');
buttons[0].addEventListener('click', onScrollButtonClick); buttons[0].addEventListener('click', onScrollButtonClick);
buttons[1].addEventListener('click', onScrollButtonClick); buttons[1].addEventListener('click', onScrollButtonClick);
this.scrollButtonsLeft = buttons[0]; this.scrollButtonsLeft = buttons[0];
this.scrollButtonsRight = buttons[1]; this.scrollButtonsRight = buttons[1];
var scrollHandler = onScroll.bind(this); const scrollHandler = onScroll.bind(this);
this.scrollHandler = scrollHandler; this.scrollHandler = scrollHandler;
scroller.addScrollEventListener(scrollHandler, { scroller.addScrollEventListener(scrollHandler, {
capture: false, capture: false,
@ -160,10 +160,10 @@ import 'paper-icon-button-light';
}; };
EmbyScrollButtonsPrototype.detachedCallback = function () { EmbyScrollButtonsPrototype.detachedCallback = function () {
var parent = this.scroller; const parent = this.scroller;
this.scroller = null; this.scroller = null;
var scrollHandler = this.scrollHandler; let scrollHandler = this.scrollHandler;
if (parent && scrollHandler) { if (parent && scrollHandler) {
parent.removeScrollEventListener(scrollHandler, { parent.removeScrollEventListener(scrollHandler, {
capture: false, capture: false,

View file

@ -6,7 +6,7 @@ import 'registerElement';
/* eslint-disable indent */ /* eslint-disable indent */
var EmbySelectPrototype = Object.create(HTMLSelectElement.prototype); const EmbySelectPrototype = Object.create(HTMLSelectElement.prototype);
function enableNativeMenu() { function enableNativeMenu() {
@ -32,7 +32,7 @@ import 'registerElement';
} }
function triggerChange(select) { function triggerChange(select) {
var evt = document.createEvent('HTMLEvents'); const evt = document.createEvent('HTMLEvents');
evt.initEvent('change', false, true); evt.initEvent('change', false, true);
select.dispatchEvent(evt); select.dispatchEvent(evt);
} }
@ -44,8 +44,8 @@ import 'registerElement';
function showActionSheet(select) { function showActionSheet(select) {
var labelElem = getLabel(select); const labelElem = getLabel(select);
var title = labelElem ? (labelElem.textContent || labelElem.innerText) : null; const title = labelElem ? (labelElem.textContent || labelElem.innerText) : null;
actionsheet.show({ actionsheet.show({
items: select.options, items: select.options,
@ -59,7 +59,7 @@ import 'registerElement';
} }
function getLabel(select) { function getLabel(select) {
var elem = select.previousSibling; let elem = select.previousSibling;
while (elem && elem.tagName !== 'LABEL') { while (elem && elem.tagName !== 'LABEL') {
elem = elem.previousSibling; elem = elem.previousSibling;
} }
@ -67,21 +67,20 @@ import 'registerElement';
} }
function onFocus(e) { function onFocus(e) {
var label = getLabel(this); const label = getLabel(this);
if (label) { if (label) {
label.classList.add('selectLabelFocused'); label.classList.add('selectLabelFocused');
} }
} }
function onBlur(e) { function onBlur(e) {
var label = getLabel(this); const label = getLabel(this);
if (label) { if (label) {
label.classList.remove('selectLabelFocused'); label.classList.remove('selectLabelFocused');
} }
} }
function onMouseDown(e) { function onMouseDown(e) {
// e.button=0 for primary (left) mouse button click // e.button=0 for primary (left) mouse button click
if (!e.button && !enableNativeMenu()) { if (!e.button && !enableNativeMenu()) {
e.preventDefault(); e.preventDefault();
@ -90,9 +89,7 @@ import 'registerElement';
} }
function onKeyDown(e) { function onKeyDown(e) {
switch (e.keyCode) { switch (e.keyCode) {
case 13: case 13:
if (!enableNativeMenu()) { if (!enableNativeMenu()) {
e.preventDefault(); e.preventDefault();
@ -112,7 +109,7 @@ import 'registerElement';
} }
} }
var inputId = 0; let inputId = 0;
EmbySelectPrototype.createdCallback = function () { EmbySelectPrototype.createdCallback = function () {
@ -142,7 +139,7 @@ import 'registerElement';
this.classList.add('emby-select'); this.classList.add('emby-select');
var label = this.ownerDocument.createElement('label'); const label = this.ownerDocument.createElement('label');
label.innerHTML = this.getAttribute('label') || ''; label.innerHTML = this.getAttribute('label') || '';
label.classList.add('selectLabel'); label.classList.add('selectLabel');
label.htmlFor = this.id; label.htmlFor = this.id;
@ -155,7 +152,7 @@ import 'registerElement';
EmbySelectPrototype.setLabel = function (text) { EmbySelectPrototype.setLabel = function (text) {
var label = this.parentNode.querySelector('label'); const label = this.parentNode.querySelector('label');
label.innerHTML = text; label.innerHTML = text;
}; };