OLD | NEW |
1 | 1 |
2 Polymer({ | 2 Polymer({ |
3 | 3 |
4 is: 'more-route-selector', | 4 is: 'more-route-selector', |
5 | 5 |
6 behaviors: [ | 6 behaviors: [ |
7 MoreRouting.ContextAware, | 7 MoreRouting.ContextAware, |
8 ], | 8 ], |
9 | 9 |
10 properties: { | 10 properties: { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 this._updateRoutes(); | 92 this._updateRoutes(); |
93 }, | 93 }, |
94 | 94 |
95 /** | 95 /** |
96 * Handle a change in selected item, driven by the targeted selector. | 96 * Handle a change in selected item, driven by the targeted selector. |
97 * | 97 * |
98 * Note that this will fail if a route is chosen that requires params not | 98 * Note that this will fail if a route is chosen that requires params not |
99 * defined by the current URL. | 99 * defined by the current URL. |
100 */ | 100 */ |
101 _onSelectedItemChanged: function(event) { | 101 _onSelectedItemChanged: function(event) { |
| 102 if (this._settingSelection) return; |
102 var route = this._routeForItem(event.detail.value); | 103 var route = this._routeForItem(event.detail.value); |
103 if (!route) return; | 104 if (!route) return; |
104 route.navigateTo(); | 105 route.navigateTo(); |
105 }, | 106 }, |
106 | 107 |
107 _updateRoutes: function() { | 108 _updateRoutes: function() { |
108 var routes = []; | 109 var routes = []; |
109 if (this._managedSelector) { | 110 if (this._managedSelector) { |
110 routes = this._managedSelector.items.map(this._routeForItem.bind(this)); | 111 routes = this._managedSelector.items.map(this._routeForItem.bind(this)); |
111 } | 112 } |
112 this._setRoutes(routes); | 113 this._setRoutes(routes); |
113 }, | 114 }, |
114 | 115 |
115 _onMoreRouteChange: function(event) { | 116 _onMoreRouteChange: function(event) { |
116 if (!this._managedSelector) return; | 117 if (!this._managedSelector) return; |
117 var route = event.detail.newRoute; | 118 |
118 this._managedSelector.select(this.routes.indexOf(route)); | 119 var selected = ''; |
| 120 |
| 121 var index = this.routes.indexOf(event.detail.newRoute); |
| 122 var attrForSelected = this._managedSelector.attrForSelected; |
| 123 if (!attrForSelected) { |
| 124 selected = index; |
| 125 } else { |
| 126 var item = this._managedSelector.items[index]; |
| 127 if (item) |
| 128 selected = item[attrForSelected] || item.getAttribute(attrForSelected); |
| 129 } |
| 130 |
| 131 // Make sure that we don't turn around and re-navigate |
| 132 this._settingSelection = true; |
| 133 this._managedSelector.select(selected); |
| 134 this._settingSelection = false; |
119 }, | 135 }, |
120 | 136 |
121 _findTargetSelector: function() { | 137 _findTargetSelector: function() { |
122 var children = Polymer.dom(this).children; | 138 var children = Polymer.dom(this).children; |
123 if (children.length !== 1) { | 139 if (children.length !== 1) { |
124 console.error(this, 'expects only a single selector child'); | 140 console.error(this, 'expects only a single selector child'); |
125 return null; | 141 return null; |
126 } | 142 } |
127 | 143 |
128 var child = children[0]; | 144 var child = children[0]; |
(...skipping 17 matching lines...) Expand all Loading... |
146 } | 162 } |
147 var expression = item.getAttribute(this.routeAttribute); | 163 var expression = item.getAttribute(this.routeAttribute); |
148 var route = MoreRouting.getRoute(expression, this.parentRoute); | 164 var route = MoreRouting.getRoute(expression, this.parentRoute); |
149 // Associate the route w/ its element while we're here. | 165 // Associate the route w/ its element while we're here. |
150 item.moreRouteContext = route; | 166 item.moreRouteContext = route; |
151 | 167 |
152 return route; | 168 return route; |
153 }, | 169 }, |
154 | 170 |
155 }); | 171 }); |
OLD | NEW |