1 |
|
2 | import { isDefined } from '@uirouter/core';
|
3 | import { val, createProxyFunctions, removeFrom, isObject } from '@uirouter/core';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var Ng1LocationServices = (function () {
|
9 | function Ng1LocationServices($locationProvider) {
|
10 |
|
11 | this._urlListeners = [];
|
12 | this.$locationProvider = $locationProvider;
|
13 | var _lp = val($locationProvider);
|
14 | createProxyFunctions(_lp, this, _lp, ['hashPrefix']);
|
15 | }
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | Ng1LocationServices.monkeyPatchPathParameterType = function (router) {
|
29 | var pathType = router.urlMatcherFactory.type('path');
|
30 | pathType.encode = function (x) {
|
31 | return x != null ? x.toString().replace(/(~|\/)/g, function (m) { return ({ '~': '~~', '/': '~2F' }[m]); }) : x;
|
32 | };
|
33 | pathType.decode = function (x) {
|
34 | return x != null ? x.toString().replace(/(~~|~2F)/g, function (m) { return ({ '~~': '~', '~2F': '/' }[m]); }) : x;
|
35 | };
|
36 | };
|
37 |
|
38 | Ng1LocationServices.prototype.dispose = function () { };
|
39 | Ng1LocationServices.prototype.onChange = function (callback) {
|
40 | var _this = this;
|
41 | this._urlListeners.push(callback);
|
42 | return function () { return removeFrom(_this._urlListeners)(callback); };
|
43 | };
|
44 | Ng1LocationServices.prototype.html5Mode = function () {
|
45 | var html5Mode = this.$locationProvider.html5Mode();
|
46 | html5Mode = isObject(html5Mode) ? html5Mode.enabled : html5Mode;
|
47 | return html5Mode && this.$sniffer.history;
|
48 | };
|
49 | Ng1LocationServices.prototype.baseHref = function () {
|
50 | return this._baseHref || (this._baseHref = this.$browser.baseHref() || this.$window.location.pathname);
|
51 | };
|
52 | Ng1LocationServices.prototype.url = function (newUrl, replace, state) {
|
53 | if (replace === void 0) { replace = false; }
|
54 | if (isDefined(newUrl))
|
55 | this.$location.url(newUrl);
|
56 | if (replace)
|
57 | this.$location.replace();
|
58 | if (state)
|
59 | this.$location.state(state);
|
60 | return this.$location.url();
|
61 | };
|
62 | Ng1LocationServices.prototype._runtimeServices = function ($rootScope, $location, $sniffer, $browser, $window) {
|
63 | var _this = this;
|
64 | this.$location = $location;
|
65 | this.$sniffer = $sniffer;
|
66 | this.$browser = $browser;
|
67 | this.$window = $window;
|
68 |
|
69 | $rootScope.$on('$locationChangeSuccess', function (evt) { return _this._urlListeners.forEach(function (fn) { return fn(evt); }); });
|
70 | var _loc = val($location);
|
71 |
|
72 | createProxyFunctions(_loc, this, _loc, ['replace', 'path', 'search', 'hash']);
|
73 |
|
74 | createProxyFunctions(_loc, this, _loc, ['port', 'protocol', 'host']);
|
75 | };
|
76 | return Ng1LocationServices;
|
77 | }());
|
78 | export { Ng1LocationServices };
|
79 |
|
\ | No newline at end of file |