3 is: 'more-route-selector',
6 MoreRouting.ContextAware,
12 * The attribute to read route expressions from (on children).
20 * The routes managed by this element (inferred from the items that are
21 * defined by the selector it targets).
30 * The selected `MoreRouting.Route` object, or `null`.
32 * @type {MoreRouting.Route}
42 * The index of the selected route (relative to `routes`). -1 when there
53 * The _full_ path expression of the selected route, or `null`.
62 * The params of the selected route, or an empty object if no route.
73 * @event more-route-selected fires when a new route is selected.
75 * newRoute: MoreRouting.Route, oldRoute: MoreRouting.Route,
76 * newIndex: number, oldIndex: number,
77 * newPath: ?string, oldPath: ?string,
78 * newParams: Object, oldParams: Object,
82 attached: function() {
83 this._managedSelector = this._findTargetSelector();
84 if (!this._managedSelector) {
85 console.warn(this, 'was built without a selector to manage. It will do nothing.');
89 this._managedSelector.addEventListener(
90 'selected-item-changed', this._onSelectedItemChanged.bind(this));
95 * Handle a change in selected item, driven by the targeted selector.
97 * Note that this will fail if a route is chosen that requires params not
98 * defined by the current URL.
100 _onSelectedItemChanged: function(event) {
101 if (this._settingSelection) return;
102 var route = this._routeForItem(event.detail.value);
107 _updateRoutes: function() {
109 if (this._managedSelector) {
110 routes = this._managedSelector.items.map(this._routeForItem.bind(this));
112 this._setRoutes(routes);
115 _onMoreRouteChange: function(event) {
116 if (!this._managedSelector) return;
120 var index = this.routes.indexOf(event.detail.newRoute);
121 var attrForSelected = this._managedSelector.attrForSelected;
122 if (!attrForSelected) {
125 var item = this._managedSelector.items[index];
127 selected = item[attrForSelected] || item.getAttribute(attrForSelected);
130 // Make sure that we don't turn around and re-navigate
131 this._settingSelection = true;
132 this._managedSelector.select(selected);
133 this._settingSelection = false;
136 _findTargetSelector: function() {
137 var children = Polymer.dom(this).children;
138 if (children.length !== 1) {
139 console.error(this, 'expects only a single selector child');
143 var child = children[0];
144 if ('selected' in child && 'items' in child) {
147 console.error(this, 'can only manage children that are selectors');
152 _routeForItem: function(item) {
153 if (!item) return null;
154 if (item.moreRouteContext && item.moreRouteContext instanceof MoreRouting.Route) {
155 return item.moreRouteContext;
158 if (!item.hasAttribute(this.routeAttribute)) {
159 console.warn(item, 'is missing a context route or "' + this.routeAttribute + '" attribute');
162 var expression = item.getAttribute(this.routeAttribute);
163 var route = MoreRouting.getRoute(expression, this.parentRoute);
164 // Associate the route w/ its element while we're here.
165 item.moreRouteContext = route;