| OLD | NEW |
| (Empty) |
| 1 | |
| 2 /** @polymerBehavior Polymer.IronMultiSelectableBehavior */ | |
| 3 Polymer.IronMultiSelectableBehaviorImpl = { | |
| 4 properties: { | |
| 5 | |
| 6 /** | |
| 7 * If true, multiple selections are allowed. | |
| 8 */ | |
| 9 multi: { | |
| 10 type: Boolean, | |
| 11 value: false, | |
| 12 observer: 'multiChanged' | |
| 13 }, | |
| 14 | |
| 15 /** | |
| 16 * Gets or sets the selected elements. This is used instead of `selected`
when `multi` | |
| 17 * is true. | |
| 18 */ | |
| 19 selectedValues: { | |
| 20 type: Array, | |
| 21 notify: true | |
| 22 }, | |
| 23 | |
| 24 /** | |
| 25 * Returns an array of currently selected items. | |
| 26 */ | |
| 27 selectedItems: { | |
| 28 type: Array, | |
| 29 readOnly: true, | |
| 30 notify: true | |
| 31 }, | |
| 32 | |
| 33 }, | |
| 34 | |
| 35 observers: [ | |
| 36 '_updateSelected(attrForSelected, selectedValues)' | |
| 37 ], | |
| 38 | |
| 39 /** | |
| 40 * Selects the given value. If the `multi` property is true, then the select
ed state of the | |
| 41 * `value` will be toggled; otherwise the `value` will be selected. | |
| 42 * | |
| 43 * @method select | |
| 44 * @param {string} value the value to select. | |
| 45 */ | |
| 46 select: function(value) { | |
| 47 if (this.multi) { | |
| 48 if (this.selectedValues) { | |
| 49 this._toggleSelected(value); | |
| 50 } else { | |
| 51 this.selectedValues = [value]; | |
| 52 } | |
| 53 } else { | |
| 54 this.selected = value; | |
| 55 } | |
| 56 }, | |
| 57 | |
| 58 multiChanged: function(multi) { | |
| 59 this._selection.multi = multi; | |
| 60 }, | |
| 61 | |
| 62 _updateSelected: function() { | |
| 63 if (this.multi) { | |
| 64 this._selectMulti(this.selectedValues); | |
| 65 } else { | |
| 66 this._selectSelected(this.selected); | |
| 67 } | |
| 68 }, | |
| 69 | |
| 70 _selectMulti: function(values) { | |
| 71 this._selection.clear(); | |
| 72 if (values) { | |
| 73 for (var i = 0; i < values.length; i++) { | |
| 74 this._selection.setItemSelected(this._valueToItem(values[i]), true); | |
| 75 } | |
| 76 } | |
| 77 }, | |
| 78 | |
| 79 _selectionChange: function() { | |
| 80 var s = this._selection.get(); | |
| 81 if (this.multi) { | |
| 82 this._setSelectedItems(s); | |
| 83 } else { | |
| 84 this._setSelectedItems([s]); | |
| 85 this._setSelectedItem(s); | |
| 86 } | |
| 87 }, | |
| 88 | |
| 89 _toggleSelected: function(value) { | |
| 90 var i = this.selectedValues.indexOf(value); | |
| 91 var unselected = i < 0; | |
| 92 if (unselected) { | |
| 93 this.selectedValues.push(value); | |
| 94 } else { | |
| 95 this.selectedValues.splice(i, 1); | |
| 96 } | |
| 97 this._selection.setItemSelected(this._valueToItem(value), unselected); | |
| 98 } | |
| 99 }; | |
| 100 | |
| 101 /** @polymerBehavior */ | |
| 102 Polymer.IronMultiSelectableBehavior = [ | |
| 103 Polymer.IronSelectableBehavior, | |
| 104 Polymer.IronMultiSelectableBehaviorImpl | |
| 105 ]; | |
| 106 | |
| OLD | NEW |