Skip to content

Commit

Permalink
Initial working browser history
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Feb 23, 2024
1 parent f8fe73c commit d46a33e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions omeroweb/webclient/static/webclient/javascript/ome.history.js
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);
}
});

})();
2 changes: 2 additions & 0 deletions omeroweb/webclient/templates/webclient/data/containers.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
<!-- Main jsTree code is here -->
<script src="{% static 'webclient/javascript/ome.tree.js'|add:url_suffix %}"></script>

<!-- Handle browser history, urls -->
<script type="text/javascript" src="{% static 'webclient/javascript/ome.history.js'|add:url_suffix %}"></script>

<script type="text/javascript">

Expand Down

0 comments on commit d46a33e

Please sign in to comment.