In KnockoutSpa template, fix handling clicks on descendants of A elements. Fixes #273.

This commit is contained in:
SteveSandersonMS
2016-09-29 11:04:22 +01:00
parent 3270e28b3d
commit 5f070daac8
4 changed files with 3250 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import * as ko from 'knockout';
import * as $ from 'jquery';
import crossroads = require('crossroads');
// This module configures crossroads.js, a routing library. If you prefer, you
@@ -28,7 +29,7 @@ export class Router {
// Make history.js watch for navigation and notify Crossroads
this.disposeHistory = history.listen(location => crossroads.parse(location.pathname));
this.clickEventListener = evt => {
let target: any = evt.target;
let target: any = evt.currentTarget;
if (target && target.tagName === 'A') {
let href = target.getAttribute('href');
if (href && href.charAt(0) == '/') {
@@ -38,12 +39,12 @@ export class Router {
}
};
document.addEventListener('click', this.clickEventListener);
$(document).on('click', 'a', this.clickEventListener);
}
public dispose() {
this.disposeHistory();
document.removeEventListener('click', this.clickEventListener);
$(document).off('click', 'a', this.clickEventListener);
}
}