Add ICU message format support
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / iron-selector / iron-multi-selectable-extracted.js
bloba595e492e8270a6bd0f1ea50f2ccd87cfb276918
2   /** @polymerBehavior Polymer.IronMultiSelectableBehavior */
3   Polymer.IronMultiSelectableBehaviorImpl = {
4     properties: {
6       /**
7        * If true, multiple selections are allowed.
8        */
9       multi: {
10         type: Boolean,
11         value: false,
12         observer: 'multiChanged'
13       },
15       /**
16        * Gets or sets the selected elements. This is used instead of `selected` when `multi`
17        * is true.
18        */
19       selectedValues: {
20         type: Array,
21         notify: true
22       },
24       /**
25        * Returns an array of currently selected items.
26        */
27       selectedItems: {
28         type: Array,
29         readOnly: true,
30         notify: true
31       },
33     },
35     observers: [
36       '_updateSelected(attrForSelected, selectedValues)'
37     ],
39     /**
40      * Selects the given value. If the `multi` property is true, then the selected state of the
41      * `value` will be toggled; otherwise the `value` will be selected.
42      *
43      * @method select
44      * @param {string} value the value to select.
45      */
46     select: function(value) {
47       if (this.multi) {
48         if (this.selectedValues) {
49           this._toggleSelected(value);
50         } else {
51           this.selectedValues = [value];
52         }
53       } else {
54         this.selected = value;
55       }
56     },
58     multiChanged: function(multi) {
59       this._selection.multi = multi;
60     },
62     _updateSelected: function() {
63       if (this.multi) {
64         this._selectMulti(this.selectedValues);
65       } else {
66         this._selectSelected(this.selected);
67       }
68     },
70     _selectMulti: function(values) {
71       this._selection.clear();
72       if (values) {
73         for (var i = 0; i < values.length; i++) {
74           this._selection.setItemSelected(this._valueToItem(values[i]), true);
75         }
76       }
77     },
79     _selectionChange: function() {
80       var s = this._selection.get();
81       if (this.multi) {
82         this._setSelectedItems(s);
83       } else {
84         this._setSelectedItems([s]);
85         this._setSelectedItem(s);
86       }
87     },
89     _toggleSelected: function(value) {
90       var i = this.selectedValues.indexOf(value);
91       var unselected = i < 0;
92       if (unselected) {
93         this.selectedValues.push(value);
94       } else {
95         this.selectedValues.splice(i, 1);
96       }
97       this._selection.setItemSelected(this._valueToItem(value), unselected);
98     }
99   };
101   /** @polymerBehavior */
102   Polymer.IronMultiSelectableBehavior = [
103     Polymer.IronSelectableBehavior,
104     Polymer.IronMultiSelectableBehaviorImpl
105   ];