Skip to content

Commit

Permalink
Got external links working in summary dialog.
Browse files Browse the repository at this point in the history
Links are opened in the application they need or an alert is shown.

Signed-off-by: Michel Verbraak <[email protected]>
  • Loading branch information
1stsetup committed Dec 9, 2013
1 parent 9fa97d3 commit 7c8520c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
86 changes: 86 additions & 0 deletions chrome/content/calendar-summary-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,92 @@ try{
}
}
},

hrefAndLinkNodeForClickEvent: function _hrefAndLinkNodeForClickEvent(event)
{
var href = "";
var isKeyCommand = (event.type == "command");
var linkNode = isKeyCommand ? this._document.commandDispatcher.focusedElement
: event.originalTarget;

while (linkNode instanceof Element) {
if (linkNode instanceof HTMLAnchorElement ||
linkNode instanceof HTMLAreaElement ||
linkNode instanceof HTMLLinkElement) {
href = linkNode.href;
if (href)
break;
}
// Try MathML href
else if (linkNode.namespaceURI == "http://www.w3.org/1998/Math/MathML" &&
linkNode.hasAttribute("href")) {
href = linkNode.getAttribute("href");
href = makeURLAbsolute(linkNode.baseURI, href);
break;
}
// Try simple XLink
else if (linkNode.hasAttributeNS("http://www.w3.org/1999/xlink", "href")) {
href = linkNode.getAttributeNS("http://www.w3.org/1999/xlink", "href");
href = makeURLAbsolute(linkNode.baseURI, href);
break;
}
linkNode = linkNode.parentNode;
}

return href ? {href: href, linkNode: linkNode} : null;
},

onClick: function _onClick(event)
{
// Following is copied from mailWindow.js script for emails.
var ceParams = this.hrefAndLinkNodeForClickEvent(event);
if (!ceParams && !event.button) {
var target = event.target;
// is this an image that we might want to scale?
if (target instanceof Components.interfaces.nsIImageLoadingContent) {
// make sure it loaded successfully
var req = target.getRequest(Components.interfaces.nsIImageLoadingContent.CURRENT_REQUEST);
if (!req || req.imageStatus & Components.interfaces.imgIRequest.STATUS_ERROR)
return true;
// is it an inline attachment?
if (/^moz-attached-image/.test(target.className)) {
if (target.hasAttribute("isshrunk"))
{
// currently shrunk to fit, so unshrink it
target.removeAttribute("isshrunk");
target.removeAttribute("shrinktofit");
target.setAttribute("overflowing", "true");
}
else if (target.hasAttribute("overflowing"))
{
// user wants to shrink now
target.setAttribute("isshrunk", "true");
target.setAttribute("shrinktofit", "true");
target.removeAttribute("overflowing");
}
}
}
return true;
}
var href = ceParams.href;

try {
var extProtService = Cc["@mozilla.org/uriloader/external-protocol-service;1"].getService();
extProtService = extProtService.QueryInterface(Ci.nsIExternalProtocolService);
var scheme = href.substring(0, href.indexOf(":"));
if (extProtService.isExposedProtocol(scheme)) {
var ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
extProtService.loadUrl(ioService.newURI(href, null, null));
}
}
catch (ex) {
alert("Do not know how to handle this reference:"+href);
}

event.preventDefault();
return true;
},
}

//this._window.addEventListener("load", exchWebService.forewardEvent2.onLoad, false);
Expand Down
7 changes: 6 additions & 1 deletion chrome/content/calendar-summary-dialog.xul
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@
<script type="application/javascript" src="chrome://exchangecalendar/content/calendar-summary-dialog.js" />
<box id="item-description-box" flex="1">

<browser id="exchWebService-body-editor" class="exchWebService-browser-class" type="content-targetable" insertafter="item-description" flex="1"/>
<browser id="exchWebService-body-editor"
class="exchWebService-browser-class"
type="content-targetable"
insertafter="item-description"
onclick = "return tmpEventSummaryDialog.onClick(event);"
flex="1"/>

<commandset id="itemCommands">
</commandset>
Expand Down

0 comments on commit 7c8520c

Please sign in to comment.