Skip to content

Commit 0556224

Browse files
committed
added externally open pdf
SQUASHED: added-OPEN,
1 parent 87c4361 commit 0556224

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/components/widgets/lively-pdf.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,28 @@ export default class LivelyPDF extends Morph {
5050
evt.stopPropagation();
5151
evt.preventDefault();
5252

53-
var menu = new ContextMenu(this, [
53+
54+
var menuItems = [
5455
["show outline", async () => {
5556
var workspace = await lively.openWorkspace(this.extractOutline())
5657
workspace.parentElement.setAttribute("title","Outline")
5758
workspace.mode = "text"
58-
}]]);
59-
menu.openIn(document.body, evt, this);
59+
}],
60+
]
61+
62+
let url = this.getURL()
63+
let serverURL = lively.files.serverURL(url)
64+
if (serverURL && serverURL.match("localhost")) {
65+
// does only make sense when accessing a localhost server,
66+
// otherwise a pdf viewer would be opened on a remote machine?
67+
menuItems.push(["open externally", async () => {
68+
let buildPath = url.replace(serverURL,"").replace(/^\//,"")
69+
var openURL = serverURL + "/_open/" + buildPath
70+
fetch(openURL)
71+
}])
72+
}
73+
var menu = new ContextMenu(this, menuItems);
74+
menu.openIn(document.body, evt, this);
6075
return true;
6176
}
6277
}
@@ -150,7 +165,10 @@ export default class LivelyPDF extends Morph {
150165
this.showPage(this.nextPage())
151166
}
152167

153-
168+
getURL() {
169+
return this.getAttribute("src")
170+
}
171+
154172
async setURL(url, oldPromise) {
155173
this.pdfLoaded = oldPromise || (new Promise(resolve => {
156174
this.resolveLoaded = resolve

0 commit comments

Comments
 (0)