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/10/07 20:02:38 UTC
[incubator-annotator] 02/10: Clean up demo hash vs fragment
terminology
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
commit 9909c266db0de34ff360f5706d967b0107b8e9f2
Author: Randall Leeds <ra...@apache.org>
AuthorDate: Sat Sep 28 16:29:13 2019 -0700
Clean up demo hash vs fragment terminology
---
demo/index.js | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/demo/index.js b/demo/index.js
index c4aa48e..7996023 100644
--- a/demo/index.js
+++ b/demo/index.js
@@ -97,10 +97,10 @@ const createSelector = makeRefinable(selector => {
const refresh = async () => {
clear();
- const identifier = window.location.hash.slice(1);
- if (!identifier) return;
+ const fragment = window.location.hash.slice(1);
+ if (!fragment) return;
- const { selector } = parseFragment(identifier);
+ const { selector } = parseFragment(fragment);
const matchAll = createSelector(selector);
const ranges = [];
@@ -131,15 +131,14 @@ async function describeSelection() {
async function onSelectionChange() {
const selector = await describeSelection();
+ const fragment = selector ? stringifyFragment(selector) : '';
+ const url = new URL(window.location.href);
+ url.hash = fragment ? `#${fragment}` : '';
- if (selector) {
- const fragment = stringifyFragment(selector);
- window.history.replaceState(selector, null, `#${fragment}`);
- } else {
- window.history.replaceState(null, null, location.pathname);
+ if (url.href !== window.location.href) {
+ window.history.replaceState(selector, null, url.href);
+ refresh();
}
-
- refresh();
}
window.addEventListener('popstate', refresh);