4 * @param {!Function} selectCallback
7 Polymer.IronSelection = function(selectCallback) {
9 this.selectCallback = selectCallback;
12 Polymer.IronSelection.prototype = {
15 * Retrieves the selected item(s).
18 * @returns Returns the selected item(s). If the multi property is true,
19 * `get` will return an array, otherwise it will return
20 * the selected item or undefined if there is no selection.
23 return this.multi ? this.selection : this.selection[0];
27 * Clears all the selection except the ones indicated.
30 * @param {Array} excludes items to be excluded.
32 clear: function(excludes) {
33 this.selection.slice().forEach(function(item) {
34 if (!excludes || excludes.indexOf(item) < 0) {
35 this.setItemSelected(item, false);
41 * Indicates if a given item is selected.
44 * @param {*} item The item whose selection state should be checked.
45 * @returns Returns true if `item` is selected.
47 isSelected: function(item) {
48 return this.selection.indexOf(item) >= 0;
52 * Sets the selection state for a given item to either selected or deselected.
54 * @method setItemSelected
55 * @param {*} item The item to select.
56 * @param {boolean} isSelected True for selected, false for deselected.
58 setItemSelected: function(item, isSelected) {
61 this.selection.push(item);
63 var i = this.selection.indexOf(item);
65 this.selection.splice(i, 1);
68 if (this.selectCallback) {
69 this.selectCallback(item, isSelected);
75 * Sets the selection state for a given item. If the `multi` property
76 * is true, then the selected state of `item` will be toggled; otherwise
77 * the `item` will be selected.
80 * @param {*} item The item to select.
82 select: function(item) {
85 } else if (this.get() !== item) {
86 this.setItemSelected(this.get(), false);
87 this.setItemSelected(item, true);
92 * Toggles the selection state for `item`.
95 * @param {*} item The item to toggle.
97 toggle: function(item) {
98 this.setItemSelected(item, !this.isSelected(item));