Skip to content

Commit

Permalink
feat(pdf): open external url in iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Sep 11, 2016
1 parent c81bc38 commit db7707b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ let openedFilePath;
app.once('open-file', function(event, filePath) {
openedFilePath = filePath;
});
const openURL = (URL) => {
if (/^https?:/.test(URL)) {
shell.openExternal(URL, {
activate: true
});
}
};
let mainWindow = null;
app.on('ready', function() {
const mainWindowState = windowStateKeeper({
Expand All @@ -29,7 +36,9 @@ app.on('ready', function() {
'width': mainWindowState.width,
'height': mainWindowState.height,
});
mainWindowState.manage(mainWindow);
mainWindow.webContents.on('new-window', function(e) {
openURL(e.url);
});
const openHTML = (filePath) => {
const query = qs.stringify({
file: filePath
Expand Down
16 changes: 15 additions & 1 deletion src/component/project/PDFViewer/PDFViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
const React = require("react");
const qs = require("querystring");
const fs = require("fs");
const shell = require('electron').shell;
const openURL = (URL) => {
if (/^https?:/.test(URL)) {
shell.openExternal(URL, {
activate: true
});
}
};
export default class PDFViewer extends React.Component {
static get propTypes() {
return {
Expand Down Expand Up @@ -51,7 +59,11 @@ export default class PDFViewer extends React.Component {
};
this._onIframeLoad = () => {
this._addEventToIframe();
}
};
this._onDocumentClick = (event) => {
event.preventDefault();
openURL(event.target.href);
};
}


Expand Down Expand Up @@ -96,10 +108,12 @@ export default class PDFViewer extends React.Component {
iframeWindow.removeEventListener("documentload", this._onDocumentLoad);
iframeWindow.document.removeEventListener("drop", this._onDrop);
iframeWindow.document.removeEventListener("dragover", this._onDragOver);
iframeWindow.document.removeEventListener('click', this._onDocumentClick);
// onload document
iframeWindow.addEventListener("documentload", this._onDocumentLoad);
iframeWindow.document.addEventListener("drop", this._onDrop);
iframeWindow.document.addEventListener("dragover", this._onDragOver);
iframeWindow.document.addEventListener('click', this._onDocumentClick);

}

Expand Down

0 comments on commit db7707b

Please sign in to comment.