mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Migration of viewManager to ES6 module
This commit is contained in:
parent
ade438f53d
commit
b082613ed9
5 changed files with 123 additions and 115 deletions
|
@ -158,6 +158,7 @@
|
||||||
"src/components/syncPlay/playbackPermissionManager.js",
|
"src/components/syncPlay/playbackPermissionManager.js",
|
||||||
"src/components/syncPlay/syncPlayManager.js",
|
"src/components/syncPlay/syncPlayManager.js",
|
||||||
"src/components/syncPlay/timeSyncManager.js",
|
"src/components/syncPlay/timeSyncManager.js",
|
||||||
|
"src/components/viewManager/viewManager.js",
|
||||||
"src/controllers/session/addServer/index.js",
|
"src/controllers/session/addServer/index.js",
|
||||||
"src/controllers/session/forgotPassword/index.js",
|
"src/controllers/session/forgotPassword/index.js",
|
||||||
"src/controllers/session/redeemPassword/index.js",
|
"src/controllers/session/redeemPassword/index.js",
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdrop', 'browser', 'page', 'appSettings', 'apphost', 'connectionManager'], function (loading, globalize, events, viewManager, skinManager, backdrop, browser, page, appSettings, appHost, connectionManager) {
|
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';
|
'use strict';
|
||||||
|
|
||||||
|
viewManager = viewManager.default || viewManager;
|
||||||
|
|
||||||
var appRouter = {
|
var appRouter = {
|
||||||
showLocalLogin: function (serverId, manualLogin) {
|
showLocalLogin: function (serverId, manualLogin) {
|
||||||
var pageName = manualLogin ? 'manuallogin' : 'login';
|
var pageName = manualLogin ? 'manuallogin' : 'login';
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], function (viewContainer, focusManager, queryString, layoutManager) {
|
import viewContainer from 'viewContainer';
|
||||||
'use strict';
|
import focusManager from 'focusManager';
|
||||||
|
import queryString from 'queryString';
|
||||||
|
import layoutManager from 'layoutManager';
|
||||||
|
|
||||||
var currentView;
|
let currentView;
|
||||||
var dispatchPageEvents;
|
let dispatchPageEvents;
|
||||||
|
|
||||||
viewContainer.setOnBeforeChange(function (newView, isRestored, options) {
|
viewContainer.setOnBeforeChange(function (newView, isRestored, options) {
|
||||||
var lastView = currentView;
|
const lastView = currentView;
|
||||||
if (lastView) {
|
if (lastView) {
|
||||||
var beforeHideResult = dispatchViewEvent(lastView, null, 'viewbeforehide', true);
|
const beforeHideResult = dispatchViewEvent(lastView, null, 'viewbeforehide', true);
|
||||||
|
|
||||||
if (!beforeHideResult) {
|
if (!beforeHideResult) {
|
||||||
// todo: cancel
|
// todo: cancel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var eventDetail = getViewEventDetail(newView, options, isRestored);
|
const eventDetail = getViewEventDetail(newView, options, isRestored);
|
||||||
|
|
||||||
if (!newView.initComplete) {
|
if (!newView.initComplete) {
|
||||||
newView.initComplete = true;
|
newView.initComplete = true;
|
||||||
|
@ -31,17 +33,17 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatchViewEvent(newView, eventDetail, 'viewbeforeshow');
|
dispatchViewEvent(newView, eventDetail, 'viewbeforeshow');
|
||||||
});
|
});
|
||||||
|
|
||||||
function onViewChange(view, options, isRestore) {
|
function onViewChange(view, options, isRestore) {
|
||||||
var lastView = currentView;
|
const lastView = currentView;
|
||||||
if (lastView) {
|
if (lastView) {
|
||||||
dispatchViewEvent(lastView, null, 'viewhide');
|
dispatchViewEvent(lastView, null, 'viewhide');
|
||||||
}
|
}
|
||||||
|
|
||||||
currentView = view;
|
currentView = view;
|
||||||
|
|
||||||
var eventDetail = getViewEventDetail(view, options, isRestore);
|
const eventDetail = getViewEventDetail(view, options, isRestore);
|
||||||
|
|
||||||
if (!isRestore) {
|
if (!isRestore) {
|
||||||
if (options.autoFocus !== false) {
|
if (options.autoFocus !== false) {
|
||||||
|
@ -60,19 +62,19 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
|
||||||
if (dispatchPageEvents) {
|
if (dispatchPageEvents) {
|
||||||
view.dispatchEvent(new CustomEvent('pageshow', eventDetail));
|
view.dispatchEvent(new CustomEvent('pageshow', eventDetail));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProperties(view) {
|
function getProperties(view) {
|
||||||
var props = view.getAttribute('data-properties');
|
const props = view.getAttribute('data-properties');
|
||||||
|
|
||||||
if (props) {
|
if (props) {
|
||||||
return props.split(',');
|
return props.split(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispatchViewEvent(view, eventInfo, eventName, isCancellable) {
|
function dispatchViewEvent(view, eventInfo, eventName, isCancellable) {
|
||||||
if (!eventInfo) {
|
if (!eventInfo) {
|
||||||
eventInfo = {
|
eventInfo = {
|
||||||
detail: {
|
detail: {
|
||||||
|
@ -86,7 +88,7 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
|
||||||
|
|
||||||
eventInfo.cancelable = isCancellable || false;
|
eventInfo.cancelable = isCancellable || false;
|
||||||
|
|
||||||
var eventResult = view.dispatchEvent(new CustomEvent(eventName, eventInfo));
|
const eventResult = view.dispatchEvent(new CustomEvent(eventName, eventInfo));
|
||||||
|
|
||||||
if (dispatchPageEvents) {
|
if (dispatchPageEvents) {
|
||||||
eventInfo.cancelable = false;
|
eventInfo.cancelable = false;
|
||||||
|
@ -94,12 +96,12 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventResult;
|
return eventResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViewEventDetail(view, options, isRestore) {
|
function getViewEventDetail(view, options, isRestore) {
|
||||||
var url = options.url;
|
const url = options.url;
|
||||||
var index = url.indexOf('?');
|
const index = url.indexOf('?');
|
||||||
var params = index === -1 ? {} : queryString.parse(url.substring(index + 1));
|
const params = index === -1 ? {} : queryString.parse(url.substring(index + 1));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
detail: {
|
detail: {
|
||||||
|
@ -115,20 +117,21 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
cancelable: false
|
cancelable: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetCachedViews() {
|
function resetCachedViews() {
|
||||||
// Reset all cached views whenever the skin changes
|
// Reset all cached views whenever the skin changes
|
||||||
viewContainer.reset();
|
viewContainer.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('skinunload', resetCachedViews);
|
||||||
|
|
||||||
|
class ViewManager {
|
||||||
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('skinunload', resetCachedViews);
|
loadView(options) {
|
||||||
|
const lastView = currentView;
|
||||||
function ViewManager() {
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewManager.prototype.loadView = function (options) {
|
|
||||||
var lastView = currentView;
|
|
||||||
|
|
||||||
// Record the element that has focus
|
// Record the element that has focus
|
||||||
if (lastView) {
|
if (lastView) {
|
||||||
|
@ -142,9 +145,9 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
|
||||||
viewContainer.loadView(options).then(function (view) {
|
viewContainer.loadView(options).then(function (view) {
|
||||||
onViewChange(view, options);
|
onViewChange(view, options);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
ViewManager.prototype.tryRestoreView = function (options, onViewChanging) {
|
tryRestoreView(options, onViewChanging) {
|
||||||
if (options.cancel) {
|
if (options.cancel) {
|
||||||
return Promise.reject({ cancelled: true });
|
return Promise.reject({ cancelled: true });
|
||||||
}
|
}
|
||||||
|
@ -158,15 +161,15 @@ define(['viewContainer', 'focusManager', 'queryString', 'layoutManager'], functi
|
||||||
onViewChanging();
|
onViewChanging();
|
||||||
onViewChange(view, options, true);
|
onViewChange(view, options, true);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
ViewManager.prototype.currentView = function () {
|
currentView() {
|
||||||
return currentView;
|
return currentView;
|
||||||
};
|
}
|
||||||
|
|
||||||
ViewManager.prototype.dispatchPageEvents = function (value) {
|
dispatchPageEvents(value) {
|
||||||
dispatchPageEvents = value;
|
dispatchPageEvents = value;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new ViewManager();
|
export default new ViewManager();
|
||||||
});
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
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) {
|
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';
|
'use strict';
|
||||||
|
|
||||||
|
viewManager = viewManager.default || viewManager;
|
||||||
|
|
||||||
function renderHeader() {
|
function renderHeader() {
|
||||||
var html = '';
|
var html = '';
|
||||||
html += '<div class="flex align-items-center flex-grow headerTop">';
|
html += '<div class="flex align-items-center flex-grow headerTop">';
|
||||||
|
|
|
@ -827,8 +827,8 @@ function initClient() {
|
||||||
define('tvguide', [componentsPath + '/guide/guide'], returnFirstDependency);
|
define('tvguide', [componentsPath + '/guide/guide'], returnFirstDependency);
|
||||||
define('guide-settings-dialog', [componentsPath + '/guide/guide-settings'], returnFirstDependency);
|
define('guide-settings-dialog', [componentsPath + '/guide/guide-settings'], returnFirstDependency);
|
||||||
define('viewManager', [componentsPath + '/viewManager/viewManager'], function (viewManager) {
|
define('viewManager', [componentsPath + '/viewManager/viewManager'], function (viewManager) {
|
||||||
window.ViewManager = viewManager;
|
window.ViewManager = viewManager.default;
|
||||||
viewManager.dispatchPageEvents(true);
|
viewManager.default.dispatchPageEvents(true);
|
||||||
return viewManager;
|
return viewManager;
|
||||||
});
|
});
|
||||||
define('slideshow', [componentsPath + '/slideshow/slideshow'], returnFirstDependency);
|
define('slideshow', [componentsPath + '/slideshow/slideshow'], returnFirstDependency);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue