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

Merge pull request #1733 from Camc314/migrate-to-ES6-52

Migration of viewManager to ES6 module
This commit is contained in:
dkanada 2020-08-07 14:17:17 +09:00 committed by GitHub
commit fde0fe0de4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 118 deletions

View file

@ -169,6 +169,7 @@
"src/components/syncPlay/playbackPermissionManager.js",
"src/components/syncPlay/syncPlayManager.js",
"src/components/syncPlay/timeSyncManager.js",
"src/components/viewManager/viewManager.js",
"src/components/tvproviders/schedulesdirect.js",
"src/components/tvproviders/xmltv.js",
"src/components/toast/toast.js",

View file

@ -1,6 +1,7 @@
define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdrop', 'browser', 'page', 'appSettings', 'apphost', 'connectionManager'], function (loading, globalize, events, viewManager, skinManager, backdrop, browser, page, appSettings, appHost, connectionManager) {
'use strict';
viewManager = viewManager.default || viewManager;
browser = browser.default || browser;
loading = loading.default || loading;

View file

@ -1,22 +1,22 @@
define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], function (viewContainer, focusManager, queryString, layoutManager) {
'use strict';
import viewContainer from 'viewContainer';
import focusManager from 'focusManager';
import queryString from 'queryString';
import layoutManager from 'layoutManager';
focusManager = focusManager.default || focusManager;
let currentView;
let dispatchPageEvents;
var currentView;
var dispatchPageEvents;
viewContainer.setOnBeforeChange(function (newView, isRestored, options) {
var lastView = currentView;
viewContainer.setOnBeforeChange(function (newView, isRestored, options) {
const lastView = currentView;
if (lastView) {
var beforeHideResult = dispatchViewEvent(lastView, null, 'viewbeforehide', true);
const beforeHideResult = dispatchViewEvent(lastView, null, 'viewbeforehide', true);
if (!beforeHideResult) {
// todo: cancel
}
}
var eventDetail = getViewEventDetail(newView, options, isRestored);
const eventDetail = getViewEventDetail(newView, options, isRestored);
if (!newView.initComplete) {
newView.initComplete = true;
@ -33,17 +33,17 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
}
dispatchViewEvent(newView, eventDetail, 'viewbeforeshow');
});
});
function onViewChange(view, options, isRestore) {
var lastView = currentView;
function onViewChange(view, options, isRestore) {
const lastView = currentView;
if (lastView) {
dispatchViewEvent(lastView, null, 'viewhide');
}
currentView = view;
var eventDetail = getViewEventDetail(view, options, isRestore);
const eventDetail = getViewEventDetail(view, options, isRestore);
if (!isRestore) {
if (options.autoFocus !== false) {
@ -62,19 +62,19 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
if (dispatchPageEvents) {
view.dispatchEvent(new CustomEvent('pageshow', eventDetail));
}
}
}
function getProperties(view) {
var props = view.getAttribute('data-properties');
function getProperties(view) {
const props = view.getAttribute('data-properties');
if (props) {
return props.split(',');
}
return [];
}
}
function dispatchViewEvent(view, eventInfo, eventName, isCancellable) {
function dispatchViewEvent(view, eventInfo, eventName, isCancellable) {
if (!eventInfo) {
eventInfo = {
detail: {
@ -88,7 +88,7 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
eventInfo.cancelable = isCancellable || false;
var eventResult = view.dispatchEvent(new CustomEvent(eventName, eventInfo));
const eventResult = view.dispatchEvent(new CustomEvent(eventName, eventInfo));
if (dispatchPageEvents) {
eventInfo.cancelable = false;
@ -96,12 +96,12 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
}
return eventResult;
}
}
function getViewEventDetail(view, options, isRestore) {
var url = options.url;
var index = url.indexOf('?');
var params = index === -1 ? {} : queryString.parse(url.substring(index + 1));
function getViewEventDetail(view, options, isRestore) {
const url = options.url;
const index = url.indexOf('?');
const params = index === -1 ? {} : queryString.parse(url.substring(index + 1));
return {
detail: {
@ -117,20 +117,18 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
bubbles: true,
cancelable: false
};
}
}
function resetCachedViews() {
function resetCachedViews() {
// Reset all cached views whenever the skin changes
viewContainer.reset();
}
}
document.addEventListener('skinunload', resetCachedViews);
document.addEventListener('skinunload', resetCachedViews);
function ViewManager() {
}
ViewManager.prototype.loadView = function (options) {
var lastView = currentView;
class ViewManager {
loadView(options) {
const lastView = currentView;
// Record the element that has focus
if (lastView) {
@ -144,9 +142,9 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
viewContainer.loadView(options).then(function (view) {
onViewChange(view, options);
});
};
}
ViewManager.prototype.tryRestoreView = function (options, onViewChanging) {
tryRestoreView(options, onViewChanging) {
if (options.cancel) {
return Promise.reject({ cancelled: true });
}
@ -160,15 +158,15 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
onViewChanging();
onViewChange(view, options, true);
});
};
}
ViewManager.prototype.currentView = function () {
currentView() {
return currentView;
};
}
ViewManager.prototype.dispatchPageEvents = function (value) {
dispatchPageEvents(value) {
dispatchPageEvents = value;
};
}
}
return new ViewManager();
});
export default new ViewManager();

View file

@ -1,6 +1,7 @@
define(['dom', 'layoutManager', 'inputManager', 'connectionManager', 'events', 'viewManager', 'libraryBrowser', 'appRouter', 'apphost', 'playbackManager', 'syncPlayManager', 'groupSelectionMenu', 'browser', 'globalize', 'scripts/imagehelper', 'paper-icon-button-light', 'material-icons', 'scrollStyles', 'flexStyles'], function (dom, layoutManager, inputManager, connectionManager, events, viewManager, libraryBrowser, appRouter, appHost, playbackManager, syncPlayManager, groupSelectionMenu, browser, globalize, imageHelper) {
'use strict';
viewManager = viewManager.default || viewManager;
playbackManager = playbackManager.default || playbackManager;
browser = browser.default || browser;

View file

@ -813,8 +813,8 @@ function initClient() {
define('tvguide', [componentsPath + '/guide/guide'], returnFirstDependency);
define('guide-settings-dialog', [componentsPath + '/guide/guide-settings'], returnFirstDependency);
define('viewManager', [componentsPath + '/viewManager/viewManager'], function (viewManager) {
window.ViewManager = viewManager;
viewManager.dispatchPageEvents(true);
window.ViewManager = viewManager.default;
viewManager.default.dispatchPageEvents(true);
return viewManager;
});
define('slideshow', [componentsPath + '/slideshow/slideshow'], returnFirstDependency);