|
130 | 130 |
|
131 | 131 | /** |
132 | 132 | * Specifies the CSS class to be used to add to the selected element. |
133 | | - * |
| 133 | + * |
134 | 134 | * @attribute selectedClass |
135 | 135 | * @type string |
136 | 136 | * @default 'core-selected' |
|
162 | 162 | * an array of selected elements. |
163 | 163 | * Note that you should not use this to set the selection. Instead use |
164 | 164 | * `selected`. |
165 | | - * |
| 165 | + * |
166 | 166 | * @attribute selectedItem |
167 | 167 | * @type Object |
168 | 168 | * @default null |
|
172 | 172 | /** |
173 | 173 | * In single selection, this returns the model associated with the |
174 | 174 | * selected element. |
175 | | - * Note that you should not use this to set the selection. Instead use |
| 175 | + * Note that you should not use this to set the selection. Instead use |
176 | 176 | * `selected`. |
177 | | - * |
| 177 | + * |
178 | 178 | * @attribute selectedModel |
179 | 179 | * @type Object |
180 | 180 | * @default null |
|
193 | 193 | selectedIndex: -1, |
194 | 194 |
|
195 | 195 | /** |
196 | | - * Nodes with local name that are in the list will not be included |
| 196 | + * Nodes with local name that are in the list will not be included |
197 | 197 | * in the selection items. In the following example, `items` returns four |
198 | 198 | * `core-item`'s and doesn't include `h3` and `hr`. |
199 | 199 | * |
|
213 | 213 | excludedLocalNames: '', |
214 | 214 |
|
215 | 215 | /** |
216 | | - * The target element that contains items. If this is not set |
| 216 | + * The target element that contains items. If this is not set |
217 | 217 | * core-selector is the container. |
218 | | - * |
| 218 | + * |
219 | 219 | * @attribute target |
220 | 220 | * @type Object |
221 | 221 | * @default null |
222 | 222 | */ |
223 | 223 | target: null, |
224 | 224 |
|
225 | 225 | /** |
226 | | - * This can be used to query nodes from the target node to be used for |
| 226 | + * This can be used to query nodes from the target node to be used for |
227 | 227 | * selection items. Note this only works if `target` is set |
228 | 228 | * and is not `core-selector` itself. |
229 | 229 | * |
|
236 | 236 | * <label><input type="radio" name="color" value="blue"> Blue</label> <br> |
237 | 237 | * <p>color = {{color}}</p> |
238 | 238 | * </form> |
239 | | - * |
| 239 | + * |
240 | 240 | * @attribute itemsSelector |
241 | 241 | * @type string |
242 | 242 | * @default '' |
|
264 | 264 | notap: false, |
265 | 265 |
|
266 | 266 | defaultExcludedLocalNames: 'template', |
267 | | - |
| 267 | + |
268 | 268 | observe: { |
269 | 269 | 'selected multi': 'selectedChanged' |
270 | 270 | }, |
|
288 | 288 | if (!this.target) { |
289 | 289 | return []; |
290 | 290 | } |
291 | | - var nodes = this.target !== this ? (this.itemsSelector ? |
292 | | - this.target.querySelectorAll(this.itemsSelector) : |
| 291 | + var nodes = this.target !== this ? (this.itemsSelector ? |
| 292 | + this.target.querySelectorAll(this.itemsSelector) : |
293 | 293 | this.target.children) : this.$.items.getDistributedNodes(); |
294 | 294 | return Array.prototype.filter.call(nodes, this.itemFilter); |
295 | 295 | }, |
|
332 | 332 |
|
333 | 333 | /** |
334 | 334 | * Returns the selected item(s). If the `multi` property is true, |
335 | | - * this will return an array, otherwise it will return |
| 335 | + * this will return an array, otherwise it will return |
336 | 336 | * the selected item or undefined if there is no selection. |
337 | 337 | */ |
338 | 338 | get selection() { |
|
348 | 348 | this.updateSelected(); |
349 | 349 | } |
350 | 350 | }, |
351 | | - |
| 351 | + |
352 | 352 | updateSelected: function() { |
353 | 353 | this.validateSelected(); |
354 | 354 | if (this.multi) { |
|
363 | 363 |
|
364 | 364 | validateSelected: function() { |
365 | 365 | // convert to an array for multi-selection |
366 | | - if (this.multi && !Array.isArray(this.selected) && |
| 366 | + if (this.multi && !Array.isArray(this.selected) && |
367 | 367 | this.selected != null) { |
368 | 368 | this.selected = [this.selected]; |
369 | 369 | // use the first selected in the array for single-selection |
|
373 | 373 | this.selected = s; |
374 | 374 | } |
375 | 375 | }, |
376 | | - |
| 376 | + |
377 | 377 | processSplices: function(splices) { |
378 | 378 | for (var i = 0, splice; splice = splices[i]; i++) { |
379 | 379 | for (var j = 0; j < splice.removed.length; j++) { |
|
398 | 398 | var item = this.valueToItem(value); |
399 | 399 | this.$.selection.select(item); |
400 | 400 | }, |
401 | | - |
| 401 | + |
402 | 402 | setValueSelected: function(value, isSelected) { |
403 | 403 | var item = this.valueToItem(value); |
404 | 404 | if (isSelected ^ this.$.selection.isSelected(item)) { |
|
417 | 417 | } else { |
418 | 418 | this.selectedModel = null; |
419 | 419 | } |
420 | | - this.selectedIndex = this.selectedItem ? |
| 420 | + this.selectedIndex = this.selectedItem ? |
421 | 421 | parseInt(this.valueToIndex(this.selected)) : -1; |
422 | 422 | }, |
423 | | - |
| 423 | + |
424 | 424 | valueToItem: function(value) { |
425 | | - return (value === null || value === undefined) ? |
| 425 | + return (value === null || value === undefined) ? |
426 | 426 | null : this.items[this.valueToIndex(value)]; |
427 | 427 | }, |
428 | 428 |
|
|
506 | 506 | target = target.parentNode; |
507 | 507 | } |
508 | 508 | }, |
509 | | - |
| 509 | + |
510 | 510 | selectIndex: function(index) { |
511 | 511 | var item = this.items[index]; |
512 | 512 | if (item) { |
513 | 513 | this.selected = this.valueForNode(item) || index; |
514 | 514 | return item; |
515 | 515 | } |
516 | 516 | }, |
517 | | - |
| 517 | + |
518 | 518 | /** |
519 | 519 | * Selects the previous item. This should be used in single selection only. |
520 | 520 | * |
|
524 | 524 | * @returns the previous item or undefined if there is none |
525 | 525 | */ |
526 | 526 | selectPrevious: function(wrapped) { |
527 | | - var i = wrapped && !this.selectedIndex ? |
| 527 | + var i = wrapped && !this.selectedIndex ? |
528 | 528 | this.items.length - 1 : this.selectedIndex - 1; |
529 | 529 | return this.selectIndex(i); |
530 | 530 | }, |
531 | | - |
| 531 | + |
532 | 532 | /** |
533 | 533 | * Selects the next item. This should be used in single selection only. |
534 | 534 | * |
|
538 | 538 | * @returns the next item or undefined if there is none |
539 | 539 | */ |
540 | 540 | selectNext: function(wrapped) { |
541 | | - var i = wrapped && this.selectedIndex >= this.items.length - 1 ? |
| 541 | + var i = wrapped && this.selectedIndex >= this.items.length - 1 ? |
542 | 542 | 0 : this.selectedIndex + 1; |
543 | 543 | return this.selectIndex(i); |
544 | 544 | } |
545 | | - |
| 545 | + |
546 | 546 | }); |
547 | 547 | </script> |
548 | 548 | </polymer-element> |
0 commit comments