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