3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 <link rel=
"import" href=
"../polymer/polymer.html">
12 <link rel=
"import" href=
"iron-selectable.html">
15 /** @polymerBehavior Polymer.IronMultiSelectableBehavior */
16 Polymer
.IronMultiSelectableBehaviorImpl
= {
20 * If true, multiple selections are allowed.
25 observer
: 'multiChanged'
29 * Gets or sets the selected elements. This is used instead of `selected` when `multi`
38 * Returns an array of currently selected items.
49 '_updateSelected(attrForSelected, selectedValues)'
53 * Selects the given value. If the `multi` property is true, then the selected state of the
54 * `value` will be toggled; otherwise the `value` will be selected.
57 * @param {string} value the value to select.
59 select: function(value
) {
61 if (this.selectedValues
) {
62 this._toggleSelected(value
);
64 this.selectedValues
= [value
];
67 this.selected
= value
;
71 multiChanged: function(multi
) {
72 this._selection
.multi
= multi
;
75 _updateSelected: function() {
77 this._selectMulti(this.selectedValues
);
79 this._selectSelected(this.selected
);
83 _selectMulti: function(values
) {
84 this._selection
.clear();
86 for (var i
= 0; i
< values
.length
; i
++) {
87 this._selection
.setItemSelected(this._valueToItem(values
[i
]), true);
92 _selectionChange: function() {
93 var s
= this._selection
.get();
95 this._setSelectedItems(s
);
97 this._setSelectedItems([s
]);
98 this._setSelectedItem(s
);
102 _toggleSelected: function(value
) {
103 var i
= this.selectedValues
.indexOf(value
);
104 var unselected
= i
< 0;
106 this.selectedValues
.push(value
);
108 this.selectedValues
.splice(i
, 1);
110 this._selection
.setItemSelected(this._valueToItem(value
), unselected
);
114 /** @polymerBehavior */
115 Polymer
.IronMultiSelectableBehavior
= [
116 Polymer
.IronSelectableBehavior
,
117 Polymer
.IronMultiSelectableBehaviorImpl