mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
use shared viewmanager
This commit is contained in:
parent
aa35c3ef4c
commit
2807ef810f
5 changed files with 160 additions and 10 deletions
|
@ -16,12 +16,12 @@
|
|||
},
|
||||
"devDependencies": {},
|
||||
"ignore": [],
|
||||
"version": "1.1.47",
|
||||
"_release": "1.1.47",
|
||||
"version": "1.1.48",
|
||||
"_release": "1.1.48",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "1.1.47",
|
||||
"commit": "476832cea8f424a2cb15eee0f27fa4750619c1fb"
|
||||
"tag": "1.1.48",
|
||||
"commit": "1301ee3681a29577ba045c0ce20fd0e914cee168"
|
||||
},
|
||||
"_source": "git://github.com/MediaBrowser/emby-webcomponents.git",
|
||||
"_target": "~1.1.5",
|
||||
|
|
149
dashboard-ui/bower_components/emby-webcomponents/viewmanager.js
vendored
Normal file
149
dashboard-ui/bower_components/emby-webcomponents/viewmanager.js
vendored
Normal file
|
@ -0,0 +1,149 @@
|
|||
define(['viewcontainer', 'focusManager', 'queryString'], function (viewcontainer, focusManager, queryString) {
|
||||
|
||||
var currentView;
|
||||
|
||||
viewcontainer.setOnBeforeChange(function (newView, isRestored, options) {
|
||||
|
||||
var lastView = currentView;
|
||||
if (lastView) {
|
||||
dispatchViewEvent(lastView, 'viewbeforehide');
|
||||
}
|
||||
|
||||
if (!newView.initComplete) {
|
||||
newView.initComplete = true;
|
||||
|
||||
var eventDetail = getViewEventDetail(newView, options, false);
|
||||
|
||||
if (options.controllerFactory) {
|
||||
|
||||
// Use controller method
|
||||
var controller = new options.controllerFactory(newView, eventDetail.detail.params);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dispatchViewEvent(newView, 'viewbeforeshow', isRestored);
|
||||
});
|
||||
|
||||
function onViewChange(view, options, isRestore) {
|
||||
|
||||
var viewType = options.type;
|
||||
|
||||
var lastView = currentView;
|
||||
if (lastView) {
|
||||
dispatchViewEvent(lastView, 'viewhide');
|
||||
}
|
||||
|
||||
currentView = view;
|
||||
|
||||
var eventDetail = getViewEventDetail(view, options, isRestore);
|
||||
|
||||
if (!isRestore) {
|
||||
focusManager.autoFocus(view);
|
||||
}
|
||||
else if (view.activeElement) {
|
||||
view.activeElement.focus();
|
||||
}
|
||||
|
||||
view.dispatchEvent(new CustomEvent("viewshow", eventDetail));
|
||||
}
|
||||
|
||||
function dispatchViewEvent(view, eventName, isRestored) {
|
||||
|
||||
view.dispatchEvent(new CustomEvent(eventName, {
|
||||
detail: {
|
||||
type: view.getAttribute('data-type'),
|
||||
isRestored: isRestored
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: false
|
||||
}));
|
||||
}
|
||||
|
||||
function getViewEventDetail(view, options, isRestore) {
|
||||
|
||||
var url = options.url;
|
||||
var state = options.state;
|
||||
var index = url.indexOf('?');
|
||||
var params = index == -1 ? {} : queryString.parse(url.substring(index + 1));
|
||||
|
||||
return {
|
||||
detail: {
|
||||
type: view.getAttribute('data-type'),
|
||||
params: params,
|
||||
isRestored: isRestore,
|
||||
state: options.state,
|
||||
|
||||
// The route options
|
||||
options: options.options || {}
|
||||
},
|
||||
bubbles: true,
|
||||
cancelable: false
|
||||
};
|
||||
}
|
||||
|
||||
function resetCachedViews() {
|
||||
// Reset all cached views whenever the skin changes
|
||||
viewcontainer.reset();
|
||||
}
|
||||
|
||||
document.addEventListener('skinunload', resetCachedViews);
|
||||
document.addEventListener('usersignedin', resetCachedViews);
|
||||
document.addEventListener('usersignedout', resetCachedViews);
|
||||
|
||||
function tryRestoreInternal(viewcontainer, options, resolve, reject) {
|
||||
|
||||
if (options.cancel) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewcontainer.tryRestoreView(options).then(function (view) {
|
||||
|
||||
onViewChange(view, options, true);
|
||||
resolve();
|
||||
|
||||
}, reject);
|
||||
}
|
||||
|
||||
function ViewManager() {
|
||||
|
||||
var self = this;
|
||||
|
||||
self.loadView = function (options) {
|
||||
|
||||
var lastView = currentView;
|
||||
|
||||
// Record the element that has focus
|
||||
if (lastView) {
|
||||
lastView.activeElement = document.activeElement;
|
||||
}
|
||||
|
||||
if (options.cancel) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewcontainer.loadView(options).then(function (view) {
|
||||
|
||||
onViewChange(view, options);
|
||||
});
|
||||
};
|
||||
|
||||
self.tryRestoreView = function (options) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
if (options.cancel) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Record the element that has focus
|
||||
if (currentView) {
|
||||
currentView.activeElement = document.activeElement;
|
||||
}
|
||||
|
||||
tryRestoreInternal(viewcontainer, options, resolve, reject);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return new ViewManager();
|
||||
});
|
|
@ -32,14 +32,14 @@
|
|||
"web-component-tester": "^4.0.0",
|
||||
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
|
||||
},
|
||||
"homepage": "https://github.com/PolymerElements/iron-icon",
|
||||
"homepage": "https://github.com/polymerelements/iron-icon",
|
||||
"_release": "1.0.8",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.0.8",
|
||||
"commit": "f36b38928849ef3853db727faa8c9ef104d611eb"
|
||||
},
|
||||
"_source": "git://github.com/PolymerElements/iron-icon.git",
|
||||
"_source": "git://github.com/polymerelements/iron-icon.git",
|
||||
"_target": "^1.0.0",
|
||||
"_originalSource": "PolymerElements/iron-icon"
|
||||
"_originalSource": "polymerelements/iron-icon"
|
||||
}
|
|
@ -54,7 +54,7 @@
|
|||
"tag": "v1.1.10",
|
||||
"commit": "d8e201099b4b2987bea1dbcf5804c0383544bbfd"
|
||||
},
|
||||
"_source": "git://github.com/PolymerElements/paper-input.git",
|
||||
"_target": "^1.0.0",
|
||||
"_originalSource": "PolymerElements/paper-input"
|
||||
"_source": "git://github.com/polymerelements/paper-input.git",
|
||||
"_target": "^1.0.9",
|
||||
"_originalSource": "polymerelements/paper-input"
|
||||
}
|
|
@ -1744,6 +1744,7 @@ var AppInfo = {};
|
|||
hammer: bowerPath + "/hammerjs/hammer.min",
|
||||
layoutManager: embyWebComponentsBowerPath + "/layoutmanager",
|
||||
focusManager: embyWebComponentsBowerPath + "/focusmanager",
|
||||
viewManager: embyWebComponentsBowerPath + "/viewmanager",
|
||||
globalize: embyWebComponentsBowerPath + "/globalize",
|
||||
imageLoader: embyWebComponentsBowerPath + "/images/imagehelper"
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue