2 Polymer('core-selection', {
4 * If true, multiple selections are allowed.
18 * Retrieves the selected item(s).
19 * @method getSelection
20 * @returns Returns the selected item(s). If the multi property is true,
21 * getSelection will return an array, otherwise it will return
22 * the selected item or undefined if there is no selection.
24 getSelection: function() {
25 return this.multi
? this.selection
: this.selection
[0];
28 * Indicates if a given item is selected.
30 * @param {any} item The item whose selection state should be checked.
31 * @returns Returns true if `item` is selected.
33 isSelected: function(item
) {
34 return this.selection
.indexOf(item
) >= 0;
36 setItemSelected: function(item
, isSelected
) {
37 if (item
!== undefined && item
!== null) {
39 this.selection
.push(item
);
41 var i
= this.selection
.indexOf(item
);
43 this.selection
.splice(i
, 1);
46 this.fire("core-select", {isSelected
: isSelected
, item
: item
});
50 * Set the selection state for a given `item`. If the multi property
51 * is true, then the selected state of `item` will be toggled; otherwise
52 * the `item` will be selected.
54 * @param {any} item: The item to select.
56 select: function(item
) {
59 } else if (this.getSelection() !== item
) {
60 this.setItemSelected(this.getSelection(), false);
61 this.setItemSelected(item
, true);
65 * Toggles the selection state for `item`.
67 * @param {any} item: The item to toggle.
69 toggle: function(item
) {
70 this.setItemSelected(item
, !this.isSelected(item
));