Allow http link handler to fallback to standard handler

This commit is contained in:
Daniel Imms
2017-03-04 14:44:11 -08:00
parent ab34d53d6b
commit 1f518b0b45
3 changed files with 11 additions and 13 deletions
+10 -11
View File
@@ -229,19 +229,10 @@ export class Linkifier {
* @param {string} uri The uri of the link.
* @return {HTMLAnchorElement} The link.
*/
private _createAnchorElement(uri: string, handler: LinkMatcherHandler): HTMLAnchorElement {
private _createAnchorElement(uri: string, handler: LinkMatcherHandler, isHypertextLinkHandler: boolean): HTMLAnchorElement {
const element = this._document.createElement('a');
element.textContent = uri;
if (handler) {
element.addEventListener('click', (event: MouseEvent) => {
// Don't execute the handler if the link is flagged as invalid
if (element.classList.contains(INVALID_LINK_CLASS)) {
return;
}
return handler(event, uri);
});
} else {
if (isHypertextLinkHandler) {
element.href = uri;
// Force link on another tab so work is not lost
element.target = '_blank';
@@ -250,6 +241,14 @@ export class Linkifier {
return handler(event, uri);
}
});
} else {
element.addEventListener('click', (event: MouseEvent) => {
// Don't execute the handler if the link is flagged as invalid
if (element.classList.contains(INVALID_LINK_CLASS)) {
return;
}
return handler(event, uri);
});
}
return element;
}
+1 -1
View File
@@ -10,5 +10,5 @@ export type LinkMatcher = {
validationCallback?: LinkMatcherValidationCallback,
priority?: number
};
export type LinkMatcherHandler = (event: MouseEvent, uri: string) => void;
export type LinkMatcherHandler = (event: MouseEvent, uri: string) => boolean | void;
export type LinkMatcherValidationCallback = (uri: string, callback: (isValid: boolean) => void) => void;
-1
View File
@@ -1295,7 +1295,6 @@ Terminal.prototype.attachHypertextLinkHandler = function(handler) {
this.refresh(0, this.rows - 1);
}
/**
* Registers a link matcher, allowing custom link patterns to be matched and
* handled.