From f356d033625c25cfa169e0b0943620c2bb5a44d8 Mon Sep 17 00:00:00 2001 From: Rado Kirov Date: Tue, 5 May 2015 14:50:53 -0700 Subject: [PATCH] feat(dom): add location and history as DOM-like APIs. Instead of global access methods. --- modules/angular2/src/dom/browser_adapter.dart | 6 ++++++ modules/angular2/src/dom/browser_adapter.es6 | 6 ++++++ modules/angular2/src/dom/dom_adapter.js | 6 ++++++ modules/angular2/src/dom/html_adapter.dart | 6 ++++++ modules/angular2/src/dom/parse5_adapter.cjs | 6 ++++++ modules/angular2/src/router/location.js | 8 ++++---- 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/modules/angular2/src/dom/browser_adapter.dart b/modules/angular2/src/dom/browser_adapter.dart index 6184ea0cd8..f33c03d825 100644 --- a/modules/angular2/src/dom/browser_adapter.dart +++ b/modules/angular2/src/dom/browser_adapter.dart @@ -307,4 +307,10 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter { return document.body; } } + getHistory() { + return window.history; + } + getLocation() { + return window.location; + } } diff --git a/modules/angular2/src/dom/browser_adapter.es6 b/modules/angular2/src/dom/browser_adapter.es6 index 567b6c0c36..dfeefd5f3e 100644 --- a/modules/angular2/src/dom/browser_adapter.es6 +++ b/modules/angular2/src/dom/browser_adapter.es6 @@ -372,4 +372,10 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { return document.body; } } + getHistory() { + return window.history; + } + getLocation() { + return window.location; + } } diff --git a/modules/angular2/src/dom/dom_adapter.js b/modules/angular2/src/dom/dom_adapter.js index 2ce54edb8b..c25f5c70f5 100644 --- a/modules/angular2/src/dom/dom_adapter.js +++ b/modules/angular2/src/dom/dom_adapter.js @@ -283,4 +283,10 @@ export class DomAdapter { getGlobalEventTarget(target:string) { throw _abstract(); } + getHistory() { + throw _abstract(); + } + getLocation() { + throw _abstract(); + } } diff --git a/modules/angular2/src/dom/html_adapter.dart b/modules/angular2/src/dom/html_adapter.dart index d71a2c16f1..63a3af3772 100644 --- a/modules/angular2/src/dom/html_adapter.dart +++ b/modules/angular2/src/dom/html_adapter.dart @@ -281,4 +281,10 @@ class Html5LibDomAdapter implements DomAdapter { bool supportsNativeShadowDOM() { throw 'not implemented'; } + getHistory() { + throw 'not implemented'; + } + getLocation() { + throw 'not implemented'; + } } diff --git a/modules/angular2/src/dom/parse5_adapter.cjs b/modules/angular2/src/dom/parse5_adapter.cjs index 4ac8ba3539..d126d185fa 100644 --- a/modules/angular2/src/dom/parse5_adapter.cjs +++ b/modules/angular2/src/dom/parse5_adapter.cjs @@ -523,6 +523,12 @@ export class Parse5DomAdapter extends DomAdapter { return this.defaultDoc().body; } } + getHistory() { + throw 'not implemented'; + } + getLocation() { + throw 'not implemented'; + } } //TODO: build a proper list, this one is all the keys of a HTMLInputElement diff --git a/modules/angular2/src/router/location.js b/modules/angular2/src/router/location.js index fe32064493..1d903619d1 100644 --- a/modules/angular2/src/router/location.js +++ b/modules/angular2/src/router/location.js @@ -1,4 +1,4 @@ -import {global} from 'angular2/src/facade/lang'; +import {DOM} from 'angular2/src/dom/dom_adapter'; import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; export class Location { @@ -7,9 +7,9 @@ export class Location { _history; constructor() { this._subject = new EventEmitter(); - this._location = global.location; - this._history = global.history; - global.addEventListener('popstate', (_) => this._onPopState(_), false); + this._location = DOM.getLocation(); + this._history = DOM.getHistory(); + DOM.getGlobalEventTarget('window').addEventListener('popstate', (_) => this._onPopState(_), false); } _onPopState(_) {