Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: third_party/polymer/v0_8/components/iron-selector/iron-multi-selectable.html

Issue 1162563004: Upgrade to 1.0 and switch clients to dom-repeat where needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a layout import and remove the gzipped webanimation in reproduce.sh Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 @license
2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt 4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt
6 Code distributed by Google as part of the polymer project is also 7 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
8 --> 9 -->
9 10
10 <link rel="import" href="../polymer/polymer.html"> 11 <link rel="import" href="../polymer/polymer.html">
11 <link rel="import" href="iron-selectable.html"> 12 <link rel="import" href="iron-selectable.html">
12 13
13 <script> 14 <script>
15 /** @polymerBehavior Polymer.IronMultiSelectableBehavior */
16 Polymer.IronMultiSelectableBehaviorImpl = {
17 properties: {
14 18
15 Polymer.IronMultiSelectableBehavior = [ 19 /**
16 Polymer.IronSelectableBehavior, { 20 * If true, multiple selections are allowed.
17 21 */
18 properties: { 22 multi: {
19 23 type: Boolean,
20 /** 24 value: false,
21 * If true, multiple selections are allowed. 25 observer: 'multiChanged'
22 *
23 * @attribute multi
24 * @type Boolean
25 * @default false
26 */
27 multi: {
28 type: Boolean,
29 value: false,
30 observer: 'multiChanged'
31 },
32
33 /**
34 * Gets or sets the selected elements. This is used instead of `selected ` when `multi`
35 * is true.
36 *
37 * @attribute selectedValues
38 * @type Array
39 */
40 selectedValues: {
41 type: Array,
42 notify: true
43 },
44
45 /**
46 * Returns an array of currently selected items.
47 *
48 * @attribute selectedItems
49 * @type Array
50 */
51 selectedItems: {
52 type: Array,
53 readOnly: true,
54 notify: true
55 },
56
57 }, 26 },
58 27
59 observers: [ 28 /**
60 '_updateSelected(attrForSelected, selectedValues)' 29 * Gets or sets the selected elements. This is used instead of `selected` when `multi`
61 ], 30 * is true.
31 */
32 selectedValues: {
33 type: Array,
34 notify: true
35 },
62 36
63 /** 37 /**
64 * Selects the given value. If the `multi` property is true, then the sele cted state of the 38 * Returns an array of currently selected items.
65 * `value` will be toggled; otherwise the `value` will be selected.
66 *
67 * @method select
68 * @param {string} value the value to select.
69 */ 39 */
70 select: function(value) { 40 selectedItems: {
71 if (this.multi) { 41 type: Array,
72 if (this.selectedValues) { 42 readOnly: true,
73 this._toggleSelected(value); 43 notify: true
74 } else {
75 this.selectedValues = [value];
76 }
77 } else {
78 this.selected = value;
79 }
80 }, 44 },
81 45
82 multiChanged: function(multi) { 46 },
83 this._selection.multi = multi;
84 },
85 47
86 _updateSelected: function() { 48 observers: [
87 if (this.multi) { 49 '_updateSelected(attrForSelected, selectedValues)'
88 this._selectMulti(this.selectedValues); 50 ],
51
52 /**
53 * Selects the given value. If the `multi` property is true, then the select ed state of the
54 * `value` will be toggled; otherwise the `value` will be selected.
55 *
56 * @method select
57 * @param {string} value the value to select.
58 */
59 select: function(value) {
60 if (this.multi) {
61 if (this.selectedValues) {
62 this._toggleSelected(value);
89 } else { 63 } else {
90 this._selectSelected(this.selected); 64 this.selectedValues = [value];
91 } 65 }
92 }, 66 } else {
67 this.selected = value;
68 }
69 },
93 70
94 _selectMulti: function(values) { 71 multiChanged: function(multi) {
95 this._selection.clear(); 72 this._selection.multi = multi;
96 if (values) { 73 },
97 for (var i = 0; i < values.length; i++) { 74
98 this._selection.setItemSelected(this._valueToItem(values[i]), true); 75 _updateSelected: function() {
99 } 76 if (this.multi) {
77 this._selectMulti(this.selectedValues);
78 } else {
79 this._selectSelected(this.selected);
80 }
81 },
82
83 _selectMulti: function(values) {
84 this._selection.clear();
85 if (values) {
86 for (var i = 0; i < values.length; i++) {
87 this._selection.setItemSelected(this._valueToItem(values[i]), true);
100 } 88 }
101 }, 89 }
90 },
102 91
103 _selectionChange: function() { 92 _selectionChange: function() {
104 var s = this._selection.get(); 93 var s = this._selection.get();
105 if (this.multi) { 94 if (this.multi) {
106 this._setSelectedItems(s); 95 this._setSelectedItems(s);
107 } else { 96 } else {
108 this._setSelectedItems([s]); 97 this._setSelectedItems([s]);
109 this._setSelectedItem(s); 98 this._setSelectedItem(s);
110 } 99 }
111 }, 100 },
112 101
113 _toggleSelected: function(value) { 102 _toggleSelected: function(value) {
114 var i = this.selectedValues.indexOf(value); 103 var i = this.selectedValues.indexOf(value);
115 var unselected = i < 0; 104 var unselected = i < 0;
116 if (unselected) { 105 if (unselected) {
117 this.selectedValues.push(value); 106 this.selectedValues.push(value);
118 } else { 107 } else {
119 this.selectedValues.splice(i, 1); 108 this.selectedValues.splice(i, 1);
120 }
121 this._selection.setItemSelected(this._valueToItem(value), unselected);
122 } 109 }
110 this._selection.setItemSelected(this._valueToItem(value), unselected);
111 }
112 };
123 113
124 } 114 /** @polymerBehavior */
115 Polymer.IronMultiSelectableBehavior = [
116 Polymer.IronSelectableBehavior,
117 Polymer.IronMultiSelectableBehaviorImpl
125 ]; 118 ];
126 119
127 </script> 120 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698