2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9 <link rel=
"import" href=
"../polymer/polymer.html">
11 <link rel=
"import" href=
"routing.html">
12 <link rel=
"import" href=
"more-route-context-aware.html">
21 MoreRouting
.ContextAware
,
27 * The name of this route. Behavior differs based on the presence of
28 * `path` during _declaration_.
30 * If `path` is present during declaration, it is registered via `name`.
32 * Otherwise, this `more-route` becomes a `reference` to the route with
33 * `name`. Changing `name` will update which route is referenced.
37 observer
: '_nameChanged',
41 * A path expression used to parse parameters from the window's URL.
45 obserer
: '_pathChanged',
49 * Whether this route should become a context for the element that
57 * The underlying `MoreRouting.Route` object that is being wrapped.
59 * @type {MoreRouting.Route}
65 observer
: '_routeChanged',
69 * The full path expression for this route, including routes this is
79 * Param values matching the current URL, or an empty object if not
89 * Whether the route matches the current URL.
99 routingReady: function() {
100 this._identityChanged();
103 _nameChanged: function(newName
, oldName
) {
105 console
.error('Changing the `name` property is not supported for', this);
108 this._identityChanged();
111 _pathChanged: function(newPath
, oldPath
) {
113 console
.error('Changing the `path` property is not supported for', this);
116 this._identityChanged();
119 _identityChanged: function() {
120 if (!this.routingIsReady
) return;
122 if (this.name
&& this.path
) {
123 this._setRoute(MoreRouting
.registerNamedRoute(this.name
, this.path
, this.parentRoute
));
124 } else if (this.name
) {
125 this._setRoute(MoreRouting
.getRouteByName(this.name
));
126 } else if (this.path
) {
127 this._setRoute(MoreRouting
.getRouteByPath(this.path
, this.parentRoute
));
129 this._setRoute(null);
133 _routeChanged: function() {
134 this._observeRoute();
135 this._setFullPath(this.route
.fullPath
);
136 // this._setParams(this.route.params);
137 this.params
= this.route
.params
;
138 this._setActive(this.route
.active
);
140 // @see MoreRouting.ContextAware
141 this.moreRouteContext
= this.route
;
144 var parent
= Polymer
.dom(this).parentNode
;
145 if (parent
.nodeType
!== Node
.ELEMENT_NODE
) {
146 parent
= parent
.host
;
149 if (parent
.nodeType
=== Node
.ELEMENT_NODE
) {
150 parent
.moreRouteContext
= this.route
;
152 console
.warn('Unable to determine parent element for', this, '- not setting a context');
157 _observeRoute: function() {
158 // TODO(nevir) https://github.com/Polymore/more-routing/issues/24
159 if (this._routeListener
) {
160 this._routeListener
.close();
161 this._routeListener
= null;
163 if (this._paramListener
) {
164 this._paramListener
.close();
165 this._paramListener
= null;
167 if (!this.route
) return;
169 this._routeListener
= this.route
.__subscribe(function() {
170 this._setActive(this.route
&& this.route
.active
);
173 this._paramListener
= this.route
.params
.__subscribe(function(key
, value
) {
174 // https://github.com/Polymer/polymer/issues/1505
175 this.notifyPath('params.' + key
, value
);
179 urlFor: function(params
) {
180 return this.route
.urlFor(params
);
183 navigateTo: function(params
) {
184 return this.route
.navigateTo(params
);
187 isCurrentUrl: function(params
) {
188 return this.route
.isCurrentUrl(params
);