Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion for issue 676 #790

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/js/timeline/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ function make_keydown_handler(timeline) {
}
}

if (typeof makeHash !== 'function') {
function makeHash(id) {
var hash = "#" + "event-" + id.toString();
return hash;
}
}

if (typeof idFromHash !== 'function') {
function idFromHash(hash) {
if (!hash.startsWith("#event")) {
return null;
}
return hash.replace("#event-", "");
}
}

/**
* Primary entry point for using TimelineJS.
* @constructor
Expand Down Expand Up @@ -791,15 +807,17 @@ class Timeline {
this.goTo(this.options.start_at_slide);
}
if (this.options.hash_bookmark) {
if (window.location.hash != "") {
this.goToId(window.location.hash.replace("#event-", ""));
let hash = window.location.hash;
if (hash != "") {
this.goToId(idFromHash(hash));
} else {
this._updateHashBookmark(this.current_id);
}
let the_timeline = this;
window.addEventListener('hashchange', function() {
if (window.location.hash.indexOf('#event-') == 0) {
the_timeline.goToId(window.location.hash.replace("#event-", ""));
let id = idFromHash(hash);
if (id !== null) {
the_timeline.goToId(id);
}
}, false);
}
Expand All @@ -810,9 +828,9 @@ class Timeline {
// Update hashbookmark in the url bar
_updateHashBookmark(id) {
if (id) { // TODO: validate the id...
var hash = "#" + "event-" + id.toString();
var hash = makeHash(id);
window.history.replaceState(null, "Browsing TimelineJS", hash);
this.fire("hash_updated", { unique_id: this.current_id, hashbookmark: "#" + "event-" + id.toString() }, this);
this.fire("hash_updated", { unique_id: this.current_id, hashbookmark: hash }, this);
}
}

Expand Down