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);
}
}

View File

@@ -28,6 +28,9 @@
},
"isomorphic-fetch/isomorphic-fetch.d.ts": {
"commit": "57ec5fbb76060329c10959d449eb1d4e70b15a65"
},
"jquery/jquery.d.ts": {
"commit": "f470e7569e7046c62866f57bc4fea56ba79975d5"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -6,3 +6,4 @@
/// <reference path="crossroads/crossroads.d.ts" />
/// <reference path="js-signals/js-signals.d.ts" />
/// <reference path="isomorphic-fetch/isomorphic-fetch.d.ts" />
/// <reference path="jquery/jquery.d.ts" />