| OLD | NEW |
| 1 /** @polymerBehavior Polymer.IronMultiSelectableBehavior */ | 1 /** @polymerBehavior Polymer.IronMultiSelectableBehavior */ |
| 2 Polymer.IronMultiSelectableBehaviorImpl = { | 2 Polymer.IronMultiSelectableBehaviorImpl = { |
| 3 properties: { | 3 properties: { |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * If true, multiple selections are allowed. | 6 * If true, multiple selections are allowed. |
| 7 */ | 7 */ |
| 8 multi: { | 8 multi: { |
| 9 type: Boolean, | 9 type: Boolean, |
| 10 value: false, | 10 value: false, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 */ | 25 */ |
| 26 selectedItems: { | 26 selectedItems: { |
| 27 type: Array, | 27 type: Array, |
| 28 readOnly: true, | 28 readOnly: true, |
| 29 notify: true | 29 notify: true |
| 30 }, | 30 }, |
| 31 | 31 |
| 32 }, | 32 }, |
| 33 | 33 |
| 34 observers: [ | 34 observers: [ |
| 35 '_updateSelected(selectedValues)' | 35 '_updateSelected(selectedValues.splices)' |
| 36 ], | 36 ], |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * Selects the given value. If the `multi` property is true, then the select
ed state of the | 39 * Selects the given value. If the `multi` property is true, then the select
ed state of the |
| 40 * `value` will be toggled; otherwise the `value` will be selected. | 40 * `value` will be toggled; otherwise the `value` will be selected. |
| 41 * | 41 * |
| 42 * @method select | 42 * @method select |
| 43 * @param {string|number} value the value to select. | 43 * @param {string|number} value the value to select. |
| 44 */ | 44 */ |
| 45 select: function(value) { | 45 select: function(value) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 61 get _shouldUpdateSelection() { | 61 get _shouldUpdateSelection() { |
| 62 return this.selected != null || | 62 return this.selected != null || |
| 63 (this.selectedValues != null && this.selectedValues.length); | 63 (this.selectedValues != null && this.selectedValues.length); |
| 64 }, | 64 }, |
| 65 | 65 |
| 66 _updateAttrForSelected: function() { | 66 _updateAttrForSelected: function() { |
| 67 if (!this.multi) { | 67 if (!this.multi) { |
| 68 Polymer.IronSelectableBehavior._updateAttrForSelected.apply(this); | 68 Polymer.IronSelectableBehavior._updateAttrForSelected.apply(this); |
| 69 } else if (this._shouldUpdateSelection) { | 69 } else if (this._shouldUpdateSelection) { |
| 70 this.selectedValues = this.selectedItems.map(function(selectedItem) { | 70 this.selectedValues = this.selectedItems.map(function(selectedItem) { |
| 71 return this._indexToValue(this.indexOf(selectedItem)); | 71 return this._indexToValue(this.indexOf(selectedItem)); |
| 72 }, this).filter(function(unfilteredValue) { | 72 }, this).filter(function(unfilteredValue) { |
| 73 return unfilteredValue != null; | 73 return unfilteredValue != null; |
| 74 }, this); | 74 }, this); |
| 75 } | 75 } |
| 76 }, | 76 }, |
| 77 | 77 |
| 78 _updateSelected: function() { | 78 _updateSelected: function() { |
| 79 if (this.multi) { | 79 if (this.multi) { |
| 80 this._selectMulti(this.selectedValues); | 80 this._selectMulti(this.selectedValues); |
| 81 } else { | 81 } else { |
| 82 this._selectSelected(this.selected); | 82 this._selectSelected(this.selected); |
| 83 } | 83 } |
| 84 }, | 84 }, |
| 85 | 85 |
| 86 _selectMulti: function(values) { | 86 _selectMulti: function(values) { |
| 87 if (values) { | 87 if (values) { |
| 88 var selectedItems = this._valuesToItems(values); | 88 var selectedItems = this._valuesToItems(values); |
| 89 // clear all but the current selected items | 89 // clear all but the current selected items |
| 90 this._selection.clear(selectedItems); | 90 this._selection.clear(selectedItems); |
| 91 // select only those not selected yet | 91 // select only those not selected yet |
| 92 for (var i = 0; i < selectedItems.length; i++) { | 92 for (var i = 0; i < selectedItems.length; i++) { |
| 93 this._selection.setItemSelected(selectedItems[i], true); | 93 this._selection.setItemSelected(selectedItems[i], true); |
| 94 } | 94 } |
| 95 // Check for items, since this array is populated only when attached |
| 96 if (this.fallbackSelection && this.items.length && !this._selection.get(
).length) { |
| 97 var fallback = this._valueToItem(this.fallbackSelection); |
| 98 if (fallback) { |
| 99 this.selectedValues = [this.fallbackSelection]; |
| 100 } |
| 101 } |
| 95 } else { | 102 } else { |
| 96 this._selection.clear(); | 103 this._selection.clear(); |
| 97 } | 104 } |
| 98 }, | 105 }, |
| 99 | 106 |
| 100 _selectionChange: function() { | 107 _selectionChange: function() { |
| 101 var s = this._selection.get(); | 108 var s = this._selection.get(); |
| 102 if (this.multi) { | 109 if (this.multi) { |
| 103 this._setSelectedItems(s); | 110 this._setSelectedItems(s); |
| 104 } else { | 111 } else { |
| 105 this._setSelectedItems([s]); | 112 this._setSelectedItems([s]); |
| 106 this._setSelectedItem(s); | 113 this._setSelectedItem(s); |
| 107 } | 114 } |
| 108 }, | 115 }, |
| 109 | 116 |
| 110 _toggleSelected: function(value) { | 117 _toggleSelected: function(value) { |
| 111 var i = this.selectedValues.indexOf(value); | 118 var i = this.selectedValues.indexOf(value); |
| 112 var unselected = i < 0; | 119 var unselected = i < 0; |
| 113 if (unselected) { | 120 if (unselected) { |
| 114 this.push('selectedValues',value); | 121 this.push('selectedValues',value); |
| 115 } else { | 122 } else { |
| 116 this.splice('selectedValues',i,1); | 123 this.splice('selectedValues',i,1); |
| 117 } | 124 } |
| 118 this._selection.setItemSelected(this._valueToItem(value), unselected); | |
| 119 }, | 125 }, |
| 120 | 126 |
| 121 _valuesToItems: function(values) { | 127 _valuesToItems: function(values) { |
| 122 return (values == null) ? null : values.map(function(value) { | 128 return (values == null) ? null : values.map(function(value) { |
| 123 return this._valueToItem(value); | 129 return this._valueToItem(value); |
| 124 }, this); | 130 }, this); |
| 125 } | 131 } |
| 126 }; | 132 }; |
| 127 | 133 |
| 128 /** @polymerBehavior */ | 134 /** @polymerBehavior */ |
| 129 Polymer.IronMultiSelectableBehavior = [ | 135 Polymer.IronMultiSelectableBehavior = [ |
| 130 Polymer.IronSelectableBehavior, | 136 Polymer.IronSelectableBehavior, |
| 131 Polymer.IronMultiSelectableBehaviorImpl | 137 Polymer.IronMultiSelectableBehaviorImpl |
| 132 ]; | 138 ]; |
| OLD | NEW |