2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Image viewer component
|
|
|
|
* @module components/slideshow/slideshow
|
|
|
|
*/
|
2020-05-07 23:11:19 +03:00
|
|
|
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) {
|
2019-01-10 15:39:37 +03:00
|
|
|
'use strict';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-05-07 23:11:19 +03:00
|
|
|
/**
|
|
|
|
* Name of transition event.
|
|
|
|
*/
|
|
|
|
const transitionEndEventName = dom.whichTransitionEvent();
|
|
|
|
|
2020-05-08 01:23:17 +03:00
|
|
|
/**
|
|
|
|
* Flag to use fake image to fix blurry zoomed image.
|
|
|
|
* At least WebKit doesn't restore quality for zoomed images.
|
|
|
|
*/
|
|
|
|
const useFakeZoomImage = browser.safari;
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function getImageUrl(item, options, apiClient) {
|
2019-01-10 15:39:37 +03:00
|
|
|
options = options || {};
|
2020-05-04 12:44:12 +02:00
|
|
|
options.type = options.type || 'Primary';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function getBackdropImageUrl(item, options, apiClient) {
|
2019-01-10 15:39:37 +03:00
|
|
|
options = options || {};
|
2020-05-04 12:44:12 +02:00
|
|
|
options.type = options.type || 'Backdrop';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
// 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;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-05-02 02:28:58 +05:30
|
|
|
function getImgUrl(item, user) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var apiClient = connectionManager.getApiClient(item.ServerId);
|
|
|
|
var imageOptions = {};
|
|
|
|
|
|
|
|
if (item.BackdropImageTags && item.BackdropImageTags.length) {
|
|
|
|
return getBackdropImageUrl(item, imageOptions, apiClient);
|
|
|
|
} else {
|
2020-05-03 03:20:40 +05:30
|
|
|
if (item.MediaType === 'Photo' && user && user.Policy.EnableContentDownloading) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return apiClient.getItemDownloadUrl(item.Id);
|
|
|
|
}
|
2020-05-04 12:44:12 +02:00
|
|
|
imageOptions.type = 'Primary';
|
2019-01-10 15:39:37 +03:00
|
|
|
return getImageUrl(item, imageOptions, apiClient);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function getIcon(icon, cssClass, canFocus, autoFocus) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var tabIndex = canFocus ? '' : ' tabindex="-1"';
|
|
|
|
autoFocus = autoFocus ? ' autofocus' : '';
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<button is="paper-icon-button-light" class="autoSize ' + cssClass + '"' + tabIndex + autoFocus + '><span class="material-icons slideshowButtonIcon ' + icon + '"></span></button>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Sets the viewport meta tag to enable or disable scaling by the user.
|
|
|
|
* @param {boolean} scalable - Flag to set the scalability of the viewport.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function setUserScalable(scalable) {
|
|
|
|
try {
|
2019-01-10 15:39:37 +03:00
|
|
|
appHost.setUserScalable(scalable);
|
2019-11-23 00:29:38 +09:00
|
|
|
} catch (err) {
|
2020-02-16 03:44:43 +01:00
|
|
|
console.error('error in appHost.setUserScalable: ' + err);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return function (options) {
|
|
|
|
var self = this;
|
2020-03-22 15:34:34 +01:00
|
|
|
/** Initialized instance of Swiper. */
|
2019-01-10 15:39:37 +03:00
|
|
|
var swiperInstance;
|
2020-03-22 15:34:34 +01:00
|
|
|
/** Initialized instance of the dialog containing the Swiper instance. */
|
|
|
|
var dialog;
|
|
|
|
/** Options of the slideshow components */
|
2019-01-10 15:39:37 +03:00
|
|
|
var currentOptions;
|
2020-03-22 15:34:34 +01:00
|
|
|
/** ID of the timeout used to hide the OSD. */
|
|
|
|
var hideTimeout;
|
|
|
|
/** Last coordinates of the mouse pointer. */
|
|
|
|
var lastMouseMoveData;
|
|
|
|
/** Visibility status of the OSD. */
|
2020-03-21 23:45:23 +01:00
|
|
|
var _osdOpen = false;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
// Use autoplay on Chromecast since it is non-interactive.
|
2020-05-04 20:38:12 +03:00
|
|
|
if (browser.chromecast) options.interactive = false;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Creates the HTML markup for the dialog and the OSD.
|
|
|
|
* @param {Object} options - Options used to create the dialog and slideshow.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function createElements(options) {
|
2020-03-21 23:45:23 +01:00
|
|
|
currentOptions = options;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
dialog = dialogHelper.createDialog({
|
2018-10-23 01:05:09 +03:00
|
|
|
exitAnimationDuration: options.interactive ? 400 : 800,
|
2019-01-10 15:39:37 +03:00
|
|
|
size: 'fullscreen',
|
|
|
|
autoFocus: false,
|
|
|
|
scrollY: false,
|
|
|
|
exitAnimation: 'fadeout',
|
|
|
|
removeOnClose: true
|
|
|
|
});
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
dialog.classList.add('slideshowDialog');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
2020-04-04 00:22:31 +02:00
|
|
|
html += '<div class="slideshowSwiperContainer"><div class="swiper-wrapper"></div></div>';
|
|
|
|
|
|
|
|
if (options.interactive && !layoutManager.tv) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var actionButtonsOnTop = layoutManager.mobile;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
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 += '<div class="topActionButtons">';
|
|
|
|
if (actionButtonsOnTop) {
|
2020-05-03 03:20:40 +05:30
|
|
|
if (appHost.supports('filedownload') && options.user && options.user.Policy.EnableContentDownloading) {
|
2019-01-10 15:39:37 +03:00
|
|
|
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 += '</div>';
|
|
|
|
|
|
|
|
if (!actionButtonsOnTop) {
|
|
|
|
html += '<div class="slideshowBottomBar hide">';
|
2020-05-02 02:28:58 +05:30
|
|
|
|
2020-03-21 23:45:23 +01:00
|
|
|
html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true, true);
|
2020-05-03 03:20:40 +05:30
|
|
|
if (appHost.supports('filedownload') && options.user && options.user.Policy.EnableContentDownloading) {
|
2019-01-10 15:39:37 +03:00
|
|
|
html += getIcon('file_download', 'btnDownload slideshowButton', true);
|
|
|
|
}
|
|
|
|
if (appHost.supports('sharing')) {
|
|
|
|
html += getIcon('share', 'btnShare slideshowButton', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
html += '<div class="slideshowImage"></div><h1 class="slideshowImageText"></h1>';
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
dialog.innerHTML = html;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-04 00:22:31 +02:00
|
|
|
if (options.interactive && !layoutManager.tv) {
|
2020-03-22 15:34:34 +01:00
|
|
|
dialog.querySelector('.btnSlideshowExit').addEventListener('click', function (e) {
|
|
|
|
dialogHelper.close(dialog);
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
var btnPause = dialog.querySelector('.btnSlideshowPause');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (btnPause) {
|
|
|
|
btnPause.addEventListener('click', playPause);
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
var btnDownload = dialog.querySelector('.btnDownload');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (btnDownload) {
|
|
|
|
btnDownload.addEventListener('click', download);
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
var btnShare = dialog.querySelector('.btnShare');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (btnShare) {
|
|
|
|
btnShare.addEventListener('click', share);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setUserScalable(true);
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
dialogHelper.open(dialog).then(function () {
|
2019-01-10 15:39:37 +03:00
|
|
|
setUserScalable(false);
|
|
|
|
});
|
|
|
|
|
2019-10-03 02:36:33 +09:00
|
|
|
inputManager.on(window, onInputCommand);
|
2019-01-10 15:39:37 +03:00
|
|
|
document.addEventListener((window.PointerEvent ? 'pointermove' : 'mousemove'), onPointerMove);
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
dialog.addEventListener('close', onDialogClosed);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-04 00:22:31 +02:00
|
|
|
loadSwiper(dialog, options);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Handles OSD changes when the autoplay is started.
|
|
|
|
*/
|
2020-02-23 11:48:01 +03:00
|
|
|
function onAutoplayStart() {
|
2020-04-26 02:37:28 +03:00
|
|
|
var btnSlideshowPause = dialog.querySelector('.btnSlideshowPause .material-icons');
|
2020-02-23 11:48:01 +03:00
|
|
|
if (btnSlideshowPause) {
|
2020-05-04 12:44:12 +02:00
|
|
|
btnSlideshowPause.classList.replace('play_arrow', 'pause');
|
2020-02-23 11:48:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Handles OSD changes when the autoplay is stopped.
|
|
|
|
*/
|
2020-02-23 11:48:01 +03:00
|
|
|
function onAutoplayStop() {
|
2020-04-26 02:37:28 +03:00
|
|
|
var btnSlideshowPause = dialog.querySelector('.btnSlideshowPause .material-icons');
|
2020-02-23 11:48:01 +03:00
|
|
|
if (btnSlideshowPause) {
|
2020-05-04 12:44:12 +02:00
|
|
|
btnSlideshowPause.classList.replace('pause', 'play_arrow');
|
2020-02-23 11:48:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 23:11:19 +03:00
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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) {
|
2020-03-21 23:45:23 +01:00
|
|
|
var slides;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (currentOptions.slides) {
|
2020-03-21 23:45:23 +01:00
|
|
|
slides = currentOptions.slides;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
2020-03-21 23:45:23 +01:00
|
|
|
slides = currentOptions.items;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2019-10-09 14:04:23 -04:00
|
|
|
require(['swiper'], function (Swiper) {
|
2020-03-22 15:34:34 +01:00
|
|
|
swiperInstance = new Swiper(dialog.querySelector('.slideshowSwiperContainer'), {
|
2019-01-10 15:39:37 +03:00
|
|
|
direction: 'horizontal',
|
2020-04-04 00:22:31 +02:00
|
|
|
// Loop is disabled due to the virtual slides option not supporting it.
|
2020-03-21 23:45:23 +01:00
|
|
|
loop: false,
|
2020-04-22 15:50:33 -04:00
|
|
|
zoom: {
|
|
|
|
minRatio: 1,
|
2020-05-07 09:45:49 +03:00
|
|
|
toggle: true
|
2020-04-22 15:50:33 -04:00
|
|
|
},
|
2020-04-04 00:22:31 +02:00
|
|
|
autoplay: !options.interactive,
|
2020-03-21 23:45:23 +01:00
|
|
|
keyboard: {
|
|
|
|
enabled: true
|
2020-02-09 13:39:19 +01:00
|
|
|
},
|
2020-03-21 23:45:23 +01:00
|
|
|
preloadImages: true,
|
|
|
|
slidesPerView: 1,
|
|
|
|
slidesPerColumn: 1,
|
2018-10-23 01:05:09 +03:00
|
|
|
initialSlide: options.startIndex || 0,
|
2020-03-21 23:45:23 +01:00
|
|
|
speed: 240,
|
|
|
|
navigation: {
|
|
|
|
nextEl: '.btnSlideshowNext',
|
|
|
|
prevEl: '.btnSlideshowPrevious'
|
|
|
|
},
|
2020-04-04 00:22:31 +02:00
|
|
|
// Virtual slides reduce memory consumption for large libraries while allowing preloading of images;
|
2020-03-21 23:45:23 +01:00
|
|
|
virtual: {
|
|
|
|
slides: slides,
|
|
|
|
cache: true,
|
|
|
|
renderSlide: getSwiperSlideHtml,
|
|
|
|
addSlidesBefore: 1,
|
|
|
|
addSlidesAfter: 1
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
|
2020-02-23 11:48:01 +03:00
|
|
|
swiperInstance.on('autoplayStart', onAutoplayStart);
|
|
|
|
swiperInstance.on('autoplayStop', onAutoplayStop);
|
2020-05-08 01:23:17 +03:00
|
|
|
|
|
|
|
if (useFakeZoomImage) {
|
|
|
|
swiperInstance.on('zoomChange', onZoomChange);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-03-21 23:45:23 +01:00
|
|
|
function getSwiperSlideHtml(item, index) {
|
|
|
|
if (currentOptions.slides) {
|
|
|
|
return getSwiperSlideHtmlFromSlide(item);
|
|
|
|
} else {
|
|
|
|
return getSwiperSlideHtmlFromItem(item);
|
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-03-21 23:45:23 +01:00
|
|
|
function getSwiperSlideHtmlFromItem(item) {
|
2018-10-23 01:05:09 +03:00
|
|
|
return getSwiperSlideHtmlFromSlide({
|
2020-05-02 02:28:58 +05:30
|
|
|
originalImage: getImgUrl(item, currentOptions.user),
|
2019-01-10 15:39:37 +03:00
|
|
|
//title: item.Name,
|
|
|
|
//description: item.Overview
|
2018-10-23 01:05:09 +03:00
|
|
|
Id: item.Id,
|
|
|
|
ServerId: item.ServerId
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function getSwiperSlideHtmlFromSlide(item) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var html = '';
|
2020-03-21 23:45:23 +01:00
|
|
|
html += '<div class="swiper-slide" data-original="' + item.originalImage + '" data-itemid="' + item.Id + '" data-serverid="' + item.ServerId + '">';
|
2020-05-07 09:45:49 +03:00
|
|
|
html += '<div class="swiper-zoom-container">';
|
2020-05-08 01:23:17 +03:00
|
|
|
if (useFakeZoomImage) {
|
|
|
|
html += `<div class="swiper-zoom-fakeimg swiper-zoom-fakeimg-hidden" style="background-image: url('${item.originalImage}')"></div>`;
|
|
|
|
}
|
2020-03-21 23:45:23 +01:00
|
|
|
html += '<img src="' + item.originalImage + '" class="swiper-slide-img">';
|
|
|
|
html += '</div>';
|
2019-01-10 15:39:37 +03:00
|
|
|
if (item.title || item.subtitle) {
|
|
|
|
html += '<div class="slideText">';
|
|
|
|
html += '<div class="slideTextInner">';
|
|
|
|
if (item.title) {
|
|
|
|
html += '<h1 class="slideTitle">';
|
|
|
|
html += item.title;
|
|
|
|
html += '</h1>';
|
|
|
|
}
|
|
|
|
if (item.description) {
|
|
|
|
html += '<div class="slideSubtitle">';
|
|
|
|
html += item.description;
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
return html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function getCurrentImageInfo() {
|
|
|
|
if (swiperInstance) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var slide = document.querySelector('.swiper-slide-active');
|
|
|
|
|
|
|
|
if (slide) {
|
|
|
|
return {
|
|
|
|
url: slide.getAttribute('data-original'),
|
2020-03-21 23:45:23 +01:00
|
|
|
shareUrl: slide.getAttribute('data-original'),
|
2019-01-10 15:39:37 +03:00
|
|
|
itemId: slide.getAttribute('data-itemid'),
|
|
|
|
serverId: slide.getAttribute('data-serverid')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return null;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Starts a download for the currently displayed slide.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function download() {
|
|
|
|
var imageInfo = getCurrentImageInfo();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
require(['fileDownloader'], function (fileDownloader) {
|
|
|
|
fileDownloader.download([imageInfo]);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Shares the currently displayed slide using the browser's built-in sharing feature.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function share() {
|
|
|
|
var imageInfo = getCurrentImageInfo();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
navigator.share({
|
|
|
|
url: imageInfo.shareUrl
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Starts the autoplay feature of the Swiper instance.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function play() {
|
2020-02-23 10:52:03 +03:00
|
|
|
if (swiperInstance.autoplay) {
|
|
|
|
swiperInstance.autoplay.start();
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Pauses the autoplay feature of the Swiper instance;
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function pause() {
|
2020-02-23 10:52:03 +03:00
|
|
|
if (swiperInstance.autoplay) {
|
|
|
|
swiperInstance.autoplay.stop();
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Toggles the autoplay feature of the Swiper instance.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function playPause() {
|
2020-05-04 12:44:12 +02:00
|
|
|
var paused = !dialog.querySelector('.btnSlideshowPause .material-icons').classList.contains('pause');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (paused) {
|
|
|
|
play();
|
|
|
|
} else {
|
|
|
|
pause();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Closes the dialog and destroys the Swiper instance.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function onDialogClosed() {
|
|
|
|
var swiper = swiperInstance;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (swiper) {
|
|
|
|
swiper.destroy(true, true);
|
|
|
|
swiperInstance = null;
|
|
|
|
}
|
|
|
|
|
2019-10-03 02:36:33 +09:00
|
|
|
inputManager.off(window, onInputCommand);
|
2019-01-10 15:39:37 +03:00
|
|
|
document.removeEventListener((window.PointerEvent ? 'pointermove' : 'mousemove'), onPointerMove);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Shows the OSD.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function showOsd() {
|
2020-03-22 15:34:34 +01:00
|
|
|
var bottom = dialog.querySelector('.slideshowBottomBar');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (bottom) {
|
|
|
|
slideUpToShow(bottom);
|
|
|
|
startHideTimer();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Hides the OSD.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function hideOsd() {
|
2020-03-22 15:34:34 +01:00
|
|
|
var bottom = dialog.querySelector('.slideshowBottomBar');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (bottom) {
|
|
|
|
slideDownToHide(bottom);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Starts the timer used to automatically hide the OSD.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function startHideTimer() {
|
2019-01-10 15:39:37 +03:00
|
|
|
stopHideTimer();
|
2020-03-22 15:34:34 +01:00
|
|
|
hideTimeout = setTimeout(hideOsd, 3000);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Stops the timer used to automatically hide the OSD.
|
|
|
|
*/
|
2018-10-23 01:05:09 +03:00
|
|
|
function stopHideTimer() {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (hideTimeout) {
|
|
|
|
clearTimeout(hideTimeout);
|
|
|
|
hideTimeout = null;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Shows the OSD by sliding it into view.
|
|
|
|
* @param {HTMLElement} element - Element containing the OSD.
|
|
|
|
*/
|
|
|
|
function slideUpToShow(element) {
|
|
|
|
if (!element.classList.contains('hide')) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_osdOpen = true;
|
2020-03-22 15:34:34 +01:00
|
|
|
element.classList.remove('hide');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var onFinish = function () {
|
2020-03-22 15:34:34 +01:00
|
|
|
focusManager.focus(element.querySelector('.btnSlideshowPause'));
|
2019-01-10 15:39:37 +03:00
|
|
|
};
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
if (!element.animate) {
|
2019-01-10 15:39:37 +03:00
|
|
|
onFinish();
|
|
|
|
return;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
requestAnimationFrame(function () {
|
|
|
|
var keyframes = [
|
2020-03-22 15:34:34 +01:00
|
|
|
{ transform: 'translate3d(0,' + element.offsetHeight + 'px,0)', opacity: '.3', offset: 0 },
|
2019-01-10 15:39:37 +03:00
|
|
|
{ transform: 'translate3d(0,0,0)', opacity: '1', offset: 1 }
|
|
|
|
];
|
|
|
|
var timing = { duration: 300, iterations: 1, easing: 'ease-out' };
|
2020-03-22 15:34:34 +01:00
|
|
|
element.animate(keyframes, timing).onfinish = onFinish;
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Hides the OSD by sliding it out of view.
|
|
|
|
* @param {HTMLElement} element - Element containing the OSD.
|
|
|
|
*/
|
|
|
|
function slideDownToHide(element) {
|
|
|
|
if (element.classList.contains('hide')) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var onFinish = function () {
|
2020-03-22 15:34:34 +01:00
|
|
|
element.classList.add('hide');
|
2019-01-10 15:39:37 +03:00
|
|
|
_osdOpen = false;
|
|
|
|
};
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
if (!element.animate) {
|
2019-01-10 15:39:37 +03:00
|
|
|
onFinish();
|
|
|
|
return;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
requestAnimationFrame(function () {
|
|
|
|
var keyframes = [
|
|
|
|
{ transform: 'translate3d(0,0,0)', opacity: '1', offset: 0 },
|
2020-03-22 15:34:34 +01:00
|
|
|
{ transform: 'translate3d(0,' + element.offsetHeight + 'px,0)', opacity: '.3', offset: 1 }
|
2019-01-10 15:39:37 +03:00
|
|
|
];
|
|
|
|
var timing = { duration: 300, iterations: 1, easing: 'ease-out' };
|
2020-03-22 15:34:34 +01:00
|
|
|
element.animate(keyframes, timing).onfinish = onFinish;
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* 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');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (pointerType === 'mouse') {
|
2020-03-22 15:34:34 +01:00
|
|
|
var eventX = event.screenX || 0;
|
|
|
|
var eventY = event.screenY || 0;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
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();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Dispatches keyboard inputs to their proper handlers.
|
|
|
|
* @param {Event} event - Keyboard input event.
|
|
|
|
*/
|
|
|
|
function onInputCommand(event) {
|
|
|
|
switch (event.detail.command) {
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'up':
|
|
|
|
case 'down':
|
|
|
|
case 'select':
|
|
|
|
case 'menu':
|
|
|
|
case 'info':
|
2020-03-22 15:34:34 +01:00
|
|
|
showOsd();
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'play':
|
2020-03-22 15:34:34 +01:00
|
|
|
play();
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'pause':
|
2020-03-22 15:34:34 +01:00
|
|
|
pause();
|
|
|
|
break;
|
|
|
|
case 'playpause':
|
|
|
|
playPause();
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
default:
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Shows the slideshow component.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
self.show = function () {
|
2020-03-21 23:45:23 +01:00
|
|
|
createElements(options);
|
2019-01-10 15:39:37 +03:00
|
|
|
};
|
|
|
|
|
2020-03-22 15:34:34 +01:00
|
|
|
/**
|
|
|
|
* Hides the slideshow element.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
self.hide = function () {
|
|
|
|
if (dialog) {
|
|
|
|
dialogHelper.close(dialog);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2020-02-22 11:47:03 -05:00
|
|
|
});
|