diff --git a/modules/angular2/src/dom/browser_adapter.dart b/modules/angular2/src/dom/browser_adapter.dart index b9528b266c..8e23678bb7 100644 --- a/modules/angular2/src/dom/browser_adapter.dart +++ b/modules/angular2/src/dom/browser_adapter.dart @@ -188,6 +188,9 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter { void preventDefault(Event evt) { evt.preventDefault(); } + bool isPrevented(Event evt) { + return evt.defaultPrevented; + } String getInnerHTML(Element el) => el.innerHtml; String getOuterHTML(Element el) => el.outerHtml; void setInnerHTML(Element el, String value) { diff --git a/modules/angular2/src/dom/browser_adapter.ts b/modules/angular2/src/dom/browser_adapter.ts index c62cb4162e..24e4f452af 100644 --- a/modules/angular2/src/dom/browser_adapter.ts +++ b/modules/angular2/src/dom/browser_adapter.ts @@ -104,6 +104,9 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { evt.preventDefault(); evt.returnValue = false; } + isPrevented(evt: Event): boolean { + return evt.defaultPrevented || isPresent(evt.returnValue) && !evt.returnValue; + } getInnerHTML(el): string { return el.innerHTML; } getOuterHTML(el): string { return el.outerHTML; } nodeName(node: Node): string { return node.nodeName; } diff --git a/modules/angular2/src/dom/dom_adapter.ts b/modules/angular2/src/dom/dom_adapter.ts index 8136aa229b..8c9e1cb75c 100644 --- a/modules/angular2/src/dom/dom_adapter.ts +++ b/modules/angular2/src/dom/dom_adapter.ts @@ -43,6 +43,7 @@ export class DomAdapter { createMouseEvent(eventType): any { throw _abstract(); } createEvent(eventType: string): any { throw _abstract(); } preventDefault(evt) { throw _abstract(); } + isPrevented(evt): boolean { throw _abstract(); } getInnerHTML(el): string { throw _abstract(); } getOuterHTML(el): string { throw _abstract(); } nodeName(node): string { throw _abstract(); } diff --git a/modules/angular2/src/dom/html_adapter.dart b/modules/angular2/src/dom/html_adapter.dart index b7656393b3..646b4a76bd 100644 --- a/modules/angular2/src/dom/html_adapter.dart +++ b/modules/angular2/src/dom/html_adapter.dart @@ -102,6 +102,9 @@ class Html5LibDomAdapter implements DomAdapter { preventDefault(evt) { throw 'not implemented'; } + isPrevented(evt) { + throw 'not implemented'; + } getInnerHTML(el) { return el.innerHtml; } diff --git a/modules/angular2/src/dom/parse5_adapter.ts b/modules/angular2/src/dom/parse5_adapter.ts index a596417fbe..945c505e88 100644 --- a/modules/angular2/src/dom/parse5_adapter.ts +++ b/modules/angular2/src/dom/parse5_adapter.ts @@ -154,6 +154,7 @@ export class Parse5DomAdapter extends DomAdapter { return evt; } preventDefault(evt) { evt.returnValue = false; } + isPrevented(evt): boolean { return isPresent(evt.returnValue) && !evt.returnValue; } getInnerHTML(el): string { return serializer.serialize(this.templateAwareRoot(el)); } getOuterHTML(el): string { serializer.html = ''; diff --git a/modules/angular2/src/render/dom/view/view.ts b/modules/angular2/src/render/dom/view/view.ts index 11a5db1c98..907fd6c071 100644 --- a/modules/angular2/src/render/dom/view/view.ts +++ b/modules/angular2/src/render/dom/view/view.ts @@ -79,7 +79,7 @@ export class DomView { allowDefaultBehavior = this.eventDispatcher.dispatchRenderEvent(elementIndex, eventName, evalLocals); if (!allowDefaultBehavior) { - event.preventDefault(); + DOM.preventDefault(event); } } return allowDefaultBehavior; diff --git a/modules/angular2/test/core/compiler/integration_spec.ts b/modules/angular2/test/core/compiler/integration_spec.ts index a5b24887a0..7b957705f7 100644 --- a/modules/angular2/test/core/compiler/integration_spec.ts +++ b/modules/angular2/test/core/compiler/integration_spec.ts @@ -900,14 +900,14 @@ export function main() { .createAsync(MyComp) .then((rootTC) => { - expect(DOM.getChecked(rootTC.componentViewChildren[0].nativeElement)) - .toBeFalsy(); - expect(DOM.getChecked(rootTC.componentViewChildren[1].nativeElement)) - .toBeFalsy(); + var dispatchedEvent = DOM.createMouseEvent('click'); + var dispatchedEvent2 = DOM.createMouseEvent('click'); DOM.dispatchEvent(rootTC.componentViewChildren[0].nativeElement, - DOM.createMouseEvent('click')); + dispatchedEvent); DOM.dispatchEvent(rootTC.componentViewChildren[1].nativeElement, - DOM.createMouseEvent('click')); + dispatchedEvent2); + expect(DOM.isPrevented(dispatchedEvent)).toBe(true); + expect(DOM.isPrevented(dispatchedEvent2)).toBe(false); expect(DOM.getChecked(rootTC.componentViewChildren[0].nativeElement)) .toBeFalsy(); expect(DOM.getChecked(rootTC.componentViewChildren[1].nativeElement)) diff --git a/modules/angular2/test/dom/dom_adapter_spec.ts b/modules/angular2/test/dom/dom_adapter_spec.ts index 2d867d517b..978bf1678e 100644 --- a/modules/angular2/test/dom/dom_adapter_spec.ts +++ b/modules/angular2/test/dom/dom_adapter_spec.ts @@ -34,7 +34,7 @@ export function main() { expect(clone).not.toBe(el1); DOM.setAttribute(clone, 'test', '1'); - expect(DOM.getOuterHTML(clone)).toEqual('