Revert "Add fail handler"

This reverts commit 1ecc5674ac.
This commit is contained in:
Daniel Imms
2017-03-04 14:01:40 -08:00
parent 1ecc5674ac
commit 5e2791f981
3 changed files with 6 additions and 21 deletions
-6
View File
@@ -85,12 +85,6 @@ export interface LinkMatcherOptions {
* false if invalid.
*/
validationCallback?: LinkMatcherValidationCallback;
/**
* A callback that fires when a link click fails due to ctrl or cmd (mac) not
* being pressed. This allows hinting to the user after a likely failed
* click.
*/
clickFailCallback?: (event: MouseEvent) => any;
/**
* The priority of the link matcher, this defines the order in which the link
* matcher is evaluated relative to others, from highest to lowest. The
+6 -14
View File
@@ -100,7 +100,6 @@ export class Linkifier {
handler,
matchIndex: options.matchIndex,
validationCallback: options.validationCallback,
clickFailCallback: options.clickFailCallback,
priority: options.priority || 0
};
this._addLinkMatcherToList(matcher);
@@ -159,7 +158,7 @@ export class Linkifier {
const matcher = this._linkMatchers[i];
const uri = this._findLinkMatch(text, matcher.regex, matcher.matchIndex);
if (uri) {
const linkElement = this._doLinkifyRow(rowIndex, uri, matcher.handler, matcher.clickFailCallback);
const linkElement = this._doLinkifyRow(rowIndex, uri, matcher.handler);
// Fire validation callback
if (linkElement && matcher.validationCallback) {
matcher.validationCallback(uri, isValid => {
@@ -181,14 +180,14 @@ export class Linkifier {
* @param {handler} handler The handler to trigger when the link is triggered.
* @return The link element if it was added, otherwise undefined.
*/
private _doLinkifyRow(rowIndex: number, uri: string, handler?: LinkMatcherHandler, clickFailHandler?: (event: MouseEvent) => any): HTMLElement {
private _doLinkifyRow(rowIndex: number, uri: string, handler?: LinkMatcherHandler): HTMLElement {
// Iterate over nodes as we want to consider text nodes
const nodes = this._rows[rowIndex].childNodes;
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
const searchIndex = node.textContent.indexOf(uri);
if (searchIndex >= 0) {
const linkElement = this._createAnchorElement(uri, handler, clickFailHandler);
const linkElement = this._createAnchorElement(uri, handler);
if (node.textContent.length === uri.length) {
// Matches entire string
@@ -231,11 +230,11 @@ export class Linkifier {
* @param {string} uri The uri of the link.
* @return {HTMLAnchorElement} The link.
*/
private _createAnchorElement(uri: string, handler: LinkMatcherHandler, failHandler: (event: MouseEvent) => any): HTMLAnchorElement {
private _createAnchorElement(uri: string, handler: LinkMatcherHandler): HTMLAnchorElement {
const element = this._document.createElement('a');
element.textContent = uri;
if (handler) {
element.addEventListener('click', (event: MouseEvent) => {
element.addEventListener('click', (event: KeyboardEvent) => {
// Don't execute the handler if the link is flagged as invalid
if (element.classList.contains(INVALID_LINK_CLASS)) {
return;
@@ -243,22 +242,15 @@ export class Linkifier {
// Require ctrl on click
if (isMac ? event.metaKey : event.ctrlKey) {
handler(uri);
} else {
if (failHandler) {
failHandler(event);
}
}
});
} else {
element.href = uri;
// Force link on another tab so work is not lost
element.target = '_blank';
element.addEventListener('click', (event: MouseEvent) => {
element.addEventListener('click', (event: KeyboardEvent) => {
// Require ctrl on click
if (isMac ? !event.metaKey : !event.ctrlKey) {
if (failHandler) {
failHandler(event);
}
event.preventDefault();
return false;
}
-1
View File
@@ -8,7 +8,6 @@ export type LinkMatcher = {
handler: LinkMatcherHandler,
matchIndex?: number,
validationCallback?: LinkMatcherValidationCallback,
clickFailCallback?: (event: MouseEvent) => any,
priority?: number
};
export type LinkMatcherHandler = (uri: string) => void;