UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

55 lines (54 loc) 2.52 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Injectable } from 'angular2/src/core/di/decorators'; import { PlatformLocation } from './platform_location'; import { DOM } from 'angular2/src/platform/dom/dom_adapter'; /** * `PlatformLocation` encapsulates all of the direct calls to platform APIs. * This class should not be used directly by an application developer. Instead, use * {@link Location}. */ export let BrowserPlatformLocation = class BrowserPlatformLocation extends PlatformLocation { constructor() { super(); this._init(); } // This is moved to its own method so that `MockPlatformLocationStrategy` can overwrite it /** @internal */ _init() { this._location = DOM.getLocation(); this._history = DOM.getHistory(); } /** @internal */ get location() { return this._location; } getBaseHrefFromDOM() { return DOM.getBaseHref(); } onPopState(fn) { DOM.getGlobalEventTarget('window').addEventListener('popstate', fn, false); } onHashChange(fn) { DOM.getGlobalEventTarget('window').addEventListener('hashchange', fn, false); } get pathname() { return this._location.pathname; } get search() { return this._location.search; } get hash() { return this._location.hash; } set pathname(newPath) { this._location.pathname = newPath; } pushState(state, title, url) { this._history.pushState(state, title, url); } replaceState(state, title, url) { this._history.replaceState(state, title, url); } forward() { this._history.forward(); } back() { this._history.back(); } }; BrowserPlatformLocation = __decorate([ Injectable(), __metadata('design:paramtypes', []) ], BrowserPlatformLocation);