mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
In KnockoutSpa template, fix handling clicks on descendants of A elements. Fixes #273.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import * as ko from 'knockout';
|
import * as ko from 'knockout';
|
||||||
|
import * as $ from 'jquery';
|
||||||
import crossroads = require('crossroads');
|
import crossroads = require('crossroads');
|
||||||
|
|
||||||
// This module configures crossroads.js, a routing library. If you prefer, you
|
// 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
|
// Make history.js watch for navigation and notify Crossroads
|
||||||
this.disposeHistory = history.listen(location => crossroads.parse(location.pathname));
|
this.disposeHistory = history.listen(location => crossroads.parse(location.pathname));
|
||||||
this.clickEventListener = evt => {
|
this.clickEventListener = evt => {
|
||||||
let target: any = evt.target;
|
let target: any = evt.currentTarget;
|
||||||
if (target && target.tagName === 'A') {
|
if (target && target.tagName === 'A') {
|
||||||
let href = target.getAttribute('href');
|
let href = target.getAttribute('href');
|
||||||
if (href && href.charAt(0) == '/') {
|
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() {
|
public dispose() {
|
||||||
this.disposeHistory();
|
this.disposeHistory();
|
||||||
document.removeEventListener('click', this.clickEventListener);
|
$(document).off('click', 'a', this.clickEventListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@
|
|||||||
},
|
},
|
||||||
"isomorphic-fetch/isomorphic-fetch.d.ts": {
|
"isomorphic-fetch/isomorphic-fetch.d.ts": {
|
||||||
"commit": "57ec5fbb76060329c10959d449eb1d4e70b15a65"
|
"commit": "57ec5fbb76060329c10959d449eb1d4e70b15a65"
|
||||||
|
},
|
||||||
|
"jquery/jquery.d.ts": {
|
||||||
|
"commit": "f470e7569e7046c62866f57bc4fea56ba79975d5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3242
templates/KnockoutSpa/typings/jquery/jquery.d.ts
vendored
Normal file
3242
templates/KnockoutSpa/typings/jquery/jquery.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
templates/KnockoutSpa/typings/tsd.d.ts
vendored
1
templates/KnockoutSpa/typings/tsd.d.ts
vendored
@@ -6,3 +6,4 @@
|
|||||||
/// <reference path="crossroads/crossroads.d.ts" />
|
/// <reference path="crossroads/crossroads.d.ts" />
|
||||||
/// <reference path="js-signals/js-signals.d.ts" />
|
/// <reference path="js-signals/js-signals.d.ts" />
|
||||||
/// <reference path="isomorphic-fetch/isomorphic-fetch.d.ts" />
|
/// <reference path="isomorphic-fetch/isomorphic-fetch.d.ts" />
|
||||||
|
/// <reference path="jquery/jquery.d.ts" />
|
||||||
|
|||||||
Reference in New Issue
Block a user