| OLD | NEW |
| 1 /** | 1 /** |
| 2 * @param {!Function} selectCallback | 2 * @param {!Function} selectCallback |
| 3 * @constructor | 3 * @constructor |
| 4 */ | 4 */ |
| 5 Polymer.IronSelection = function(selectCallback) { | 5 Polymer.IronSelection = function(selectCallback) { |
| 6 this.selection = []; | 6 this.selection = []; |
| 7 this.selectCallback = selectCallback; | 7 this.selectCallback = selectCallback; |
| 8 }; | 8 }; |
| 9 | 9 |
| 10 Polymer.IronSelection.prototype = { | 10 Polymer.IronSelection.prototype = { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Sets the selection state for a given item to either selected or deselecte
d. | 50 * Sets the selection state for a given item to either selected or deselecte
d. |
| 51 * | 51 * |
| 52 * @method setItemSelected | 52 * @method setItemSelected |
| 53 * @param {*} item The item to select. | 53 * @param {*} item The item to select. |
| 54 * @param {boolean} isSelected True for selected, false for deselected. | 54 * @param {boolean} isSelected True for selected, false for deselected. |
| 55 */ | 55 */ |
| 56 setItemSelected: function(item, isSelected) { | 56 setItemSelected: function(item, isSelected) { |
| 57 if (item != null) { | 57 if (item != null) { |
| 58 if (isSelected) { | 58 if (isSelected !== this.isSelected(item)) { |
| 59 this.selection.push(item); | 59 // proceed to update selection only if requested state differs from cu
rrent |
| 60 } else { | 60 if (isSelected) { |
| 61 var i = this.selection.indexOf(item); | 61 this.selection.push(item); |
| 62 if (i >= 0) { | 62 } else { |
| 63 this.selection.splice(i, 1); | 63 var i = this.selection.indexOf(item); |
| 64 if (i >= 0) { |
| 65 this.selection.splice(i, 1); |
| 66 } |
| 64 } | 67 } |
| 65 } | 68 if (this.selectCallback) { |
| 66 if (this.selectCallback) { | 69 this.selectCallback(item, isSelected); |
| 67 this.selectCallback(item, isSelected); | 70 } |
| 68 } | 71 } |
| 69 } | 72 } |
| 70 }, | 73 }, |
| 71 | 74 |
| 72 /** | 75 /** |
| 73 * Sets the selection state for a given item. If the `multi` property | 76 * Sets the selection state for a given item. If the `multi` property |
| 74 * is true, then the selected state of `item` will be toggled; otherwise | 77 * is true, then the selected state of `item` will be toggled; otherwise |
| 75 * the `item` will be selected. | 78 * the `item` will be selected. |
| 76 * | 79 * |
| 77 * @method select | 80 * @method select |
| (...skipping 12 matching lines...) Expand all Loading... |
| 90 * Toggles the selection state for `item`. | 93 * Toggles the selection state for `item`. |
| 91 * | 94 * |
| 92 * @method toggle | 95 * @method toggle |
| 93 * @param {*} item The item to toggle. | 96 * @param {*} item The item to toggle. |
| 94 */ | 97 */ |
| 95 toggle: function(item) { | 98 toggle: function(item) { |
| 96 this.setItemSelected(item, !this.isSelected(item)); | 99 this.setItemSelected(item, !this.isSelected(item)); |
| 97 } | 100 } |
| 98 | 101 |
| 99 }; | 102 }; |
| OLD | NEW |