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

Side by Side Diff: lib/src/iron-selector/iron-selectable.html

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month 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 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 2 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 3 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 4 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 5 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 6 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 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
8 --> 8 -->
9 9
10 <link rel="import" href="../polymer/polymer.html"> 10 <link rel="import" href="../polymer/polymer.html">
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 * If you want to use the attribute value of an element for `selected` ins tead of the index, 49 * If you want to use the attribute value of an element for `selected` ins tead of the index,
50 * set this to the name of the attribute. 50 * set this to the name of the attribute.
51 */ 51 */
52 attrForSelected: { 52 attrForSelected: {
53 type: String, 53 type: String,
54 value: null 54 value: null
55 }, 55 },
56 56
57 /** 57 /**
58 * Gets or sets the selected element. The default is to use the index of t he item. 58 * Gets or sets the selected element. The default is to use the index of t he item.
59 *
60 * @type {string|number}
61 */ 59 */
62 selected: { 60 selected: {
63 type: String, 61 type: String,
64 notify: true 62 notify: true
65 }, 63 },
66 64
67 /** 65 /**
68 * Returns the currently selected item. 66 * Returns the currently selected item.
69 */ 67 */
70 selectedItem: { 68 selectedItem: {
(...skipping 29 matching lines...) Expand all
100 98
101 /** 99 /**
102 * The attribute to set on elements when selected. 100 * The attribute to set on elements when selected.
103 */ 101 */
104 selectedAttribute: { 102 selectedAttribute: {
105 type: String, 103 type: String,
106 value: null 104 value: null
107 }, 105 },
108 106
109 /** 107 /**
110 * The set of excluded elements where the key is the `localName` 108 * The set of excluded elements where the key is the `localName`
111 * of the element that will be ignored from the item list. 109 * of the element that will be ignored from the item list.
112 * 110 *
111 * @type {object}
113 * @default {template: 1} 112 * @default {template: 1}
114 */ 113 */
115 excludedLocalNames: { 114 _excludedLocalNames: {
116 type: Object, 115 type: Object,
117 value: function() { 116 value: function() {
118 return { 117 return {
119 'template': 1 118 'template': 1
120 }; 119 };
121 } 120 }
122 } 121 }
123 }, 122 },
124 123
125 observers: [ 124 observers: [
126 '_updateSelected(attrForSelected, selected)' 125 '_updateSelected(attrForSelected, selected)'
127 ], 126 ],
128 127
129 created: function() { 128 created: function() {
130 this._bindFilterItem = this._filterItem.bind(this); 129 this._bindFilterItem = this._filterItem.bind(this);
131 this._selection = new Polymer.IronSelection(this._applySelection.bind(this )); 130 this._selection = new Polymer.IronSelection(this._applySelection.bind(this ));
131 // TODO(cdata): When polymer/polymer#2535 lands, we do not need to do this
132 // book keeping anymore:
133 this.__listeningForActivate = false;
132 }, 134 },
133 135
134 attached: function() { 136 attached: function() {
135 this._observer = this._observeItems(this); 137 this._observer = this._observeItems(this);
136 this._contentObserver = this._observeContent(this); 138 this._contentObserver = this._observeContent(this);
139 if (!this.selectedItem && this.selected) {
140 this._updateSelected(this.attrForSelected,this.selected)
141 }
142 this._addListener(this.activateEvent);
137 }, 143 },
138 144
139 detached: function() { 145 detached: function() {
140 if (this._observer) { 146 if (this._observer) {
141 this._observer.disconnect(); 147 this._observer.disconnect();
142 } 148 }
143 if (this._contentObserver) { 149 if (this._contentObserver) {
144 this._contentObserver.disconnect(); 150 this._contentObserver.disconnect();
145 } 151 }
146 this._removeListener(this.activateEvent); 152 this._removeListener(this.activateEvent);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 * Selects the next item. 199 * Selects the next item.
194 * 200 *
195 * @method selectNext 201 * @method selectNext
196 */ 202 */
197 selectNext: function() { 203 selectNext: function() {
198 var index = (Number(this._valueToIndex(this.selected)) + 1) % this.items.l ength; 204 var index = (Number(this._valueToIndex(this.selected)) + 1) % this.items.l ength;
199 this.selected = this._indexToValue(index); 205 this.selected = this._indexToValue(index);
200 }, 206 },
201 207
202 _addListener: function(eventName) { 208 _addListener: function(eventName) {
209 if (!this.isAttached || this.__listeningForActivate) {
210 return;
211 }
212
213 this.__listeningForActivate = true;
203 this.listen(this, eventName, '_activateHandler'); 214 this.listen(this, eventName, '_activateHandler');
204 }, 215 },
205 216
206 _removeListener: function(eventName) { 217 _removeListener: function(eventName) {
207 this.unlisten(this, eventName, '_activateHandler'); 218 this.unlisten(this, eventName, '_activateHandler');
219 this.__listeningForActivate = false;
208 }, 220 },
209 221
210 _activateEventChanged: function(eventName, old) { 222 _activateEventChanged: function(eventName, old) {
211 this._removeListener(old); 223 this._removeListener(old);
212 this._addListener(eventName); 224 this._addListener(eventName);
213 }, 225 },
214 226
215 _updateSelected: function() { 227 _updateSelected: function() {
216 this._selectSelected(this.selected); 228 this._selectSelected(this.selected);
217 }, 229 },
218 230
219 _selectSelected: function(selected) { 231 _selectSelected: function(selected) {
220 this._selection.select(this._valueToItem(this.selected)); 232 this._selection.select(this._valueToItem(this.selected));
221 }, 233 },
222 234
223 _filterItem: function(node) { 235 _filterItem: function(node) {
224 return !this.excludedLocalNames[node.localName]; 236 return !this._excludedLocalNames[node.localName];
225 }, 237 },
226 238
227 _valueToItem: function(value) { 239 _valueToItem: function(value) {
228 return (value == null) ? null : this.items[this._valueToIndex(value)]; 240 return (value == null) ? null : this.items[this._valueToIndex(value)];
229 }, 241 },
230 242
231 _valueToIndex: function(value) { 243 _valueToIndex: function(value) {
232 if (this.attrForSelected) { 244 if (this.attrForSelected) {
233 for (var i = 0, item; item = this.items[i]; i++) { 245 for (var i = 0, item; item = this.items[i]; i++) {
234 if (this._valueForItem(item) == value) { 246 if (this._valueForItem(item) == value) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 _itemActivate: function(value, item) { 329 _itemActivate: function(value, item) {
318 if (!this.fire('iron-activate', 330 if (!this.fire('iron-activate',
319 {selected: value, item: item}, {cancelable: true}).defaultPrevented) { 331 {selected: value, item: item}, {cancelable: true}).defaultPrevented) {
320 this.select(value); 332 this.select(value);
321 } 333 }
322 } 334 }
323 335
324 }; 336 };
325 337
326 </script> 338 </script>
OLDNEW
« no previous file with comments | « lib/src/iron-selector/iron-multi-selectable.html ('k') | lib/src/iron-selector/iron-selection.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698