Skip to content

TagSpaces is an offline, open source, document manager with tagging support

enable opening of external links

uggrock3cbbdddefe2d
diff --git a/data/ext/viewerHTML/extension.js b/data/ext/viewerHTML/extension.js
index 016e42430..a6e7b712a 100644
--- a/data/ext/viewerHTML/extension.js
+++ b/data/ext/viewerHTML/extension.js
@@ -43,7 +43,7 @@ define(function(require, exports, module) {
"sandbox": "allow-same-origin allow-scripts",
"id": "iframeViewer",
"nwdisable": "",
- "nwfaketop": "",
+ //"nwfaketop": "",
"src": extensionDirectory + "/index.html?&locale=" + TSCORE.currentLanguage,
}));
diff --git a/data/ext/viewerHTML/main.js b/data/ext/viewerHTML/main.js
index 0453177f1..0104dd4d2 100644
--- a/data/ext/viewerHTML/main.js
+++ b/data/ext/viewerHTML/main.js
@@ -122,19 +122,36 @@ function setContent(content, fileDirectory) {
$htmlContent.append(content);
- $htmlContent.find("a").bind('click', function(e) {
- e.preventDefault();
- var msg = { link : $(this).attr("href") };
- window.parent.postMessage(JSON.stringify(msg), "*");
+ $htmlContent.find("a[href]").each(function() {
+ var currentSrc = $(this).attr("href");
+ if (currentSrc.indexOf("http://") === 0 ||
+ currentSrc.indexOf("https://") === 0 ||
+ currentSrc.indexOf("file://") === 0 ||
+ currentSrc.indexOf("data:") === 0) {
+ // do nothing if src begins with http(s):// or data:
+ } else {
+ var path = "file://" + fileDirectory + (isWin ? "\\" : "/") + currentSrc;
+ $(this).attr("href", path);
+ }
});
// fixing embedding of local images
$htmlContent.find("img[src]").each(function() {
var currentSrc = $(this).attr("src");
- if (currentSrc.indexOf("http://") === 0 || currentSrc.indexOf("https://") === 0 || currentSrc.indexOf("data:") === 0) {
+ if (currentSrc.indexOf("http://") === 0 ||
+ currentSrc.indexOf("https://") === 0 ||
+ currentSrc.indexOf("file://") === 0 ||
+ currentSrc.indexOf("data:") === 0) {
// do nothing if src begins with http(s):// or data:
} else {
$(this).attr("src", "file://" + fileDirectory + isWin ? "\\" : "/" + currentSrc);
}
});
+
+ $htmlContent.find("a").bind('click', function(e) {
+ e.preventDefault();
+ var msg = { command: "openLinkExternally", link : $(this).attr("href") };
+ window.parent.postMessage(JSON.stringify(msg), "*");
+ });
+
}
diff --git a/data/ext/viewerMD/main.js b/data/ext/viewerMD/main.js
index aac3f847d..4051c6646 100644
--- a/data/ext/viewerMD/main.js
+++ b/data/ext/viewerMD/main.js
@@ -127,9 +127,22 @@ function setContent(content, fileDirectory) {
}
});
+ $htmlContent.find("a[href]").each(function() {
+ var currentSrc = $(this).attr("href");
+ if (currentSrc.indexOf("http://") === 0 ||
+ currentSrc.indexOf("https://") === 0 ||
+ currentSrc.indexOf("file://") === 0 ||
+ currentSrc.indexOf("data:") === 0) {
+ // do nothing if src begins with http(s):// or data:
+ } else {
+ var path = "file://" + fileDirectory + (isWin ? "\\" : "/") + currentSrc;
+ $(this).attr("href", path);
+ }
+ });
+
$("#htmlContent").find("a").bind('click', function(e) {
e.preventDefault();
- var msg = { link : $(this).attr("href") };
+ var msg = { command: "openLinkExternally", link : $(this).attr("href") };
window.parent.postMessage(JSON.stringify(msg), "*");
});
}
diff --git a/data/js/ext.api.js b/data/js/ext.api.js
index ed7465c23..c0dd3ff08 100644
--- a/data/js/ext.api.js
+++ b/data/js/ext.api.js
@@ -3,13 +3,30 @@ define(function(require, exports, module) {
var TSCORE = require("tscore");
console.log("Loading: ext.api.js");
- window.addEventListener("message", function(msg) {
- console.log(msg);
+ window.addEventListener("message", handleMessage , false);
+
+ function handleMessage(msg) {
var data = JSON.parse(msg.data);
- if (data.link) {
- TSCORE.openLinkExternally(data.link);
+ var command = data.command;
+
+ switch (command) {
+ case "openLinkExternally":
+ if (data.link) {
+ openLinkExternally(data.link);
+ }
+ break;
+ default:
+ console.log("Not recognized messaging command: " + msg);
+ break;
+ }
+ }
+
+ function openLinkExternally(url) {
+ if (url.indexOf("http://") === 0 || url.indexOf("https://") === 0 || url.indexOf("file://") === 0 ) {
+ TSCORE.openLinkExternally(url);
+ } else {
+ console.log("Not supported URL format: " + url);
}
-
- }, false);
+ }
});
\ No newline at end of file