Skip to content

Commit

Permalink
Electron: Fixes #933: Handle internal links from HTML and from MD
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Nov 16, 2018
1 parent a3d64d0 commit 71d9b1d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ElectronClient/app/gui/note-viewer/index.html
Expand Up @@ -276,24 +276,32 @@
}
});

function handleInternalLink(event, anchorNode) {
const href = anchorNode.getAttribute('href');
if (href.indexOf('#') === 0) {
event.preventDefault();
location.hash = href;
return true;
}
return false;
}

document.addEventListener('click', function(event) {
const t = event.target;

// Prevent URLs added via <a> tags from being opened within the application itself
// otherwise it would open the whole website within the WebView.
if (t && t.nodeName === 'A' && !t.hasAttribute('data-from-md')) {
if (handleInternalLink(event, t)) return;

event.preventDefault();
ipcProxySendToHost(t.getAttribute('href'));
return;
}

// IF this is an internal link, jump to the anchor directly
// If this is an internal link, jump to the anchor directly
if (t && t.nodeName === 'A' && t.hasAttribute('data-from-md')) {
const href = t.getAttribute('href');
if (href.indexOf('#') === 0) {
event.preventDefault();
location.hash = href;
return;
}
if (handleInternalLink(event, t)) return;
}
});

Expand Down

0 comments on commit 71d9b1d

Please sign in to comment.