You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ra...@apache.org on 2019/05/23 19:24:39 UTC
[incubator-annotator] branch master updated: Use History API in the
demo
This is an automated email from the ASF dual-hosted git repository.
randall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
The following commit(s) were added to refs/heads/master by this push:
new a19f032 Use History API in the demo
a19f032 is described below
commit a19f03209fd627e602f49dc63afe75e8a8be8612
Author: Randall Leeds <ra...@apache.org>
AuthorDate: Thu May 23 15:24:16 2019 -0400
Use History API in the demo
---
demo/index.js | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/demo/index.js b/demo/index.js
index 63d2b1d..73648b3 100644
--- a/demo/index.js
+++ b/demo/index.js
@@ -59,7 +59,8 @@ async function onSelectionChange() {
const selectableRange = document.createRange();
selectableRange.selectNodeContents(selectable);
const descriptor = await describeRange({ range, context: selectableRange });
- window.location.hash = fragment.stringify(descriptor);
+ const nextFragment = fragment.stringify(descriptor);
+ window.history.replaceState(descriptor, null, `#${nextFragment}`);
}
function isWithinNode(range, node) {
@@ -71,14 +72,14 @@ function isWithinNode(range, node) {
);
}
-window.addEventListener('hashchange', refresh);
+window.addEventListener('popstate', refresh);
document.addEventListener('DOMContentLoaded', refresh);
document.addEventListener('selectionchange', onSelectionChange);
if (module.hot) {
module.hot.accept();
module.hot.dispose(() => {
- window.removeEventListener('hashchange', refresh);
+ window.removeEventListener('popstate', refresh);
document.removeEventListener('DOMContentLoaded', refresh);
document.removeEventListener('selectionchange', onSelectionChange);
});