diff --git a/package.json b/package.json
index 00381203b..bba1956f2 100644
--- a/package.json
+++ b/package.json
@@ -63,7 +63,7 @@
"fast-text-encoding": "^1.0.3",
"flv.js": "^1.5.0",
"headroom.js": "^0.11.0",
- "hls.js": "^0.14.7",
+ "hls.js": "^0.14.8",
"howler": "^2.2.0",
"intersection-observer": "^0.11.0",
"jellyfin-apiclient": "^1.4.1",
@@ -80,7 +80,7 @@
"sortablejs": "^1.10.2",
"swiper": "^5.4.5",
"webcomponents.js": "^0.7.24",
- "whatwg-fetch": "^3.3.1"
+ "whatwg-fetch": "^3.4.0"
},
"babel": {
"presets": [
@@ -125,6 +125,8 @@
"src/components/itemHelper.js",
"src/components/itemidentifier/itemidentifier.js",
"src/components/itemMediaInfo/itemMediaInfo.js",
+ "src/components/itemsrefresher.js",
+ "src/components/layoutManager.js",
"src/components/lazyLoader/lazyLoaderIntersectionObserver.js",
"src/components/libraryoptionseditor/libraryoptionseditor.js",
"src/components/listview/listview.js",
@@ -158,6 +160,8 @@
"src/components/refreshdialog/refreshdialog.js",
"src/components/sanatizefilename.js",
"src/components/scrollManager.js",
+ "src/components/slideshow/slideshow.js",
+ "src/components/sortmenu/sortmenu.js",
"src/plugins/htmlVideoPlayer/plugin.js",
"src/plugins/logoScreensaver/plugin.js",
"src/plugins/playAccessValidation/plugin.js",
@@ -165,6 +169,8 @@
"src/components/search/searchresults.js",
"src/components/settingshelper.js",
"src/components/shortcuts.js",
+ "src/components/subtitleeditor/subtitleeditor.js",
+ "src/components/subtitlesync/subtitlesync.js",
"src/components/subtitlesettings/subtitleappearancehelper.js",
"src/components/subtitlesettings/subtitlesettings.js",
"src/components/syncPlay/groupSelectionMenu.js",
@@ -218,6 +224,7 @@
"src/controllers/dashboard/users/userparentalcontrol.js",
"src/controllers/dashboard/users/userpasswordpage.js",
"src/controllers/dashboard/users/userprofilespage.js",
+ "src/controllers/list.js",
"src/controllers/edititemmetadata.js",
"src/controllers/favorites.js",
"src/controllers/hometab.js",
@@ -278,6 +285,7 @@
"src/elements/emby-tabs/emby-tabs.js",
"src/elements/emby-textarea/emby-textarea.js",
"src/elements/emby-toggle/emby-toggle.js",
+ "src/libraries/screensavermanager.js",
"src/libraries/navdrawer/navdrawer.js",
"src/libraries/scroller.js",
"src/plugins/backdropScreensaver/plugin.js",
diff --git a/src/components/filtermenu/filtermenu.js b/src/components/filtermenu/filtermenu.js
index 37fb66e0d..df74dc2a1 100644
--- a/src/components/filtermenu/filtermenu.js
+++ b/src/components/filtermenu/filtermenu.js
@@ -2,6 +2,8 @@ define(['require', 'dom', 'focusManager', 'dialogHelper', 'loading', 'apphost',
'use strict';
focusManager = focusManager.default || focusManager;
+ layoutManager = layoutManager.default || layoutManager;
+
function onSubmit(e) {
e.preventDefault();
return false;
diff --git a/src/components/guide/guide-settings.js b/src/components/guide/guide-settings.js
index a644c9c9b..b3133ec27 100644
--- a/src/components/guide/guide-settings.js
+++ b/src/components/guide/guide-settings.js
@@ -1,6 +1,7 @@
define(['dialogHelper', 'globalize', 'userSettings', 'layoutManager', 'connectionManager', 'require', 'loading', 'scrollHelper', 'emby-checkbox', 'emby-radio', 'css!./../formdialog', 'material-icons'], function (dialogHelper, globalize, userSettings, layoutManager, connectionManager, require, loading, scrollHelper) {
'use strict';
+ layoutManager = layoutManager.default || layoutManager;
scrollHelper = scrollHelper.default || scrollHelper;
function saveCategories(context, options) {
diff --git a/src/components/guide/guide.js b/src/components/guide/guide.js
index 05fa2b608..c8fd8021e 100644
--- a/src/components/guide/guide.js
+++ b/src/components/guide/guide.js
@@ -4,6 +4,7 @@ define(['require', 'inputManager', 'browser', 'globalize', 'connectionManager',
playbackManager = playbackManager.default || playbackManager;
browser = browser.default || browser;
loading = loading.default || loading;
+ layoutManager = layoutManager.default || layoutManager;
focusManager = focusManager.default || focusManager;
scrollHelper = scrollHelper.default || scrollHelper;
serverNotifications = serverNotifications.default || serverNotifications;
diff --git a/src/components/itemsrefresher.js b/src/components/itemsrefresher.js
index 5ce9a3b6e..3883e6e49 100644
--- a/src/components/itemsrefresher.js
+++ b/src/components/itemsrefresher.js
@@ -1,131 +1,130 @@
-define(['playbackManager', 'serverNotifications', 'events'], function (playbackManager, serverNotifications, events) {
- 'use strict';
+import playbackManager from 'playbackManager';
+import serverNotifications from 'serverNotifications';
+import events from 'events';
- serverNotifications = serverNotifications.default || serverNotifications;
- playbackManager = playbackManager.default || playbackManager;
+function onUserDataChanged(e, apiClient, userData) {
+ const instance = this;
- function onUserDataChanged(e, apiClient, userData) {
- var instance = this;
-
- var eventsToMonitor = getEventsToMonitor(instance);
-
- // TODO: Check user data change reason?
- if (eventsToMonitor.indexOf('markfavorite') !== -1) {
- instance.notifyRefreshNeeded();
- } else if (eventsToMonitor.indexOf('markplayed') !== -1) {
- instance.notifyRefreshNeeded();
- }
- }
-
- function getEventsToMonitor(instance) {
- var options = instance.options;
- var monitor = options ? options.monitorEvents : null;
- if (monitor) {
- return monitor.split(',');
- }
-
- return [];
- }
-
- function onTimerCreated(e, apiClient, data) {
- var instance = this;
-
- if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
- instance.notifyRefreshNeeded();
- return;
- }
- }
-
- function onSeriesTimerCreated(e, apiClient, data) {
- var instance = this;
- if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
- instance.notifyRefreshNeeded();
- return;
- }
- }
-
- function onTimerCancelled(e, apiClient, data) {
- var instance = this;
-
- if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
- instance.notifyRefreshNeeded();
- return;
- }
- }
-
- function onSeriesTimerCancelled(e, apiClient, data) {
- var instance = this;
- if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
- instance.notifyRefreshNeeded();
- return;
- }
- }
-
- function onLibraryChanged(e, apiClient, data) {
- var instance = this;
- var eventsToMonitor = getEventsToMonitor(instance);
- if (eventsToMonitor.indexOf('seriestimers') !== -1 || eventsToMonitor.indexOf('timers') !== -1) {
- // yes this is an assumption
- return;
- }
-
- var itemsAdded = data.ItemsAdded || [];
- var itemsRemoved = data.ItemsRemoved || [];
- if (!itemsAdded.length && !itemsRemoved.length) {
- return;
- }
-
- var options = instance.options || {};
- var parentId = options.parentId;
- if (parentId) {
- var foldersAddedTo = data.FoldersAddedTo || [];
- var foldersRemovedFrom = data.FoldersRemovedFrom || [];
- var collectionFolders = data.CollectionFolders || [];
-
- if (foldersAddedTo.indexOf(parentId) === -1 && foldersRemovedFrom.indexOf(parentId) === -1 && collectionFolders.indexOf(parentId) === -1) {
- return;
- }
- }
+ const eventsToMonitor = getEventsToMonitor(instance);
+ // TODO: Check user data change reason?
+ if (eventsToMonitor.indexOf('markfavorite') !== -1) {
+ instance.notifyRefreshNeeded();
+ } else if (eventsToMonitor.indexOf('markplayed') !== -1) {
instance.notifyRefreshNeeded();
}
+}
- function onPlaybackStopped(e, stopInfo) {
- var instance = this;
+function getEventsToMonitor(instance) {
+ const options = instance.options;
+ const monitor = options ? options.monitorEvents : null;
+ if (monitor) {
+ return monitor.split(',');
+ }
- var state = stopInfo.state;
+ return [];
+}
- var eventsToMonitor = getEventsToMonitor(instance);
- if (state.NowPlayingItem && state.NowPlayingItem.MediaType === 'Video') {
- if (eventsToMonitor.indexOf('videoplayback') !== -1) {
- instance.notifyRefreshNeeded(true);
- return;
- }
- } else if (state.NowPlayingItem && state.NowPlayingItem.MediaType === 'Audio') {
- if (eventsToMonitor.indexOf('audioplayback') !== -1) {
- instance.notifyRefreshNeeded(true);
- return;
- }
+function onTimerCreated(e, apiClient, data) {
+ const instance = this;
+
+ if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
+ instance.notifyRefreshNeeded();
+ return;
+ }
+}
+
+function onSeriesTimerCreated(e, apiClient, data) {
+ const instance = this;
+ if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
+ instance.notifyRefreshNeeded();
+ return;
+ }
+}
+
+function onTimerCancelled(e, apiClient, data) {
+ const instance = this;
+
+ if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
+ instance.notifyRefreshNeeded();
+ return;
+ }
+}
+
+function onSeriesTimerCancelled(e, apiClient, data) {
+ const instance = this;
+ if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
+ instance.notifyRefreshNeeded();
+ return;
+ }
+}
+
+function onLibraryChanged(e, apiClient, data) {
+ const instance = this;
+ const eventsToMonitor = getEventsToMonitor(instance);
+ if (eventsToMonitor.indexOf('seriestimers') !== -1 || eventsToMonitor.indexOf('timers') !== -1) {
+ // yes this is an assumption
+ return;
+ }
+
+ const itemsAdded = data.ItemsAdded || [];
+ const itemsRemoved = data.ItemsRemoved || [];
+ if (!itemsAdded.length && !itemsRemoved.length) {
+ return;
+ }
+
+ const options = instance.options || {};
+ const parentId = options.parentId;
+ if (parentId) {
+ const foldersAddedTo = data.FoldersAddedTo || [];
+ const foldersRemovedFrom = data.FoldersRemovedFrom || [];
+ const collectionFolders = data.CollectionFolders || [];
+
+ if (foldersAddedTo.indexOf(parentId) === -1 && foldersRemovedFrom.indexOf(parentId) === -1 && collectionFolders.indexOf(parentId) === -1) {
+ return;
}
}
- function addNotificationEvent(instance, name, handler, owner) {
- var localHandler = handler.bind(instance);
+ instance.notifyRefreshNeeded();
+}
+
+function onPlaybackStopped(e, stopInfo) {
+ const instance = this;
+
+ const state = stopInfo.state;
+
+ const eventsToMonitor = getEventsToMonitor(instance);
+ if (state.NowPlayingItem && state.NowPlayingItem.MediaType === 'Video') {
+ if (eventsToMonitor.indexOf('videoplayback') !== -1) {
+ instance.notifyRefreshNeeded(true);
+ return;
+ }
+ } else if (state.NowPlayingItem && state.NowPlayingItem.MediaType === 'Audio') {
+ if (eventsToMonitor.indexOf('audioplayback') !== -1) {
+ instance.notifyRefreshNeeded(true);
+ return;
+ }
+ }
+}
+
+function addNotificationEvent(instance, name, handler, owner) {
+ const localHandler = handler.bind(instance);
+ owner = owner || serverNotifications;
+ events.on(owner, name, localHandler);
+ instance['event_' + name] = localHandler;
+}
+
+function removeNotificationEvent(instance, name, owner) {
+ const handler = instance['event_' + name];
+ if (handler) {
owner = owner || serverNotifications;
- events.on(owner, name, localHandler);
- instance['event_' + name] = localHandler;
+ events.off(owner, name, handler);
+ instance['event_' + name] = null;
}
+}
- function removeNotificationEvent(instance, name, owner) {
- var handler = instance['event_' + name];
- if (handler) {
- owner = owner || serverNotifications;
- events.off(owner, name, handler);
- instance['event_' + name] = null;
- }
- }
-
- function ItemsRefresher(options) {
+class ItemsRefresher {
+ constructor(options) {
this.options = options || {};
addNotificationEvent(this, 'UserDataChanged', onUserDataChanged);
@@ -137,18 +136,18 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
addNotificationEvent(this, 'playbackstop', onPlaybackStopped, playbackManager);
}
- ItemsRefresher.prototype.pause = function () {
+ pause() {
clearRefreshInterval(this, true);
this.paused = true;
- };
+ }
- ItemsRefresher.prototype.resume = function (options) {
+ resume(options) {
this.paused = false;
- var refreshIntervalEndTime = this.refreshIntervalEndTime;
+ const refreshIntervalEndTime = this.refreshIntervalEndTime;
if (refreshIntervalEndTime) {
- var remainingMs = refreshIntervalEndTime - new Date().getTime();
+ const remainingMs = refreshIntervalEndTime - new Date().getTime();
if (remainingMs > 0 && !this.needsRefresh) {
resetRefreshInterval(this, remainingMs);
} else {
@@ -162,9 +161,9 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
}
return Promise.resolve();
- };
+ }
- ItemsRefresher.prototype.refreshItems = function () {
+ refreshItems() {
if (!this.fetchData) {
return Promise.resolve();
}
@@ -177,15 +176,15 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
this.needsRefresh = false;
return this.fetchData().then(onDataFetched.bind(this));
- };
+ }
- ItemsRefresher.prototype.notifyRefreshNeeded = function (isInForeground) {
+ notifyRefreshNeeded(isInForeground) {
if (this.paused) {
this.needsRefresh = true;
return;
}
- var timeout = this.refreshTimeout;
+ const timeout = this.refreshTimeout;
if (timeout) {
clearTimeout(timeout);
}
@@ -195,44 +194,9 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
} else {
this.refreshTimeout = setTimeout(this.refreshItems.bind(this), 10000);
}
- };
-
- function clearRefreshInterval(instance, isPausing) {
- if (instance.refreshInterval) {
- clearInterval(instance.refreshInterval);
- instance.refreshInterval = null;
-
- if (!isPausing) {
- instance.refreshIntervalEndTime = null;
- }
- }
}
- function resetRefreshInterval(instance, intervalMs) {
- clearRefreshInterval(instance);
-
- if (!intervalMs) {
- var options = instance.options;
- if (options) {
- intervalMs = options.refreshIntervalMs;
- }
- }
-
- if (intervalMs) {
- instance.refreshInterval = setInterval(instance.notifyRefreshNeeded.bind(instance), intervalMs);
- instance.refreshIntervalEndTime = new Date().getTime() + intervalMs;
- }
- }
-
- function onDataFetched(result) {
- resetRefreshInterval(this);
-
- if (this.afterRefresh) {
- this.afterRefresh(result);
- }
- }
-
- ItemsRefresher.prototype.destroy = function () {
+ destroy() {
clearRefreshInterval(this);
removeNotificationEvent(this, 'UserDataChanged');
@@ -245,7 +209,42 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
this.fetchData = null;
this.options = null;
- };
+ }
+}
- return ItemsRefresher;
-});
+function clearRefreshInterval(instance, isPausing) {
+ if (instance.refreshInterval) {
+ clearInterval(instance.refreshInterval);
+ instance.refreshInterval = null;
+
+ if (!isPausing) {
+ instance.refreshIntervalEndTime = null;
+ }
+ }
+}
+
+function resetRefreshInterval(instance, intervalMs) {
+ clearRefreshInterval(instance);
+
+ if (!intervalMs) {
+ const options = instance.options;
+ if (options) {
+ intervalMs = options.refreshIntervalMs;
+ }
+ }
+
+ if (intervalMs) {
+ instance.refreshInterval = setInterval(instance.notifyRefreshNeeded.bind(instance), intervalMs);
+ instance.refreshIntervalEndTime = new Date().getTime() + intervalMs;
+ }
+}
+
+function onDataFetched(result) {
+ resetRefreshInterval(this);
+
+ if (this.afterRefresh) {
+ this.afterRefresh(result);
+ }
+}
+
+export default ItemsRefresher;
diff --git a/src/components/layoutManager.js b/src/components/layoutManager.js
index 85d78f8ff..88a7265f8 100644
--- a/src/components/layoutManager.js
+++ b/src/components/layoutManager.js
@@ -1,23 +1,19 @@
-define(['browser', 'appSettings', 'events'], function (browser, appSettings, events) {
- 'use strict';
+import browser from 'browser';
+import appSettings from 'appSettings';
+import events from 'events';
- browser = browser.default || browser;
-
- function setLayout(instance, layout, selectedLayout) {
- if (layout === selectedLayout) {
- instance[layout] = true;
- document.documentElement.classList.add('layout-' + layout);
- } else {
- instance[layout] = false;
- document.documentElement.classList.remove('layout-' + layout);
- }
+function setLayout(instance, layout, selectedLayout) {
+ if (layout === selectedLayout) {
+ instance[layout] = true;
+ document.documentElement.classList.add('layout-' + layout);
+ } else {
+ instance[layout] = false;
+ document.documentElement.classList.remove('layout-' + layout);
}
+}
- function LayoutManager() {
-
- }
-
- LayoutManager.prototype.setLayout = function (layout, save) {
+class LayoutManager {
+ setLayout(layout, save) {
if (!layout || layout === 'auto') {
this.autoLayout();
@@ -35,13 +31,13 @@ define(['browser', 'appSettings', 'events'], function (browser, appSettings, eve
}
events.trigger(this, 'modechange');
- };
+ }
- LayoutManager.prototype.getSavedLayout = function (layout) {
+ getSavedLayout(layout) {
return appSettings.get('layout');
- };
+ }
- LayoutManager.prototype.autoLayout = function () {
+ autoLayout() {
// Take a guess at initial layout. The consuming app can override
if (browser.mobile) {
this.setLayout('mobile', false);
@@ -50,16 +46,16 @@ define(['browser', 'appSettings', 'events'], function (browser, appSettings, eve
} else {
this.setLayout(this.defaultLayout || 'tv', false);
}
- };
+ }
- LayoutManager.prototype.init = function () {
- var saved = this.getSavedLayout();
+ init() {
+ const saved = this.getSavedLayout();
if (saved) {
this.setLayout(saved, false);
} else {
this.autoLayout();
}
- };
+ }
+}
- return new LayoutManager();
-});
+export default new LayoutManager();
diff --git a/src/components/recordingcreator/recordingcreator.js b/src/components/recordingcreator/recordingcreator.js
index 9c2d8fcb6..d54dd219a 100644
--- a/src/components/recordingcreator/recordingcreator.js
+++ b/src/components/recordingcreator/recordingcreator.js
@@ -1,6 +1,7 @@
define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'connectionManager', 'require', 'loading', 'scrollHelper', 'datetime', 'imageLoader', 'recordingFields', 'events', 'emby-checkbox', 'emby-button', 'emby-collapse', 'emby-input', 'paper-icon-button-light', 'css!./../formdialog', 'css!./recordingcreator', 'material-icons'], function (dialogHelper, globalize, layoutManager, mediaInfo, appHost, connectionManager, require, loading, scrollHelper, datetime, imageLoader, recordingFields, events) {
'use strict';
+ layoutManager = layoutManager.default || layoutManager;
scrollHelper = scrollHelper.default || scrollHelper;
var currentDialog;
diff --git a/src/components/recordingcreator/recordingeditor.js b/src/components/recordingcreator/recordingeditor.js
index 7117778eb..e9aca8534 100644
--- a/src/components/recordingcreator/recordingeditor.js
+++ b/src/components/recordingcreator/recordingeditor.js
@@ -3,6 +3,7 @@ define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'c
scrollHelper = scrollHelper.default || scrollHelper;
loading = loading.default || loading;
+ layoutManager = layoutManager.default || layoutManager;
var currentDialog;
var recordingDeleted = false;
diff --git a/src/components/remotecontrol/remotecontrol.js b/src/components/remotecontrol/remotecontrol.js
index b5ac4c9a8..c6c2a123b 100644
--- a/src/components/remotecontrol/remotecontrol.js
+++ b/src/components/remotecontrol/remotecontrol.js
@@ -2,6 +2,7 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL
'use strict';
playbackManager = playbackManager.default || playbackManager;
+ layoutManager = layoutManager.default || layoutManager;
var showMuteButton = true;
var showVolumeSlider = true;
diff --git a/src/components/slideshow/slideshow.js b/src/components/slideshow/slideshow.js
index 38728ec6c..82f541a11 100644
--- a/src/components/slideshow/slideshow.js
+++ b/src/components/slideshow/slideshow.js
@@ -2,667 +2,672 @@
* Image viewer component
* @module components/slideshow/slideshow
*/
-define(['dialogHelper', 'inputManager', 'connectionManager', 'layoutManager', 'focusManager', 'browser', 'apphost', 'dom', 'css!./style', 'material-icons', 'paper-icon-button-light'], function (dialogHelper, inputManager, connectionManager, layoutManager, focusManager, browser, appHost, dom) {
- 'use strict';
+import dialogHelper from 'dialogHelper';
+import inputManager from 'inputManager';
+import connectionManager from 'connectionManager';
+import layoutManager from 'layoutManager';
+import focusManager from 'focusManager';
+import browser from 'browser';
+import appHost from 'apphost';
+import dom from 'dom';
+import 'css!./style';
+import 'material-icons';
+import 'paper-icon-button-light';
- browser = browser.default || browser;
- focusManager = focusManager.default || focusManager;
+/**
+ * Name of transition event.
+ */
+const transitionEndEventName = dom.whichTransitionEvent();
- /**
- * Name of transition event.
- */
- const transitionEndEventName = dom.whichTransitionEvent();
+/**
+ * Flag to use fake image to fix blurry zoomed image.
+ * At least WebKit doesn't restore quality for zoomed images.
+ */
+const useFakeZoomImage = browser.safari;
- /**
- * Flag to use fake image to fix blurry zoomed image.
- * At least WebKit doesn't restore quality for zoomed images.
- */
- const useFakeZoomImage = browser.safari;
+/**
+ * Retrieves an item's image URL from the API.
+ * @param {object|string} item - Item used to generate the image URL.
+ * @param {object} options - Options of the image.
+ * @param {object} apiClient - API client instance used to retrieve the image.
+ * @returns {null|string} URL of the item's image.
+ */
+function getImageUrl(item, options, apiClient) {
+ options = options || {};
+ options.type = options.type || 'Primary';
- /**
- * Retrieves an item's image URL from the API.
- * @param {object|string} item - Item used to generate the image URL.
- * @param {object} options - Options of the image.
- * @param {object} apiClient - API client instance used to retrieve the image.
- * @returns {null|string} URL of the item's image.
- */
- function getImageUrl(item, options, apiClient) {
- options = options || {};
- options.type = options.type || 'Primary';
+ if (typeof (item) === 'string') {
+ return apiClient.getScaledImageUrl(item, options);
+ }
- if (typeof (item) === 'string') {
- return apiClient.getScaledImageUrl(item, options);
+ if (item.ImageTags && item.ImageTags[options.type]) {
+ options.tag = item.ImageTags[options.type];
+ return apiClient.getScaledImageUrl(item.Id, options);
+ }
+
+ if (options.type === 'Primary') {
+ if (item.AlbumId && item.AlbumPrimaryImageTag) {
+ options.tag = item.AlbumPrimaryImageTag;
+ return apiClient.getScaledImageUrl(item.AlbumId, options);
}
+ }
- if (item.ImageTags && item.ImageTags[options.type]) {
- options.tag = item.ImageTags[options.type];
- return apiClient.getScaledImageUrl(item.Id, options);
+ return null;
+}
+
+/**
+ * Retrieves a backdrop's image URL from the API.
+ * @param {object} item - Item used to generate the image URL.
+ * @param {object} options - Options of the image.
+ * @param {object} apiClient - API client instance used to retrieve the image.
+ * @returns {null|string} URL of the item's backdrop.
+ */
+function getBackdropImageUrl(item, options, apiClient) {
+ options = options || {};
+ options.type = options.type || 'Backdrop';
+
+ // If not resizing, get the original image
+ if (!options.maxWidth && !options.width && !options.maxHeight && !options.height) {
+ options.quality = 100;
+ }
+
+ if (item.BackdropImageTags && item.BackdropImageTags.length) {
+ options.tag = item.BackdropImageTags[0];
+ return apiClient.getScaledImageUrl(item.Id, options);
+ }
+
+ return null;
+}
+
+/**
+ * Dispatches a request for an item's image to its respective handler.
+ * @param {object} item - Item used to generate the image URL.
+ * @returns {string} URL of the item's image.
+ */
+function getImgUrl(item, user) {
+ const apiClient = connectionManager.getApiClient(item.ServerId);
+ const imageOptions = {};
+
+ if (item.BackdropImageTags && item.BackdropImageTags.length) {
+ return getBackdropImageUrl(item, imageOptions, apiClient);
+ } else {
+ if (item.MediaType === 'Photo' && user && user.Policy.EnableContentDownloading) {
+ return apiClient.getItemDownloadUrl(item.Id);
}
+ imageOptions.type = 'Primary';
+ return getImageUrl(item, imageOptions, apiClient);
+ }
+}
- if (options.type === 'Primary') {
- if (item.AlbumId && item.AlbumPrimaryImageTag) {
- options.tag = item.AlbumPrimaryImageTag;
- return apiClient.getScaledImageUrl(item.AlbumId, options);
+/**
+ * Generates a button using the specified icon, classes and properties.
+ * @param {string} icon - Name of the material icon on the button
+ * @param {string} cssClass - CSS classes to assign to the button
+ * @param {boolean} canFocus - Flag to set the tabindex attribute on the button to -1.
+ * @param {boolean} autoFocus - Flag to set the autofocus attribute on the button.
+ * @returns {string} The HTML markup of the button.
+ */
+function getIcon(icon, cssClass, canFocus, autoFocus) {
+ const tabIndex = canFocus ? '' : ' tabindex="-1"';
+ autoFocus = autoFocus ? ' autofocus' : '';
+ return '';
+}
+
+/**
+ * Sets the viewport meta tag to enable or disable scaling by the user.
+ * @param {boolean} scalable - Flag to set the scalability of the viewport.
+ */
+function setUserScalable(scalable) {
+ try {
+ appHost.setUserScalable(scalable);
+ } catch (err) {
+ console.error('error in appHost.setUserScalable: ' + err);
+ }
+}
+
+export default function (options) {
+ const self = this;
+ /** Initialized instance of Swiper. */
+ let swiperInstance;
+ /** Initialized instance of the dialog containing the Swiper instance. */
+ let dialog;
+ /** Options of the slideshow components */
+ let currentOptions;
+ /** ID of the timeout used to hide the OSD. */
+ let hideTimeout;
+ /** Last coordinates of the mouse pointer. */
+ let lastMouseMoveData;
+
+ /**
+ * Creates the HTML markup for the dialog and the OSD.
+ * @param {Object} options - Options used to create the dialog and slideshow.
+ */
+ function createElements(options) {
+ currentOptions = options;
+
+ dialog = dialogHelper.createDialog({
+ exitAnimationDuration: options.interactive ? 400 : 800,
+ size: 'fullscreen',
+ autoFocus: false,
+ scrollY: false,
+ exitAnimation: 'fadeout',
+ removeOnClose: true
+ });
+
+ dialog.classList.add('slideshowDialog');
+
+ let html = '';
+
+ html += '
';
+
+ if (options.interactive && !layoutManager.tv) {
+ const actionButtonsOnTop = layoutManager.mobile;
+
+ html += getIcon('keyboard_arrow_left', 'btnSlideshowPrevious slideshowButton hide-mouse-idle-tv', false);
+ html += getIcon('keyboard_arrow_right', 'btnSlideshowNext slideshowButton hide-mouse-idle-tv', false);
+
+ html += '
';
+ if (actionButtonsOnTop) {
+ if (appHost.supports('filedownload') && options.user && options.user.Policy.EnableContentDownloading) {
+ html += getIcon('file_download', 'btnDownload slideshowButton', true);
+ }
+ if (appHost.supports('sharing')) {
+ html += getIcon('share', 'btnShare slideshowButton', true);
+ }
}
- }
+ html += getIcon('close', 'slideshowButton btnSlideshowExit hide-mouse-idle-tv', false);
+ html += '
';
- return null;
- }
+ if (!actionButtonsOnTop) {
+ html += '
';
- /**
- * Retrieves a backdrop's image URL from the API.
- * @param {object} item - Item used to generate the image URL.
- * @param {object} options - Options of the image.
- * @param {object} apiClient - API client instance used to retrieve the image.
- * @returns {null|string} URL of the item's backdrop.
- */
- function getBackdropImageUrl(item, options, apiClient) {
- options = options || {};
- options.type = options.type || 'Backdrop';
+ html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true, true);
+ if (appHost.supports('filedownload') && options.user && options.user.Policy.EnableContentDownloading) {
+ html += getIcon('file_download', 'btnDownload slideshowButton', true);
+ }
+ if (appHost.supports('sharing')) {
+ html += getIcon('share', 'btnShare slideshowButton', true);
+ }
- // If not resizing, get the original image
- if (!options.maxWidth && !options.width && !options.maxHeight && !options.height) {
- options.quality = 100;
- }
-
- if (item.BackdropImageTags && item.BackdropImageTags.length) {
- options.tag = item.BackdropImageTags[0];
- return apiClient.getScaledImageUrl(item.Id, options);
- }
-
- return null;
- }
-
- /**
- * Dispatches a request for an item's image to its respective handler.
- * @param {object} item - Item used to generate the image URL.
- * @returns {string} URL of the item's image.
- */
- function getImgUrl(item, user) {
- var apiClient = connectionManager.getApiClient(item.ServerId);
- var imageOptions = {};
-
- if (item.BackdropImageTags && item.BackdropImageTags.length) {
- return getBackdropImageUrl(item, imageOptions, apiClient);
+ html += '
';
+ }
} else {
- if (item.MediaType === 'Photo' && user && user.Policy.EnableContentDownloading) {
- return apiClient.getItemDownloadUrl(item.Id);
- }
- imageOptions.type = 'Primary';
- return getImageUrl(item, imageOptions, apiClient);
- }
- }
-
- /**
- * Generates a button using the specified icon, classes and properties.
- * @param {string} icon - Name of the material icon on the button
- * @param {string} cssClass - CSS classes to assign to the button
- * @param {boolean} canFocus - Flag to set the tabindex attribute on the button to -1.
- * @param {boolean} autoFocus - Flag to set the autofocus attribute on the button.
- * @returns {string} The HTML markup of the button.
- */
- function getIcon(icon, cssClass, canFocus, autoFocus) {
- var tabIndex = canFocus ? '' : ' tabindex="-1"';
- autoFocus = autoFocus ? ' autofocus' : '';
- return '';
- }
-
- /**
- * Sets the viewport meta tag to enable or disable scaling by the user.
- * @param {boolean} scalable - Flag to set the scalability of the viewport.
- */
- function setUserScalable(scalable) {
- try {
- appHost.setUserScalable(scalable);
- } catch (err) {
- console.error('error in appHost.setUserScalable: ' + err);
- }
- }
-
- return function (options) {
- var self = this;
- /** Initialized instance of Swiper. */
- var swiperInstance;
- /** Initialized instance of the dialog containing the Swiper instance. */
- var dialog;
- /** Options of the slideshow components */
- var currentOptions;
- /** ID of the timeout used to hide the OSD. */
- var hideTimeout;
- /** Last coordinates of the mouse pointer. */
- var lastMouseMoveData;
-
- /**
- * Creates the HTML markup for the dialog and the OSD.
- * @param {Object} options - Options used to create the dialog and slideshow.
- */
- function createElements(options) {
- currentOptions = options;
-
- dialog = dialogHelper.createDialog({
- exitAnimationDuration: options.interactive ? 400 : 800,
- size: 'fullscreen',
- autoFocus: false,
- scrollY: false,
- exitAnimation: 'fadeout',
- removeOnClose: true
- });
-
- dialog.classList.add('slideshowDialog');
-
- var html = '';
-
- html += '
';
-
- if (options.interactive && !layoutManager.tv) {
- var actionButtonsOnTop = layoutManager.mobile;
-
- html += getIcon('keyboard_arrow_left', 'btnSlideshowPrevious slideshowButton hide-mouse-idle-tv', false);
- html += getIcon('keyboard_arrow_right', 'btnSlideshowNext slideshowButton hide-mouse-idle-tv', false);
-
- html += '
';
- if (actionButtonsOnTop) {
- if (appHost.supports('filedownload') && options.user && options.user.Policy.EnableContentDownloading) {
- html += getIcon('file_download', 'btnDownload slideshowButton', true);
- }
- if (appHost.supports('sharing')) {
- html += getIcon('share', 'btnShare slideshowButton', true);
- }
- }
- html += getIcon('close', 'slideshowButton btnSlideshowExit hide-mouse-idle-tv', false);
- html += '
';
-
- if (!actionButtonsOnTop) {
- html += '
';
-
- html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true, true);
- if (appHost.supports('filedownload') && options.user && options.user.Policy.EnableContentDownloading) {
- html += getIcon('file_download', 'btnDownload slideshowButton', true);
- }
- if (appHost.supports('sharing')) {
- html += getIcon('share', 'btnShare slideshowButton', true);
- }
-
- html += '
';
- }
- } else {
- html += '';
- }
-
- dialog.innerHTML = html;
-
- if (options.interactive && !layoutManager.tv) {
- dialog.querySelector('.btnSlideshowExit').addEventListener('click', function (e) {
- dialogHelper.close(dialog);
- });
-
- var btnPause = dialog.querySelector('.btnSlideshowPause');
- if (btnPause) {
- btnPause.addEventListener('click', playPause);
- }
-
- var btnDownload = dialog.querySelector('.btnDownload');
- if (btnDownload) {
- btnDownload.addEventListener('click', download);
- }
-
- var btnShare = dialog.querySelector('.btnShare');
- if (btnShare) {
- btnShare.addEventListener('click', share);
- }
- }
-
- setUserScalable(true);
-
- dialogHelper.open(dialog).then(function () {
- setUserScalable(false);
- });
-
- inputManager.on(window, onInputCommand);
- /* eslint-disable-next-line compat/compat */
- document.addEventListener((window.PointerEvent ? 'pointermove' : 'mousemove'), onPointerMove);
-
- dialog.addEventListener('close', onDialogClosed);
-
- loadSwiper(dialog, options);
+ html += '';
}
- /**
- * Handles OSD changes when the autoplay is started.
- */
- function onAutoplayStart() {
- var btnSlideshowPause = dialog.querySelector('.btnSlideshowPause .material-icons');
- if (btnSlideshowPause) {
- btnSlideshowPause.classList.replace('play_arrow', 'pause');
- }
- }
+ dialog.innerHTML = html;
- /**
- * Handles OSD changes when the autoplay is stopped.
- */
- function onAutoplayStop() {
- var btnSlideshowPause = dialog.querySelector('.btnSlideshowPause .material-icons');
- if (btnSlideshowPause) {
- btnSlideshowPause.classList.replace('pause', 'play_arrow');
- }
- }
-
- /**
- * Handles zoom changes.
- */
- function onZoomChange(scale, imageEl, slideEl) {
- const zoomImage = slideEl.querySelector('.swiper-zoom-fakeimg');
-
- if (zoomImage) {
- zoomImage.style.width = zoomImage.style.height = scale * 100 + '%';
-
- if (scale > 1) {
- if (zoomImage.classList.contains('swiper-zoom-fakeimg-hidden')) {
- // Await for Swiper style changes
- setTimeout(() => {
- const callback = () => {
- imageEl.removeEventListener(transitionEndEventName, callback);
- zoomImage.classList.remove('swiper-zoom-fakeimg-hidden');
- };
-
- // Swiper set 'transition-duration: 300ms' for auto zoom
- // and 'transition-duration: 0s' for touch zoom
- const transitionDuration = parseFloat(imageEl.style.transitionDuration.replace(/[a-z]/i, ''));
-
- if (transitionDuration > 0) {
- imageEl.addEventListener(transitionEndEventName, callback);
- } else {
- callback();
- }
- }, 0);
- }
- } else {
- zoomImage.classList.add('swiper-zoom-fakeimg-hidden');
- }
- }
- }
-
- /**
- * Initializes the Swiper instance and binds the relevant events.
- * @param {HTMLElement} dialog - Element containing the dialog.
- * @param {Object} options - Options used to initialize the Swiper instance.
- */
- function loadSwiper(dialog, options) {
- var slides;
- if (currentOptions.slides) {
- slides = currentOptions.slides;
- } else {
- slides = currentOptions.items;
- }
-
- require(['swiper'], function (Swiper) {
- swiperInstance = new Swiper(dialog.querySelector('.slideshowSwiperContainer'), {
- direction: 'horizontal',
- // Loop is disabled due to the virtual slides option not supporting it.
- loop: false,
- zoom: {
- minRatio: 1,
- toggle: true
- },
- autoplay: !options.interactive,
- keyboard: {
- enabled: true
- },
- preloadImages: true,
- slidesPerView: 1,
- slidesPerColumn: 1,
- initialSlide: options.startIndex || 0,
- speed: 240,
- navigation: {
- nextEl: '.btnSlideshowNext',
- prevEl: '.btnSlideshowPrevious'
- },
- // Virtual slides reduce memory consumption for large libraries while allowing preloading of images;
- virtual: {
- slides: slides,
- cache: true,
- renderSlide: getSwiperSlideHtml,
- addSlidesBefore: 1,
- addSlidesAfter: 1
- }
- });
-
- swiperInstance.on('autoplayStart', onAutoplayStart);
- swiperInstance.on('autoplayStop', onAutoplayStop);
-
- if (useFakeZoomImage) {
- swiperInstance.on('zoomChange', onZoomChange);
- }
- });
- }
-
- /**
- * Renders the HTML markup of a slide for an item or a slide.
- * @param {Object} item - The item used to render the slide.
- * @param {number} index - The index of the item in the Swiper instance.
- * @returns {string} The HTML markup of the slide.
- */
- function getSwiperSlideHtml(item, index) {
- if (currentOptions.slides) {
- return getSwiperSlideHtmlFromSlide(item);
- } else {
- return getSwiperSlideHtmlFromItem(item);
- }
- }
-
- /**
- * Renders the HTML markup of a slide for an item.
- * @param {Object} item - Item used to generate the slide.
- * @returns {string} The HTML markup of the slide.
- */
- function getSwiperSlideHtmlFromItem(item) {
- return getSwiperSlideHtmlFromSlide({
- originalImage: getImgUrl(item, currentOptions.user),
- Id: item.Id,
- ServerId: item.ServerId
- });
- }
-
- /**
- * Renders the HTML markup of a slide for a slide object.
- * @param {Object} item - Slide object used to generate the slide.
- * @returns {string} The HTML markup of the slide.
- */
- function getSwiperSlideHtmlFromSlide(item) {
- var html = '';
- html += '
';
- html += '
';
- if (useFakeZoomImage) {
- html += ``;
- }
- html += '';
- html += '
';
- if (item.title || item.subtitle) {
- html += '
';
- html += '
';
- if (item.title) {
- html += '
';
- html += item.title;
- html += '
';
- }
- if (item.description) {
- html += '
';
- html += item.description;
- html += '
';
- }
- html += '
';
- html += '
';
- }
- html += '
';
-
- return html;
- }
-
- /**
- * Fetches the information of the currently displayed slide.
- * @returns {null|{itemId: string, shareUrl: string, serverId: string, url: string}} Object containing the information of the currently displayed slide.
- */
- function getCurrentImageInfo() {
- if (swiperInstance) {
- var slide = document.querySelector('.swiper-slide-active');
-
- if (slide) {
- return {
- url: slide.getAttribute('data-original'),
- shareUrl: slide.getAttribute('data-original'),
- itemId: slide.getAttribute('data-itemid'),
- serverId: slide.getAttribute('data-serverid')
- };
- }
- return null;
- } else {
- return null;
- }
- }
-
- /**
- * Starts a download for the currently displayed slide.
- */
- function download() {
- var imageInfo = getCurrentImageInfo();
-
- require(['fileDownloader'], function (fileDownloader) {
- fileDownloader.download([imageInfo]);
- });
- }
-
- /**
- * Shares the currently displayed slide using the browser's built-in sharing feature.
- */
- function share() {
- var imageInfo = getCurrentImageInfo();
-
- navigator.share({
- url: imageInfo.shareUrl
- });
- }
-
- /**
- * Starts the autoplay feature of the Swiper instance.
- */
- function play() {
- if (swiperInstance.autoplay) {
- swiperInstance.autoplay.start();
- }
- }
-
- /**
- * Pauses the autoplay feature of the Swiper instance;
- */
- function pause() {
- if (swiperInstance.autoplay) {
- swiperInstance.autoplay.stop();
- }
- }
-
- /**
- * Toggles the autoplay feature of the Swiper instance.
- */
- function playPause() {
- var paused = !dialog.querySelector('.btnSlideshowPause .material-icons').classList.contains('pause');
- if (paused) {
- play();
- } else {
- pause();
- }
- }
-
- /**
- * Closes the dialog and destroys the Swiper instance.
- */
- function onDialogClosed() {
- var swiper = swiperInstance;
- if (swiper) {
- swiper.destroy(true, true);
- swiperInstance = null;
- }
-
- inputManager.off(window, onInputCommand);
- /* eslint-disable-next-line compat/compat */
- document.removeEventListener((window.PointerEvent ? 'pointermove' : 'mousemove'), onPointerMove);
- // Shows page scrollbar
- document.body.classList.remove('hide-scroll');
- document.body.classList.add('force-scroll');
- }
-
- /**
- * Shows the OSD.
- */
- function showOsd() {
- var bottom = dialog.querySelector('.slideshowBottomBar');
- if (bottom) {
- slideUpToShow(bottom);
- startHideTimer();
- }
- }
-
- /**
- * Hides the OSD.
- */
- function hideOsd() {
- var bottom = dialog.querySelector('.slideshowBottomBar');
- if (bottom) {
- slideDownToHide(bottom);
- }
- }
-
- /**
- * Starts the timer used to automatically hide the OSD.
- */
- function startHideTimer() {
- stopHideTimer();
- hideTimeout = setTimeout(hideOsd, 3000);
- }
-
- /**
- * Stops the timer used to automatically hide the OSD.
- */
- function stopHideTimer() {
- if (hideTimeout) {
- clearTimeout(hideTimeout);
- hideTimeout = null;
- }
- }
-
- /**
- * Shows the OSD by sliding it into view.
- * @param {HTMLElement} element - Element containing the OSD.
- */
- function slideUpToShow(element) {
- if (!element.classList.contains('hide')) {
- return;
- }
-
- element.classList.remove('hide');
-
- var onFinish = function () {
- focusManager.focus(element.querySelector('.btnSlideshowPause'));
- };
-
- if (!element.animate) {
- onFinish();
- return;
- }
-
- requestAnimationFrame(function () {
- var keyframes = [
- { transform: 'translate3d(0,' + element.offsetHeight + 'px,0)', opacity: '.3', offset: 0 },
- { transform: 'translate3d(0,0,0)', opacity: '1', offset: 1 }
- ];
- var timing = { duration: 300, iterations: 1, easing: 'ease-out' };
- element.animate(keyframes, timing).onfinish = onFinish;
- });
- }
-
- /**
- * Hides the OSD by sliding it out of view.
- * @param {HTMLElement} element - Element containing the OSD.
- */
- function slideDownToHide(element) {
- if (element.classList.contains('hide')) {
- return;
- }
-
- var onFinish = function () {
- element.classList.add('hide');
- };
-
- if (!element.animate) {
- onFinish();
- return;
- }
-
- requestAnimationFrame(function () {
- var keyframes = [
- { transform: 'translate3d(0,0,0)', opacity: '1', offset: 0 },
- { transform: 'translate3d(0,' + element.offsetHeight + 'px,0)', opacity: '.3', offset: 1 }
- ];
- var timing = { duration: 300, iterations: 1, easing: 'ease-out' };
- element.animate(keyframes, timing).onfinish = onFinish;
- });
- }
-
- /**
- * Shows the OSD when moving the mouse pointer or touching the screen.
- * @param {Event} event - Pointer movement event.
- */
- function onPointerMove(event) {
- var pointerType = event.pointerType || (layoutManager.mobile ? 'touch' : 'mouse');
-
- if (pointerType === 'mouse') {
- var eventX = event.screenX || 0;
- var eventY = event.screenY || 0;
-
- var obj = lastMouseMoveData;
- if (!obj) {
- lastMouseMoveData = {
- x: eventX,
- y: eventY
- };
- return;
- }
-
- // if coord are same, it didn't move
- if (Math.abs(eventX - obj.x) < 10 && Math.abs(eventY - obj.y) < 10) {
- return;
- }
-
- obj.x = eventX;
- obj.y = eventY;
-
- showOsd();
- }
- }
-
- /**
- * Dispatches keyboard inputs to their proper handlers.
- * @param {Event} event - Keyboard input event.
- */
- function onInputCommand(event) {
- switch (event.detail.command) {
- case 'up':
- case 'down':
- case 'select':
- case 'menu':
- case 'info':
- showOsd();
- break;
- case 'play':
- play();
- break;
- case 'pause':
- pause();
- break;
- case 'playpause':
- playPause();
- break;
- default:
- break;
- }
- }
-
- /**
- * Shows the slideshow component.
- */
- self.show = function () {
- createElements(options);
- // Hides page scrollbar
- document.body.classList.remove('force-scroll');
- document.body.classList.add('hide-scroll');
- };
-
- /**
- * Hides the slideshow element.
- */
- self.hide = function () {
- if (dialog) {
+ if (options.interactive && !layoutManager.tv) {
+ dialog.querySelector('.btnSlideshowExit').addEventListener('click', function (e) {
dialogHelper.close(dialog);
+ });
+
+ const btnPause = dialog.querySelector('.btnSlideshowPause');
+ if (btnPause) {
+ btnPause.addEventListener('click', playPause);
}
+
+ const btnDownload = dialog.querySelector('.btnDownload');
+ if (btnDownload) {
+ btnDownload.addEventListener('click', download);
+ }
+
+ const btnShare = dialog.querySelector('.btnShare');
+ if (btnShare) {
+ btnShare.addEventListener('click', share);
+ }
+ }
+
+ setUserScalable(true);
+
+ dialogHelper.open(dialog).then(function () {
+ setUserScalable(false);
+ });
+
+ inputManager.on(window, onInputCommand);
+ /* eslint-disable-next-line compat/compat */
+ document.addEventListener((window.PointerEvent ? 'pointermove' : 'mousemove'), onPointerMove);
+
+ dialog.addEventListener('close', onDialogClosed);
+
+ loadSwiper(dialog, options);
+ }
+
+ /**
+ * Handles OSD changes when the autoplay is started.
+ */
+ function onAutoplayStart() {
+ const btnSlideshowPause = dialog.querySelector('.btnSlideshowPause .material-icons');
+ if (btnSlideshowPause) {
+ btnSlideshowPause.classList.replace('play_arrow', 'pause');
+ }
+ }
+
+ /**
+ * Handles OSD changes when the autoplay is stopped.
+ */
+ function onAutoplayStop() {
+ const btnSlideshowPause = dialog.querySelector('.btnSlideshowPause .material-icons');
+ if (btnSlideshowPause) {
+ btnSlideshowPause.classList.replace('pause', 'play_arrow');
+ }
+ }
+
+ /**
+ * Handles zoom changes.
+ */
+ function onZoomChange(scale, imageEl, slideEl) {
+ const zoomImage = slideEl.querySelector('.swiper-zoom-fakeimg');
+
+ if (zoomImage) {
+ zoomImage.style.width = zoomImage.style.height = scale * 100 + '%';
+
+ if (scale > 1) {
+ if (zoomImage.classList.contains('swiper-zoom-fakeimg-hidden')) {
+ // Await for Swiper style changes
+ setTimeout(() => {
+ const callback = () => {
+ imageEl.removeEventListener(transitionEndEventName, callback);
+ zoomImage.classList.remove('swiper-zoom-fakeimg-hidden');
+ };
+
+ // Swiper set 'transition-duration: 300ms' for auto zoom
+ // and 'transition-duration: 0s' for touch zoom
+ const transitionDuration = parseFloat(imageEl.style.transitionDuration.replace(/[a-z]/i, ''));
+
+ if (transitionDuration > 0) {
+ imageEl.addEventListener(transitionEndEventName, callback);
+ } else {
+ callback();
+ }
+ }, 0);
+ }
+ } else {
+ zoomImage.classList.add('swiper-zoom-fakeimg-hidden');
+ }
+ }
+ }
+
+ /**
+ * Initializes the Swiper instance and binds the relevant events.
+ * @param {HTMLElement} dialog - Element containing the dialog.
+ * @param {Object} options - Options used to initialize the Swiper instance.
+ */
+ function loadSwiper(dialog, options) {
+ let slides;
+ if (currentOptions.slides) {
+ slides = currentOptions.slides;
+ } else {
+ slides = currentOptions.items;
+ }
+
+ import('swiper').then(({default: Swiper}) => {
+ swiperInstance = new Swiper(dialog.querySelector('.slideshowSwiperContainer'), {
+ direction: 'horizontal',
+ // Loop is disabled due to the virtual slides option not supporting it.
+ loop: false,
+ zoom: {
+ minRatio: 1,
+ toggle: true
+ },
+ autoplay: !options.interactive,
+ keyboard: {
+ enabled: true
+ },
+ preloadImages: true,
+ slidesPerView: 1,
+ slidesPerColumn: 1,
+ initialSlide: options.startIndex || 0,
+ speed: 240,
+ navigation: {
+ nextEl: '.btnSlideshowNext',
+ prevEl: '.btnSlideshowPrevious'
+ },
+ // Virtual slides reduce memory consumption for large libraries while allowing preloading of images;
+ virtual: {
+ slides: slides,
+ cache: true,
+ renderSlide: getSwiperSlideHtml,
+ addSlidesBefore: 1,
+ addSlidesAfter: 1
+ }
+ });
+
+ swiperInstance.on('autoplayStart', onAutoplayStart);
+ swiperInstance.on('autoplayStop', onAutoplayStop);
+
+ if (useFakeZoomImage) {
+ swiperInstance.on('zoomChange', onZoomChange);
+ }
+ });
+ }
+
+ /**
+ * Renders the HTML markup of a slide for an item or a slide.
+ * @param {Object} item - The item used to render the slide.
+ * @param {number} index - The index of the item in the Swiper instance.
+ * @returns {string} The HTML markup of the slide.
+ */
+ function getSwiperSlideHtml(item, index) {
+ if (currentOptions.slides) {
+ return getSwiperSlideHtmlFromSlide(item);
+ } else {
+ return getSwiperSlideHtmlFromItem(item);
+ }
+ }
+
+ /**
+ * Renders the HTML markup of a slide for an item.
+ * @param {Object} item - Item used to generate the slide.
+ * @returns {string} The HTML markup of the slide.
+ */
+ function getSwiperSlideHtmlFromItem(item) {
+ return getSwiperSlideHtmlFromSlide({
+ originalImage: getImgUrl(item, currentOptions.user),
+ Id: item.Id,
+ ServerId: item.ServerId
+ });
+ }
+
+ /**
+ * Renders the HTML markup of a slide for a slide object.
+ * @param {Object} item - Slide object used to generate the slide.
+ * @returns {string} The HTML markup of the slide.
+ */
+ function getSwiperSlideHtmlFromSlide(item) {
+ let html = '';
+ html += '
';
+ html += '
';
+ if (useFakeZoomImage) {
+ html += ``;
+ }
+ html += '';
+ html += '
';
+ if (item.title || item.subtitle) {
+ html += '
';
+ html += '
';
+ if (item.title) {
+ html += '
';
+ html += item.title;
+ html += '
';
+ }
+ if (item.description) {
+ html += '
';
+ html += item.description;
+ html += '
';
+ }
+ html += '
';
+ html += '
';
+ }
+ html += '
';
+
+ return html;
+ }
+
+ /**
+ * Fetches the information of the currently displayed slide.
+ * @returns {null|{itemId: string, shareUrl: string, serverId: string, url: string}} Object containing the information of the currently displayed slide.
+ */
+ function getCurrentImageInfo() {
+ if (swiperInstance) {
+ const slide = document.querySelector('.swiper-slide-active');
+
+ if (slide) {
+ return {
+ url: slide.getAttribute('data-original'),
+ shareUrl: slide.getAttribute('data-original'),
+ itemId: slide.getAttribute('data-itemid'),
+ serverId: slide.getAttribute('data-serverid')
+ };
+ }
+ return null;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Starts a download for the currently displayed slide.
+ */
+ function download() {
+ const imageInfo = getCurrentImageInfo();
+
+ import('fileDownloader').then(({default: fileDownloader}) => {
+ fileDownloader.download([imageInfo]);
+ });
+ }
+
+ /**
+ * Shares the currently displayed slide using the browser's built-in sharing feature.
+ */
+ function share() {
+ const imageInfo = getCurrentImageInfo();
+
+ navigator.share({
+ url: imageInfo.shareUrl
+ });
+ }
+
+ /**
+ * Starts the autoplay feature of the Swiper instance.
+ */
+ function play() {
+ if (swiperInstance.autoplay) {
+ swiperInstance.autoplay.start();
+ }
+ }
+
+ /**
+ * Pauses the autoplay feature of the Swiper instance;
+ */
+ function pause() {
+ if (swiperInstance.autoplay) {
+ swiperInstance.autoplay.stop();
+ }
+ }
+
+ /**
+ * Toggles the autoplay feature of the Swiper instance.
+ */
+ function playPause() {
+ const paused = !dialog.querySelector('.btnSlideshowPause .material-icons').classList.contains('pause');
+ if (paused) {
+ play();
+ } else {
+ pause();
+ }
+ }
+
+ /**
+ * Closes the dialog and destroys the Swiper instance.
+ */
+ function onDialogClosed() {
+ const swiper = swiperInstance;
+ if (swiper) {
+ swiper.destroy(true, true);
+ swiperInstance = null;
+ }
+
+ inputManager.off(window, onInputCommand);
+ /* eslint-disable-next-line compat/compat */
+ document.removeEventListener((window.PointerEvent ? 'pointermove' : 'mousemove'), onPointerMove);
+ // Shows page scrollbar
+ document.body.classList.remove('hide-scroll');
+ document.body.classList.add('force-scroll');
+ }
+
+ /**
+ * Shows the OSD.
+ */
+ function showOsd() {
+ const bottom = dialog.querySelector('.slideshowBottomBar');
+ if (bottom) {
+ slideUpToShow(bottom);
+ startHideTimer();
+ }
+ }
+
+ /**
+ * Hides the OSD.
+ */
+ function hideOsd() {
+ const bottom = dialog.querySelector('.slideshowBottomBar');
+ if (bottom) {
+ slideDownToHide(bottom);
+ }
+ }
+
+ /**
+ * Starts the timer used to automatically hide the OSD.
+ */
+ function startHideTimer() {
+ stopHideTimer();
+ hideTimeout = setTimeout(hideOsd, 3000);
+ }
+
+ /**
+ * Stops the timer used to automatically hide the OSD.
+ */
+ function stopHideTimer() {
+ if (hideTimeout) {
+ clearTimeout(hideTimeout);
+ hideTimeout = null;
+ }
+ }
+
+ /**
+ * Shows the OSD by sliding it into view.
+ * @param {HTMLElement} element - Element containing the OSD.
+ */
+ function slideUpToShow(element) {
+ if (!element.classList.contains('hide')) {
+ return;
+ }
+
+ element.classList.remove('hide');
+
+ const onFinish = function () {
+ focusManager.focus(element.querySelector('.btnSlideshowPause'));
};
+
+ if (!element.animate) {
+ onFinish();
+ return;
+ }
+
+ requestAnimationFrame(function () {
+ const keyframes = [
+ { transform: 'translate3d(0,' + element.offsetHeight + 'px,0)', opacity: '.3', offset: 0 },
+ { transform: 'translate3d(0,0,0)', opacity: '1', offset: 1 }
+ ];
+ const timing = { duration: 300, iterations: 1, easing: 'ease-out' };
+ element.animate(keyframes, timing).onfinish = onFinish;
+ });
+ }
+
+ /**
+ * Hides the OSD by sliding it out of view.
+ * @param {HTMLElement} element - Element containing the OSD.
+ */
+ function slideDownToHide(element) {
+ if (element.classList.contains('hide')) {
+ return;
+ }
+
+ const onFinish = function () {
+ element.classList.add('hide');
+ };
+
+ if (!element.animate) {
+ onFinish();
+ return;
+ }
+
+ requestAnimationFrame(function () {
+ const keyframes = [
+ { transform: 'translate3d(0,0,0)', opacity: '1', offset: 0 },
+ { transform: 'translate3d(0,' + element.offsetHeight + 'px,0)', opacity: '.3', offset: 1 }
+ ];
+ const timing = { duration: 300, iterations: 1, easing: 'ease-out' };
+ element.animate(keyframes, timing).onfinish = onFinish;
+ });
+ }
+
+ /**
+ * Shows the OSD when moving the mouse pointer or touching the screen.
+ * @param {Event} event - Pointer movement event.
+ */
+ function onPointerMove(event) {
+ const pointerType = event.pointerType || (layoutManager.mobile ? 'touch' : 'mouse');
+
+ if (pointerType === 'mouse') {
+ const eventX = event.screenX || 0;
+ const eventY = event.screenY || 0;
+
+ const obj = lastMouseMoveData;
+ if (!obj) {
+ lastMouseMoveData = {
+ x: eventX,
+ y: eventY
+ };
+ return;
+ }
+
+ // if coord are same, it didn't move
+ if (Math.abs(eventX - obj.x) < 10 && Math.abs(eventY - obj.y) < 10) {
+ return;
+ }
+
+ obj.x = eventX;
+ obj.y = eventY;
+
+ showOsd();
+ }
+ }
+
+ /**
+ * Dispatches keyboard inputs to their proper handlers.
+ * @param {Event} event - Keyboard input event.
+ */
+ function onInputCommand(event) {
+ switch (event.detail.command) {
+ case 'up':
+ case 'down':
+ case 'select':
+ case 'menu':
+ case 'info':
+ showOsd();
+ break;
+ case 'play':
+ play();
+ break;
+ case 'pause':
+ pause();
+ break;
+ case 'playpause':
+ playPause();
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Shows the slideshow component.
+ */
+ self.show = function () {
+ createElements(options);
+ // Hides page scrollbar
+ document.body.classList.remove('force-scroll');
+ document.body.classList.add('hide-scroll');
};
-});
+
+ /**
+ * Hides the slideshow element.
+ */
+ self.hide = function () {
+ if (dialog) {
+ dialogHelper.close(dialog);
+ }
+ };
+}
diff --git a/src/components/sortmenu/sortmenu.js b/src/components/sortmenu/sortmenu.js
index d1cea0c49..d38d98c09 100644
--- a/src/components/sortmenu/sortmenu.js
+++ b/src/components/sortmenu/sortmenu.js
@@ -1,49 +1,51 @@
-define(['require', 'dom', 'focusManager', 'dialogHelper', 'loading', 'layoutManager', 'connectionManager', 'globalize', 'userSettings', 'emby-select', 'paper-icon-button-light', 'material-icons', 'css!./../formdialog', 'emby-button', 'flexStyles'], function (require, dom, focusManager, dialogHelper, loading, layoutManager, connectionManager, globalize, userSettings) {
- 'use strict';
+import dialogHelper from 'dialogHelper';
+import layoutManager from 'layoutManager';
+import globalize from 'globalize';
+import * as userSettings from 'userSettings';
+import 'emby-select';
+import 'paper-icon-button-light';
+import 'material-icons';
+import 'css!./../formdialog';
+import 'emby-button';
+import 'flexStyles';
- focusManager = focusManager.default || focusManager;
+function onSubmit(e) {
+ e.preventDefault();
+ return false;
+}
- function onSubmit(e) {
- e.preventDefault();
- return false;
- }
+function initEditor(context, settings) {
+ context.querySelector('form').addEventListener('submit', onSubmit);
- function initEditor(context, settings) {
- context.querySelector('form').addEventListener('submit', onSubmit);
+ context.querySelector('.selectSortOrder').value = settings.sortOrder;
+ context.querySelector('.selectSortBy').value = settings.sortBy;
+}
- context.querySelector('.selectSortOrder').value = settings.sortOrder;
- context.querySelector('.selectSortBy').value = settings.sortBy;
- }
+function centerFocus(elem, horiz, on) {
+ import('scrollHelper').then(({default: scrollHelper}) => {
+ const fn = on ? 'on' : 'off';
+ scrollHelper.centerFocus[fn](elem, horiz);
+ });
+}
- function centerFocus(elem, horiz, on) {
- require(['scrollHelper'], function (scrollHelper) {
- scrollHelper = scrollHelper.default || scrollHelper;
- var fn = on ? 'on' : 'off';
- scrollHelper.centerFocus[fn](elem, horiz);
- });
- }
+function fillSortBy(context, options) {
+ const selectSortBy = context.querySelector('.selectSortBy');
- function fillSortBy(context, options) {
- var selectSortBy = context.querySelector('.selectSortBy');
+ selectSortBy.innerHTML = options.map(function (o) {
+ return '';
+ }).join('');
+}
- selectSortBy.innerHTML = options.map(function (o) {
- return '';
- }).join('');
- }
+function saveValues(context, settingsKey) {
+ userSettings.setFilter(settingsKey + '-sortorder', context.querySelector('.selectSortOrder').value);
+ userSettings.setFilter(settingsKey + '-sortby', context.querySelector('.selectSortBy').value);
+}
- function saveValues(context, settings, settingsKey) {
- userSettings.setFilter(settingsKey + '-sortorder', context.querySelector('.selectSortOrder').value);
- userSettings.setFilter(settingsKey + '-sortby', context.querySelector('.selectSortBy').value);
- }
-
- function SortMenu() {
-
- }
-
- SortMenu.prototype.show = function (options) {
+class SortMenu {
+ show(options) {
return new Promise(function (resolve, reject) {
- require(['text!./sortmenu.template.html'], function (template) {
- var dialogOptions = {
+ import('text!./sortmenu.template.html').then(({default: template}) => {
+ const dialogOptions = {
removeOnClose: true,
scrollY: false
};
@@ -54,11 +56,11 @@ define(['require', 'dom', 'focusManager', 'dialogHelper', 'loading', 'layoutMana
dialogOptions.size = 'small';
}
- var dlg = dialogHelper.createDialog(dialogOptions);
+ const dlg = dialogHelper.createDialog(dialogOptions);
dlg.classList.add('formDialog');
- var html = '';
+ let html = '';
html += '