fix(router): event.defaultPrevented is not reliable (IE11)

This commit is contained in:
Marc Laval 2015-05-21 11:32:29 +02:00
parent 5103f080e9
commit 2287938f5a
7 changed files with 17 additions and 3 deletions

View File

@ -135,6 +135,9 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
MouseEvent createMouseEvent(String eventType) =>
new MouseEvent(eventType, canBubble: true);
Event createEvent(String eventType) => new Event(eventType, canBubble: true);
void preventDefault(Event evt) {
evt.preventDefault();
}
String getInnerHTML(Element el) => el.innerHtml;
String getOuterHTML(Element el) => el.outerHtml;
void setInnerHTML(Element el, String value) {

View File

@ -77,6 +77,10 @@ createMouseEvent(eventType: string): MouseEvent {
createEvent(eventType): Event {
return new Event(eventType, true);
}
preventDefault(evt: Event) {
evt.preventDefault();
evt.returnValue = false;
}
getInnerHTML(el) {
return el.innerHTML;
}

View File

@ -33,6 +33,7 @@ export class DomAdapter {
dispatchEvent(el, evt) { throw _abstract(); }
createMouseEvent(eventType): any { throw _abstract(); }
createEvent(eventType: string): any { throw _abstract(); }
preventDefault(evt) { throw _abstract(); }
getInnerHTML(el): string { throw _abstract(); }
getOuterHTML(el): string { throw _abstract(); }
nodeName(node): string { throw _abstract(); }

View File

@ -76,6 +76,9 @@ class Html5LibDomAdapter implements DomAdapter {
createEvent(eventType) {
throw 'not implemented';
}
preventDefault(evt) {
throw 'not implemented';
}
getInnerHTML(el) {
return el.innerHtml;
}

View File

@ -134,6 +134,9 @@ export class Parse5DomAdapter extends DomAdapter {
};
return evt;
}
preventDefault(evt) {
evt.returnValue = false;
}
getInnerHTML(el) {
return serializer.serialize(this.templateAwareRoot(el));
}

View File

@ -54,7 +54,7 @@ export class RouterLink {
this._location = location;
this._params = StringMapWrapper.create();
DOM.on(this._domEl, 'click', (evt) => {
evt.preventDefault();
DOM.preventDefault(evt);
this._router.navigate(this._navigationHref);
});
}

View File

@ -221,7 +221,7 @@ export function main() {
view.detectChanges();
var dispatchedEvent = clickOnElement(view);
expect(dispatchedEvent.defaultPrevented).toBe(true);
expect(dispatchedEvent.defaultPrevented || !dispatchedEvent.returnValue).toBe(true);
// router navigation is async.
rtr.subscribe((_) => {
@ -244,7 +244,7 @@ export function main() {
view.detectChanges();
var dispatchedEvent = clickOnElement(view);
expect(dispatchedEvent.defaultPrevented).toBe(true);
expect(dispatchedEvent.defaultPrevented || !dispatchedEvent.returnValue).toBe(true);
// router navigation is async.
rtr.subscribe((_) => {