Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/polymer/v1_0/components-chromium/iron-selector/iron-selectable-extracted.js

Issue 1862213002: Roll third_party/polymer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove obsolete appearance_browsertest.js, result of a previous bad merge. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** @polymerBehavior */ 1 /** @polymerBehavior */
2 Polymer.IronSelectableBehavior = { 2 Polymer.IronSelectableBehavior = {
3 3
4 /** 4 /**
5 * Fired when iron-selector is activated (selected or deselected). 5 * Fired when iron-selector is activated (selected or deselected).
6 * It is fired before the selected items are changed. 6 * It is fired before the selected items are changed.
7 * Cancel the event to abort selection. 7 * Cancel the event to abort selection.
8 * 8 *
9 * @event iron-activate 9 * @event iron-activate
10 */ 10 */
(...skipping 14 matching lines...) Expand all
25 * Fired when the list of selectable items changes (e.g., items are 25 * Fired when the list of selectable items changes (e.g., items are
26 * added or removed). The detail of the event is a list of mutation 26 * added or removed). The detail of the event is a list of mutation
27 * records that describe what changed. 27 * records that describe what changed.
28 * 28 *
29 * @event iron-items-changed 29 * @event iron-items-changed
30 */ 30 */
31 31
32 properties: { 32 properties: {
33 33
34 /** 34 /**
35 * If you want to use the attribute value of an element for `selected` ins tead of the index, 35 * If you want to use an attribute value or property of an element for
36 * set this to the name of the attribute. 36 * `selected` instead of the index, set this to the name of the attribute
37 * or property. Hyphenated values are converted to camel case when used to
38 * look up the property of a selectable element. Camel cased values are
39 * *not* converted to hyphenated values for attribute lookup. It's
40 * recommended that you provide the hyphenated form of the name so that
41 * selection works in both cases. (Use `attr-or-property-name` instead of
42 * `attrOrPropertyName`.)
37 */ 43 */
38 attrForSelected: { 44 attrForSelected: {
39 type: String, 45 type: String,
40 value: null 46 value: null
41 }, 47 },
42 48
43 /** 49 /**
44 * Gets or sets the selected element. The default is to use the index of t he item. 50 * Gets or sets the selected element. The default is to use the index of t he item.
45 * @type {string|number} 51 * @type {string|number}
46 */ 52 */
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 93
88 /** 94 /**
89 * The attribute to set on elements when selected. 95 * The attribute to set on elements when selected.
90 */ 96 */
91 selectedAttribute: { 97 selectedAttribute: {
92 type: String, 98 type: String,
93 value: null 99 value: null
94 }, 100 },
95 101
96 /** 102 /**
103 * Default fallback if the selection based on selected with `attrForSelect ed`
104 * is not found.
105 */
106 fallbackSelection: {
107 type: String,
108 value: null
109 },
110
111 /**
97 * The list of items from which a selection can be made. 112 * The list of items from which a selection can be made.
98 */ 113 */
99 items: { 114 items: {
100 type: Array, 115 type: Array,
101 readOnly: true, 116 readOnly: true,
102 notify: true, 117 notify: true,
103 value: function() { 118 value: function() {
104 return []; 119 return [];
105 } 120 }
106 }, 121 },
107 122
108 /** 123 /**
109 * The set of excluded elements where the key is the `localName` 124 * The set of excluded elements where the key is the `localName`
110 * of the element that will be ignored from the item list. 125 * of the element that will be ignored from the item list.
111 * 126 *
112 * @default {template: 1} 127 * @default {template: 1}
113 */ 128 */
114 _excludedLocalNames: { 129 _excludedLocalNames: {
115 type: Object, 130 type: Object,
116 value: function() { 131 value: function() {
117 return { 132 return {
118 'template': 1 133 'template': 1
119 }; 134 };
120 } 135 }
121 } 136 }
122 }, 137 },
123 138
124 observers: [ 139 observers: [
125 '_updateAttrForSelected(attrForSelected)', 140 '_updateAttrForSelected(attrForSelected)',
126 '_updateSelected(selected)' 141 '_updateSelected(selected)',
142 '_checkFallback(fallbackSelection)'
127 ], 143 ],
128 144
129 created: function() { 145 created: function() {
130 this._bindFilterItem = this._filterItem.bind(this); 146 this._bindFilterItem = this._filterItem.bind(this);
131 this._selection = new Polymer.IronSelection(this._applySelection.bind(this )); 147 this._selection = new Polymer.IronSelection(this._applySelection.bind(this ));
132 }, 148 },
133 149
134 attached: function() { 150 attached: function() {
135 this._observer = this._observeItems(this); 151 this._observer = this._observeItems(this);
136 this._updateItems(); 152 this._updateItems();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 * on its own to reflect selectable items in the DOM. 218 * on its own to reflect selectable items in the DOM.
203 */ 219 */
204 forceSynchronousItemUpdate: function() { 220 forceSynchronousItemUpdate: function() {
205 this._updateItems(); 221 this._updateItems();
206 }, 222 },
207 223
208 get _shouldUpdateSelection() { 224 get _shouldUpdateSelection() {
209 return this.selected != null; 225 return this.selected != null;
210 }, 226 },
211 227
228 _checkFallback: function() {
229 if (this._shouldUpdateSelection) {
230 this._updateSelected();
231 }
232 },
233
212 _addListener: function(eventName) { 234 _addListener: function(eventName) {
213 this.listen(this, eventName, '_activateHandler'); 235 this.listen(this, eventName, '_activateHandler');
214 }, 236 },
215 237
216 _removeListener: function(eventName) { 238 _removeListener: function(eventName) {
217 this.unlisten(this, eventName, '_activateHandler'); 239 this.unlisten(this, eventName, '_activateHandler');
218 }, 240 },
219 241
220 _activateEventChanged: function(eventName, old) { 242 _activateEventChanged: function(eventName, old) {
221 this._removeListener(old); 243 this._removeListener(old);
222 this._addListener(eventName); 244 this._addListener(eventName);
223 }, 245 },
224 246
225 _updateItems: function() { 247 _updateItems: function() {
226 var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*'); 248 var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*');
227 nodes = Array.prototype.filter.call(nodes, this._bindFilterItem); 249 nodes = Array.prototype.filter.call(nodes, this._bindFilterItem);
228 this._setItems(nodes); 250 this._setItems(nodes);
229 }, 251 },
230 252
231 _updateAttrForSelected: function() { 253 _updateAttrForSelected: function() {
232 if (this._shouldUpdateSelection) { 254 if (this._shouldUpdateSelection) {
233 this.selected = this._indexToValue(this.indexOf(this.selectedItem)); 255 this.selected = this._indexToValue(this.indexOf(this.selectedItem));
234 } 256 }
235 }, 257 },
236 258
237 _updateSelected: function() { 259 _updateSelected: function() {
238 this._selectSelected(this.selected); 260 this._selectSelected(this.selected);
239 }, 261 },
240 262
241 _selectSelected: function(selected) { 263 _selectSelected: function(selected) {
242 this._selection.select(this._valueToItem(this.selected)); 264 this._selection.select(this._valueToItem(this.selected));
265 // Check for items, since this array is populated only when attached
266 // Since Number(0) is falsy, explicitly check for undefined
267 if (this.fallbackSelection && this.items.length && (this._selection.get() === undefined)) {
268 this.selected = this.fallbackSelection;
269 }
243 }, 270 },
244 271
245 _filterItem: function(node) { 272 _filterItem: function(node) {
246 return !this._excludedLocalNames[node.localName]; 273 return !this._excludedLocalNames[node.localName];
247 }, 274 },
248 275
249 _valueToItem: function(value) { 276 _valueToItem: function(value) {
250 return (value == null) ? null : this.items[this._valueToIndex(value)]; 277 return (value == null) ? null : this.items[this._valueToIndex(value)];
251 }, 278 },
252 279
(...skipping 14 matching lines...) Expand all
267 var item = this.items[index]; 294 var item = this.items[index];
268 if (item) { 295 if (item) {
269 return this._valueForItem(item); 296 return this._valueForItem(item);
270 } 297 }
271 } else { 298 } else {
272 return index; 299 return index;
273 } 300 }
274 }, 301 },
275 302
276 _valueForItem: function(item) { 303 _valueForItem: function(item) {
277 var propValue = item[this.attrForSelected]; 304 var propValue = item[Polymer.CaseMap.dashToCamelCase(this.attrForSelected) ];
278 return propValue != undefined ? propValue : item.getAttribute(this.attrFor Selected); 305 return propValue != undefined ? propValue : item.getAttribute(this.attrFor Selected);
279 }, 306 },
280 307
281 _applySelection: function(item, isSelected) { 308 _applySelection: function(item, isSelected) {
282 if (this.selectedClass) { 309 if (this.selectedClass) {
283 this.toggleClass(this.selectedClass, isSelected, item); 310 this.toggleClass(this.selectedClass, isSelected, item);
284 } 311 }
285 if (this.selectedAttribute) { 312 if (this.selectedAttribute) {
286 this.toggleAttribute(this.selectedAttribute, isSelected, item); 313 this.toggleAttribute(this.selectedAttribute, isSelected, item);
287 } 314 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 }, 353 },
327 354
328 _itemActivate: function(value, item) { 355 _itemActivate: function(value, item) {
329 if (!this.fire('iron-activate', 356 if (!this.fire('iron-activate',
330 {selected: value, item: item}, {cancelable: true}).defaultPrevented) { 357 {selected: value, item: item}, {cancelable: true}).defaultPrevented) {
331 this.select(value); 358 this.select(value);
332 } 359 }
333 } 360 }
334 361
335 }; 362 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698