Skip to content

Commit 65780bc

Browse files
committed
Updated Discovery, fixed issues with navigation
1 parent a918bb9 commit 65780bc

9 files changed

Lines changed: 204 additions & 150 deletions

File tree

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build/*.js
2+
src/discovery

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.0.5 (22-11-2018)
2+
3+
* Updated Discovery
4+
* Fixed issues with navigation
5+
16
## 1.0.4 (22-11-2018)
27

38
* Initial GitHub release

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsondiscovery",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "DiscoveryJson",
55
"author": "exsdis@gmail.com",
66
"license": "MIT",

src/content/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Widget, router } from '../discovery/lib.umd.js';
1+
import { Widget, router, complexViews } from '../discovery/lib.umd.js';
22

33
require('../discovery/lib.css');
44
require('../discovery/common.css');
@@ -13,6 +13,7 @@ function initDiscovery(settings) {
1313
const discovery = new Widget(document.body);
1414

1515
discovery.apply(router);
16+
discovery.apply(complexViews);
1617

1718
discovery.definePage('default', [
1819
{
@@ -85,6 +86,8 @@ function initDiscovery(settings) {
8586
}
8687

8788
window.addEventListener('message', function(event) {
89+
window.location.hash = event.data.hash;
90+
8891
if (event.data && event.data.json) {
8992
const { data } = event;
9093

@@ -98,11 +101,7 @@ window.addEventListener('message', function(event) {
98101
createdAt: new Date().toISOString() // TODO fix in discovery
99102
}
100103
);
101-
102-
discovery.renderPage('default');
103104
}
104-
105-
window.location.hash = event.data.hash;
106105
}, false);
107106

108107
window.addEventListener('hashchange', () => {

src/content/inject.js

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ if (json) {
5858
});
5959
});
6060

61-
window.addEventListener('message', event => {
62-
if (event.data && event.data.hash) {
63-
window.location.hash = event.data.hash;
64-
} else {
61+
const setHash = debounce(hash => {
62+
if (hash) {
63+
window.location.hash = hash;
64+
} else if (window.location.hash) {
6565
history.pushState('', document.title, window.location.pathname + window.location.search);
6666
}
67+
}, 300);
68+
69+
const onMessage = event => {
70+
setHash(event.data.hash);
6771

6872
if (event.data && event.data.openSettings) {
6973
if (chrome.runtime.openOptionsPage) {
@@ -72,11 +76,43 @@ if (json) {
7276
window.open(chrome.runtime.getURL('pages/settings.html'));
7377
}
7478
}
75-
});
79+
};
7680

77-
window.addEventListener('hashchange', () => {
81+
window.addEventListener('message', onMessage);
82+
83+
const onHashChange = () => {
7884
iframe.contentWindow.postMessage({
7985
hash: window.location.hash
8086
}, '*');
87+
};
88+
89+
window.addEventListener('hashchange', onHashChange);
90+
91+
window.addEventListener('beforeunload', () => {
92+
window.removeEventListener('message', onMessage);
93+
window.removeEventListener('hashchange', onHashChange);
8194
});
8295
}
96+
97+
/**
98+
* Debounce
99+
* @param {Function} func
100+
* @param {number} wait
101+
* @returns {Function}
102+
*/
103+
function debounce(func, wait) {
104+
let timer = null;
105+
106+
return function(...args) {
107+
const onComplete = () => {
108+
func.apply(this, args);
109+
timer = null;
110+
};
111+
112+
if (timer) {
113+
clearTimeout(timer);
114+
}
115+
116+
timer = setTimeout(onComplete, wait);
117+
};
118+
}

src/discovery/lib.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)