basicViewer: Open links externally
This commit is contained in:
parent
7eb4c1f6f6
commit
8eedfd4a14
5 changed files with 57 additions and 10 deletions
|
@ -29,7 +29,6 @@ ChromeUtils.registerWindowActor("FeedAbstract", {
|
|||
moduleURI: "chrome://zotero/content/actors/FeedAbstractChild.jsm",
|
||||
events: {
|
||||
DOMDocElementInserted: {},
|
||||
click: {},
|
||||
}
|
||||
},
|
||||
messageManagerGroups: ["feedAbstract"]
|
||||
|
@ -47,3 +46,16 @@ ChromeUtils.registerWindowActor("ZoteroPrint", {
|
|||
}
|
||||
});
|
||||
|
||||
ChromeUtils.registerWindowActor("ExternalLinkHandler", {
|
||||
parent: {
|
||||
moduleURI: "chrome://zotero/content/actors/ExternalLinkHandlerParent.jsm",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "chrome://zotero/content/actors/ExternalLinkHandlerChild.jsm",
|
||||
events: {
|
||||
click: {},
|
||||
}
|
||||
},
|
||||
messageManagerGroups: ["feedAbstract", "basicViewer"]
|
||||
});
|
||||
|
||||
|
|
26
chrome/content/zotero/actors/ExternalLinkHandlerChild.jsm
Normal file
26
chrome/content/zotero/actors/ExternalLinkHandlerChild.jsm
Normal file
|
@ -0,0 +1,26 @@
|
|||
var EXPORTED_SYMBOLS = ["ExternalLinkHandlerChild"];
|
||||
|
||||
|
||||
class ExternalLinkHandlerChild extends JSWindowActorChild {
|
||||
async handleEvent(event) {
|
||||
switch (event.type) {
|
||||
case "click": {
|
||||
let { button, target } = event;
|
||||
if (button !== 0) {
|
||||
break;
|
||||
}
|
||||
if ((target.localName === 'a' || target.localName === 'area') && target.href
|
||||
|| target.localName === 'label' && target.classList.contains('text-link')) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
await this._sendLaunchURL(target.href || target.getAttribute('href'));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async _sendLaunchURL(url) {
|
||||
await this.sendAsyncMessage("launchURL", url);
|
||||
}
|
||||
}
|
16
chrome/content/zotero/actors/ExternalLinkHandlerParent.jsm
Normal file
16
chrome/content/zotero/actors/ExternalLinkHandlerParent.jsm
Normal file
|
@ -0,0 +1,16 @@
|
|||
var EXPORTED_SYMBOLS = ["ExternalLinkHandlerParent"];
|
||||
|
||||
ChromeUtils.defineESModuleGetters(this, {
|
||||
Zotero: "chrome://zotero/content/zotero.mjs"
|
||||
});
|
||||
|
||||
class ExternalLinkHandlerParent extends JSWindowActorParent {
|
||||
async receiveMessage({ name, data }) {
|
||||
switch (name) {
|
||||
case "launchURL": {
|
||||
Zotero.launchURL(data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -68,14 +68,6 @@ window.addEventListener("keypress", function (event) {
|
|||
}
|
||||
});
|
||||
|
||||
// Handle <label class="text-link />
|
||||
window.addEventListener("click", function (event) {
|
||||
if (event.originalTarget.localName == 'label'
|
||||
&& event.originalTarget.classList.contains('text-link')) {
|
||||
Zotero.launchURL(event.originalTarget.getAttribute('href'));
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('dragover', (e) => {
|
||||
// Prevent default to allow drop (e.g. to allow dropping an XPI on the Add-ons window)
|
||||
e.preventDefault();
|
||||
|
|
|
@ -221,7 +221,8 @@
|
|||
remote="false"
|
||||
disableglobalhistory="true"
|
||||
maychangeremoteness="true"
|
||||
context="contentAreaContextMenu"/>
|
||||
context="contentAreaContextMenu"
|
||||
messagemanagergroup="basicViewer"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</window>
|
||||
|
|
Loading…
Reference in a new issue