Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 5f070da

Browse files
In KnockoutSpa template, fix handling clicks on descendants of A elements. Fixes #273.
1 parent 3270e28 commit 5f070da

File tree

4 files changed

+3250
-3
lines changed

4 files changed

+3250
-3
lines changed

templates/KnockoutSpa/ClientApp/router.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as ko from 'knockout';
2+
import * as $ from 'jquery';
23
import crossroads = require('crossroads');
34

45
// This module configures crossroads.js, a routing library. If you prefer, you
@@ -28,7 +29,7 @@ export class Router {
2829
// Make history.js watch for navigation and notify Crossroads
2930
this.disposeHistory = history.listen(location => crossroads.parse(location.pathname));
3031
this.clickEventListener = evt => {
31-
let target: any = evt.target;
32+
let target: any = evt.currentTarget;
3233
if (target && target.tagName === 'A') {
3334
let href = target.getAttribute('href');
3435
if (href && href.charAt(0) == '/') {
@@ -38,12 +39,12 @@ export class Router {
3839
}
3940
};
4041

41-
document.addEventListener('click', this.clickEventListener);
42+
$(document).on('click', 'a', this.clickEventListener);
4243
}
4344

4445
public dispose() {
4546
this.disposeHistory();
46-
document.removeEventListener('click', this.clickEventListener);
47+
$(document).off('click', 'a', this.clickEventListener);
4748
}
4849
}
4950

templates/KnockoutSpa/tsd.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
},
2929
"isomorphic-fetch/isomorphic-fetch.d.ts": {
3030
"commit": "57ec5fbb76060329c10959d449eb1d4e70b15a65"
31+
},
32+
"jquery/jquery.d.ts": {
33+
"commit": "f470e7569e7046c62866f57bc4fea56ba79975d5"
3134
}
3235
}
3336
}

0 commit comments

Comments
 (0)