-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8fe73c
commit d46a33e
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
omeroweb/webclient/static/webclient/javascript/ome.history.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
function setQueryStringParameter(name, value, data) { | ||
const params = new URLSearchParams(window.location.search); | ||
params.set(name, value); | ||
data = data || {}; | ||
window.history.pushState(data, "", decodeURIComponent(`${window.location.pathname}?${params}`)); | ||
} | ||
|
||
(function(){ | ||
let listening = true; | ||
|
||
// on selection change, update history | ||
$("body").on("selection_change.ome", function(event) { | ||
if (!listening) return; | ||
var selected = $("body").data("selected_objects.ome"); | ||
let show = selected.map(obj => obj.id).join("|") | ||
setQueryStringParameter("show", show, {selected: selected}); | ||
}); | ||
|
||
// Handle forward/back buttons | ||
window.addEventListener("popstate", (event) => { | ||
if (event.state) { | ||
const {selected} = event.state; | ||
console.log("popstate selected...", selected); | ||
if (selected.length == 0) { | ||
return; | ||
} | ||
var inst = $.jstree.reference('#dataTree'); | ||
inst.deselect_all(true); | ||
|
||
// disable history above, otherwise it adds to pushState, | ||
// wipes out any 'forward' history etc. | ||
listening = false; | ||
|
||
selected.forEach((obj) => { | ||
var obj_id = obj.id; | ||
var node = inst.locate_node(obj_id)[0]; | ||
if (node) { | ||
inst.select_node(node); | ||
// we also focus the node, to scroll to it and setup hotkey events | ||
$("#" + node.id).children('.jstree-anchor').trigger('focus'); | ||
} else { | ||
// TODO: not handled 'Well' | ||
console.log("HISTORY node not found ", obj_id); | ||
} | ||
}); | ||
// once we're done, start listening again | ||
setTimeout(() => {listening = true}, 500); | ||
} | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters