* support for going back between multi app tabs.

This commit is contained in:
Catouse
2021-03-04 15:51:14 +08:00
parent 38cbc02c95
commit 3faa875fae
+12 -6
View File
@@ -235,7 +235,7 @@
if(lastOpenedApp !== appCode)
{
lastOpenedApp = appCode;
updateAppUrl(appCode);
updateAppUrl(appCode, null, null, true);
}
return true;
@@ -350,12 +350,13 @@
* @param {string} appCode The app code of target app to update url
* @param {string|boolean} [url] The new url of the app
* @param {string|boolean} [title] The new title of the app
* @param {boolean} [push] Use push instead of replace
* @return {void}
*/
function updateAppUrl(appCode, url, title)
function updateAppUrl(appCode, url, title, push)
{
var app = openedApps[appCode];
if(!app) return;
if(!app || lastOpenedApp !== appCode) return;
if(url) app.appUrl = url;
else url = app.appUrl;
@@ -363,11 +364,11 @@
else title = app.appTitle || app.text;
if(url && url.indexOf('#') < 0 && getAppCodeFromUrl(url) !== appCode) url = url + '#app=' + appCode;
if(lastOpenedApp === appCode)
if(location.href !== url)
{
if(location.url !== url) history.replaceState({app: appCode}, title, url);
document.title = title;
history[push ? 'pushState' : 'replaceState']({app: appCode}, title, url);
}
document.title = title;
}
/* Bind helper methods to global object "$.apps" */
@@ -442,6 +443,11 @@
event.preventDefault();
});
window.addEventListener('popstate', function(event)
{
if(lastOpenedApp !== event.state.app) openApp(event.state.app);
});
/* Redirect or open default app after document load */
var defaultOpenUrl = window.defaultOpen;
if(!defaultOpenUrl && location.hash.indexOf('#app=') === 0)