use history.replaceState() so we don't have to reload page

This commit is contained in:
Steven Hugg 2018-08-23 17:46:25 -04:00
parent e808d817f0
commit 1ba3d621ce
3 changed files with 20 additions and 15 deletions

View File

@ -46,7 +46,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<span class="caret"></span> <span class="caret"></span>
</a> </a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li><a class="dropdown-item" href="#" id="item_new_file">New File...</a></li> <li><a class="dropdown-item" href="#" id="item_new_file">New Project...</a></li>
<li><a class="dropdown-item" href="#" id="item_upload_file">Upload File...</a></li> <li><a class="dropdown-item" href="#" id="item_upload_file">Upload File...</a></li>
<!--<li><a class="dropdown-item" href="#" id="item_share_file">Share File as GitHub Gist...</a></li>--> <!--<li><a class="dropdown-item" href="#" id="item_share_file">Share File as GitHub Gist...</a></li>-->
<li><a class="dropdown-item" href="#" id="item_reset_file">Revert to Original...</a></li> <li><a class="dropdown-item" href="#" id="item_reset_file">Revert to Original...</a></li>

View File

@ -62,8 +62,8 @@ class VCSPlatform {
// intercept clockPulse function // intercept clockPulse function
Javatari.room.console.oldClockPulse = Javatari.room.console.clockPulse; Javatari.room.console.oldClockPulse = Javatari.room.console.clockPulse;
Javatari.room.console.clockPulse = function() { Javatari.room.console.clockPulse = function() {
self.updateRecorder();
this.oldClockPulse(); this.oldClockPulse();
self.updateRecorder();
} }
this.paused = false; this.paused = false;
} }

View File

@ -899,6 +899,11 @@ function gotoNewLocation() {
window.location.href = "?" + $.param(qs); window.location.href = "?" + $.param(qs);
} }
function replaceURLState() {
if (platform_id) qs['platform'] = platform_id;
history.replaceState({}, "", "?" + $.param(qs));
}
function showBookLink() { function showBookLink() {
if (platform_id == 'vcs') if (platform_id == 'vcs')
$("#booklink_vcs").show(); $("#booklink_vcs").show();
@ -936,23 +941,22 @@ function startPlatform() {
platform = new PLATFORMS[platform_id]($("#emulator")[0]); platform = new PLATFORMS[platform_id]($("#emulator")[0]);
stateRecorder = new StateRecorderImpl(platform); stateRecorder = new StateRecorderImpl(platform);
PRESETS = platform.getPresets(); PRESETS = platform.getPresets();
if (qs['file']) { if (!qs['file']) {
// start platform and load file
platform.start();
setupDebugControls();
initProject();
loadProject(qs['file']);
updateSelector();
showBookLink();
addPageFocusHandlers();
return true;
} else {
// try to load last file (redirect) // try to load last file (redirect)
var lastid = localStorage.getItem("__lastid_"+platform_id) || localStorage.getItem("__lastid"); var lastid = localStorage.getItem("__lastid_"+platform_id) || localStorage.getItem("__lastid");
localStorage.removeItem("__lastid"); localStorage.removeItem("__lastid");
reloadPresetNamed(lastid || PRESETS[0].id); qs['file'] = lastid || PRESETS[0].id;
return false; replaceURLState();
} }
// start platform and load file
platform.start();
setupDebugControls();
initProject();
loadProject(qs['file']);
updateSelector();
showBookLink();
addPageFocusHandlers();
return true;
} }
function loadSharedFile(sharekey : string) { function loadSharedFile(sharekey : string) {
@ -966,6 +970,7 @@ function loadSharedFile(sharekey : string) {
console.log("Fetched " + newid, json); console.log("Fetched " + newid, json);
platform_id = json['platform']; platform_id = json['platform'];
store = createNewPersistentStore(platform_id, () => { store = createNewPersistentStore(platform_id, () => {
// runs after migration, if it happens
current_project.updateFile(newid, val.files[filename].content); current_project.updateFile(newid, val.files[filename].content);
reloadPresetNamed(newid); reloadPresetNamed(newid);
delete qs['sharekey']; delete qs['sharekey'];