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

Side by Side Diff: third_party/polymer/v1_0/components-chromium/iron-selector/iron-selectable-extracted.js

Issue 1766433002: Roll Polymer to 1.3.1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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 /** @polymerBehavior */ 1 /** @polymerBehavior */
2 Polymer.IronSelectableBehavior = { 2 Polymer.IronSelectableBehavior = {
3 3
4 /** 4 /**
5 * Fired when iron-selector is activated (selected or deselected). 5 * Fired when iron-selector is activated (selected or deselected).
6 * It is fired before the selected items are changed. 6 * It is fired before the selected items are changed.
7 * Cancel the event to abort selection. 7 * Cancel the event to abort selection.
8 * 8 *
9 * @event iron-activate 9 * @event iron-activate
10 */ 10 */
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 type: Object, 115 type: Object,
116 value: function() { 116 value: function() {
117 return { 117 return {
118 'template': 1 118 'template': 1
119 }; 119 };
120 } 120 }
121 } 121 }
122 }, 122 },
123 123
124 observers: [ 124 observers: [
125 '_updateSelected(attrForSelected, selected)' 125 '_updateAttrForSelected(attrForSelected)',
126 '_updateSelected(selected)'
126 ], 127 ],
127 128
128 created: function() { 129 created: function() {
129 this._bindFilterItem = this._filterItem.bind(this); 130 this._bindFilterItem = this._filterItem.bind(this);
130 this._selection = new Polymer.IronSelection(this._applySelection.bind(this )); 131 this._selection = new Polymer.IronSelection(this._applySelection.bind(this ));
131 }, 132 },
132 133
133 attached: function() { 134 attached: function() {
134 this._observer = this._observeItems(this); 135 this._observer = this._observeItems(this);
135 this._updateItems(); 136 this._updateItems();
136 if (!this._shouldUpdateSelection) { 137 if (!this._shouldUpdateSelection) {
137 this._updateSelected(this.attrForSelected,this.selected) 138 this._updateSelected();
138 } 139 }
139 this._addListener(this.activateEvent); 140 this._addListener(this.activateEvent);
140 }, 141 },
141 142
142 detached: function() { 143 detached: function() {
143 if (this._observer) { 144 if (this._observer) {
144 Polymer.dom(this).unobserveNodes(this._observer); 145 Polymer.dom(this).unobserveNodes(this._observer);
145 } 146 }
146 this._removeListener(this.activateEvent); 147 this._removeListener(this.activateEvent);
147 }, 148 },
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 this._removeListener(old); 221 this._removeListener(old);
221 this._addListener(eventName); 222 this._addListener(eventName);
222 }, 223 },
223 224
224 _updateItems: function() { 225 _updateItems: function() {
225 var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*'); 226 var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*');
226 nodes = Array.prototype.filter.call(nodes, this._bindFilterItem); 227 nodes = Array.prototype.filter.call(nodes, this._bindFilterItem);
227 this._setItems(nodes); 228 this._setItems(nodes);
228 }, 229 },
229 230
231 _updateAttrForSelected: function() {
232 if (this._shouldUpdateSelection) {
233 this.selected = this._indexToValue(this.indexOf(this.selectedItem));
234 }
235 },
236
230 _updateSelected: function() { 237 _updateSelected: function() {
231 this._selectSelected(this.selected); 238 this._selectSelected(this.selected);
232 }, 239 },
233 240
234 _selectSelected: function(selected) { 241 _selectSelected: function(selected) {
235 this._selection.select(this._valueToItem(this.selected)); 242 this._selection.select(this._valueToItem(this.selected));
236 }, 243 },
237 244
238 _filterItem: function(node) { 245 _filterItem: function(node) {
239 return !this._excludedLocalNames[node.localName]; 246 return !this._excludedLocalNames[node.localName];
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // observe items change under the given node. 296 // observe items change under the given node.
290 _observeItems: function(node) { 297 _observeItems: function(node) {
291 return Polymer.dom(node).observeNodes(function(mutations) { 298 return Polymer.dom(node).observeNodes(function(mutations) {
292 this._updateItems(); 299 this._updateItems();
293 300
294 if (this._shouldUpdateSelection) { 301 if (this._shouldUpdateSelection) {
295 this._updateSelected(); 302 this._updateSelected();
296 } 303 }
297 304
298 // Let other interested parties know about the change so that 305 // Let other interested parties know about the change so that
299 // we don't have to recreate mutation observers everywher. 306 // we don't have to recreate mutation observers everywhere.
300 this.fire('iron-items-changed', mutations, { 307 this.fire('iron-items-changed', mutations, {
301 bubbles: false, 308 bubbles: false,
302 cancelable: false 309 cancelable: false
303 }); 310 });
304 }); 311 });
305 }, 312 },
306 313
307 _activateHandler: function(e) { 314 _activateHandler: function(e) {
308 var t = e.target; 315 var t = e.target;
309 var items = this.items; 316 var items = this.items;
310 while (t && t != this) { 317 while (t && t != this) {
311 var i = items.indexOf(t); 318 var i = items.indexOf(t);
312 if (i >= 0) { 319 if (i >= 0) {
313 var value = this._indexToValue(i); 320 var value = this._indexToValue(i);
314 this._itemActivate(value, t); 321 this._itemActivate(value, t);
315 return; 322 return;
316 } 323 }
317 t = t.parentNode; 324 t = t.parentNode;
318 } 325 }
319 }, 326 },
320 327
321 _itemActivate: function(value, item) { 328 _itemActivate: function(value, item) {
322 if (!this.fire('iron-activate', 329 if (!this.fire('iron-activate',
323 {selected: value, item: item}, {cancelable: true}).defaultPrevented) { 330 {selected: value, item: item}, {cancelable: true}).defaultPrevented) {
324 this.select(value); 331 this.select(value);
325 } 332 }
326 } 333 }
327 334
328 }; 335 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698