From 2807ef810f1432e6af452186f8deca92394481f8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 14 Mar 2016 16:05:15 -0400 Subject: [PATCH] use shared viewmanager --- .../emby-webcomponents/.bower.json | 8 +- .../emby-webcomponents/viewmanager.js | 149 ++++++++++++++++++ .../bower_components/iron-icon/.bower.json | 6 +- .../bower_components/paper-input/.bower.json | 6 +- dashboard-ui/scripts/site.js | 1 + 5 files changed, 160 insertions(+), 10 deletions(-) create mode 100644 dashboard-ui/bower_components/emby-webcomponents/viewmanager.js diff --git a/dashboard-ui/bower_components/emby-webcomponents/.bower.json b/dashboard-ui/bower_components/emby-webcomponents/.bower.json index cf5deae83f..a5e409c1d0 100644 --- a/dashboard-ui/bower_components/emby-webcomponents/.bower.json +++ b/dashboard-ui/bower_components/emby-webcomponents/.bower.json @@ -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", diff --git a/dashboard-ui/bower_components/emby-webcomponents/viewmanager.js b/dashboard-ui/bower_components/emby-webcomponents/viewmanager.js new file mode 100644 index 0000000000..1249c6b463 --- /dev/null +++ b/dashboard-ui/bower_components/emby-webcomponents/viewmanager.js @@ -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(); +}); diff --git a/dashboard-ui/bower_components/iron-icon/.bower.json b/dashboard-ui/bower_components/iron-icon/.bower.json index 9784e3a3b7..f0167baf13 100644 --- a/dashboard-ui/bower_components/iron-icon/.bower.json +++ b/dashboard-ui/bower_components/iron-icon/.bower.json @@ -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" } \ No newline at end of file diff --git a/dashboard-ui/bower_components/paper-input/.bower.json b/dashboard-ui/bower_components/paper-input/.bower.json index 416633ba74..536b8d1c24 100644 --- a/dashboard-ui/bower_components/paper-input/.bower.json +++ b/dashboard-ui/bower_components/paper-input/.bower.json @@ -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" } \ No newline at end of file diff --git a/dashboard-ui/scripts/site.js b/dashboard-ui/scripts/site.js index 8bc1d46c4e..721ebcc440 100644 --- a/dashboard-ui/scripts/site.js +++ b/dashboard-ui/scripts/site.js @@ -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" };