Handle external links in the embedded viewer

This commit is contained in:
Kostas Chatzikokolakis 2018-02-17 19:30:01 +01:00
parent 965d03970e
commit 309f82ce8d
2 changed files with 13 additions and 0 deletions

View File

@ -152,6 +152,9 @@ export class Viewer {
case 'click':
this.extension.locator.locate(data, decodeURIComponent(data.path))
break
case 'external_link':
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(data.url))
break
default:
this.extension.logger.addLogMessage(`Unknown websocket message: ${msg}`)
break

View File

@ -420,6 +420,16 @@ See https://github.com/adobe-type-tools/cmap-resources
socket.send(JSON.stringify({type:"loaded", path:file}))
})
// if we're embedded we cannot open external links here. So we intercept clicks and forward them to the extension
if (window.parent !== window) {
document.addEventListener('click', (e) => {
if (e.target.nodeName == 'A' && !e.target.href.startsWith(window.location.href)) { // is external link
socket.send(JSON.stringify({type:"external_link", url:e.target.href}))
e.preventDefault();
}
})
}
document.addEventListener('pagerendered', (e) => {
let page = e.target.dataset.pageNumber
let target = e.target