Skip to content

Commit

Permalink
Include element in validationCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Mar 9, 2017
1 parent 2c151f4 commit b66776a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Linkifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Linkifier', () => {
it('should enable link if true', done => {
addRow('test');
linkifier.registerLinkMatcher(/test/, () => done(), {
validationCallback: (url, cb) => {
validationCallback: (url, element, cb) => {
cb(true);
assert.equal((<HTMLElement>rows[0].firstChild).tagName, 'A');
setTimeout(() => clickElement(rows[0].firstChild), 0);
Expand All @@ -65,7 +65,7 @@ describe('Linkifier', () => {
it('should disable link if false', done => {
addRow('test');
linkifier.registerLinkMatcher(/test/, () => assert.fail(), {
validationCallback: (url, cb) => {
validationCallback: (url, element, cb) => {
cb(false);
assert.equal((<HTMLElement>rows[0].firstChild).tagName, 'A');
setTimeout(() => clickElement(rows[0].firstChild), 0);
Expand Down
2 changes: 1 addition & 1 deletion src/Linkifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class Linkifier {
const linkElement = this._doLinkifyRow(rowIndex, uri, matcher.handler, matcher.id === HYPERTEXT_LINK_MATCHER_ID);
// Fire validation callback
if (linkElement && matcher.validationCallback) {
matcher.validationCallback(uri, isValid => {
matcher.validationCallback(uri, linkElement, isValid => {
if (!isValid) {
linkElement.classList.add(INVALID_LINK_CLASS);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export type LinkMatcher = {
priority?: number
};
export type LinkMatcherHandler = (event: MouseEvent, uri: string) => boolean | void;
export type LinkMatcherValidationCallback = (uri: string, callback: (isValid: boolean) => void) => void;
export type LinkMatcherValidationCallback = (uri: string, element: HTMLElement, callback: (isValid: boolean) => void) => void;

0 comments on commit b66776a

Please sign in to comment.