Skip to content

Commit

Permalink
Updated Discovery, fixed issues with navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
exdis committed Nov 22, 2018
1 parent a918bb9 commit 65780bc
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 150 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/*.js
src/discovery
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.5 (22-11-2018)

* Updated Discovery
* Fixed issues with navigation

## 1.0.4 (22-11-2018)

* Initial GitHub release
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsondiscovery",
"version": "1.0.4",
"version": "1.0.5",
"description": "DiscoveryJson",
"author": "exsdis@gmail.com",
"license": "MIT",
Expand Down
9 changes: 4 additions & 5 deletions src/content/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Widget, router } from '../discovery/lib.umd.js';
import { Widget, router, complexViews } from '../discovery/lib.umd.js';

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

discovery.apply(router);
discovery.apply(complexViews);

discovery.definePage('default', [
{
Expand Down Expand Up @@ -85,6 +86,8 @@ function initDiscovery(settings) {
}

window.addEventListener('message', function(event) {
window.location.hash = event.data.hash;

if (event.data && event.data.json) {
const { data } = event;

Expand All @@ -98,11 +101,7 @@ window.addEventListener('message', function(event) {
createdAt: new Date().toISOString() // TODO fix in discovery
}
);

discovery.renderPage('default');
}

window.location.hash = event.data.hash;
}, false);

window.addEventListener('hashchange', () => {
Expand Down
48 changes: 42 additions & 6 deletions src/content/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ if (json) {
});
});

window.addEventListener('message', event => {
if (event.data && event.data.hash) {
window.location.hash = event.data.hash;
} else {
const setHash = debounce(hash => {
if (hash) {
window.location.hash = hash;
} else if (window.location.hash) {
history.pushState('', document.title, window.location.pathname + window.location.search);
}
}, 300);

const onMessage = event => {
setHash(event.data.hash);

if (event.data && event.data.openSettings) {
if (chrome.runtime.openOptionsPage) {
Expand All @@ -72,11 +76,43 @@ if (json) {
window.open(chrome.runtime.getURL('pages/settings.html'));
}
}
});
};

window.addEventListener('hashchange', () => {
window.addEventListener('message', onMessage);

const onHashChange = () => {
iframe.contentWindow.postMessage({
hash: window.location.hash
}, '*');
};

window.addEventListener('hashchange', onHashChange);

window.addEventListener('beforeunload', () => {
window.removeEventListener('message', onMessage);
window.removeEventListener('hashchange', onHashChange);
});
}

/**
* Debounce
* @param {Function} func
* @param {number} wait
* @returns {Function}
*/
function debounce(func, wait) {
let timer = null;

return function(...args) {
const onComplete = () => {
func.apply(this, args);
timer = null;
};

if (timer) {
clearTimeout(timer);
}

timer = setTimeout(onComplete, wait);
};
}
2 changes: 1 addition & 1 deletion src/discovery/lib.css

Large diffs are not rendered by default.

Loading

0 comments on commit 65780bc

Please sign in to comment.