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

Side by Side Diff: chrome/browser/resources/chromeos/login/oobe_i18n_dropdown.js

Issue 2502773003: ChromeOS OOBE: switch from iron-dropdown to <select>. (Closed)
Patch Set: Fix polymer load order Created 4 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Polymer class definition for 'oobe-i18n-dropdown'. 6 * Polymer class definition for 'oobe-i18n-dropdown'.
7 */ 7 */
8 (function() { 8 (function() {
9 9
10 10
(...skipping 19 matching lines...) Expand all
30 /** 30 /**
31 * Accessibility label. 31 * Accessibility label.
32 * @type {!string} 32 * @type {!string}
33 */ 33 */
34 label: { 34 label: {
35 type: String, 35 type: String,
36 }, 36 },
37 }, 37 },
38 38
39 /** 39 /**
40 * This flag prevents recursive calls of observers and callbacks. 40 * Mapping from item id to item.
41 * @type {!Map<string,I18nMenuItem>}
41 */ 42 */
42 observersDisabled_: false, 43 idToItem_: null,
43 44
44 /** 45 /**
45 * @param {!{detail: !{item: { item: {!I18nMenuItem}}}}} event 46 * @param {string} value Option value.
46 * @private 47 * @private
47 */ 48 */
48 onSelect_: function(event) { 49 onSelected_: function(value) {
49 if (this.observersDisabled_) 50 this.fire('select-item', this.idToItem_.get(value));
50 return;
51
52 var selectedModel = this.$.domRepeat.modelForElement(event.detail.item);
53 if (!selectedModel.item)
54 return;
55
56 selectedModel.set('item.selected', true);
57 this.fire('select-item', selectedModel.item);
58 },
59
60 onDeselect_: function(event) {
61 if (this.observersDisabled_)
62 return;
63
64 var deSelectedModel = this.$.domRepeat.modelForElement(event.detail.item);
65 if (!deSelectedModel.item)
66 return;
67
68 deSelectedModel.set('item.selected', false);
69 }, 51 },
70 52
71 onItemsChanged_: function(items) { 53 onItemsChanged_: function(items) {
72 if (this.observersDisabled_) 54 this.idToItem_ = new Map();
73 return; 55 for (var i = 0; i < items.length; ++i) {
74 56 var item = items[i];
75 if (!items) 57 this.idToItem_.set(item.value, item);
76 return;
77
78 this.observersDisabled_ = true;
79
80 var index = items.findIndex(function(item) { return item.selected; });
81 if (index != -1) {
82 // This is needed for selectIndex() to pick up values from updated
83 // this.items (for example, translated into other language).
84 Polymer.dom.flush();
85
86 if (this.$.listboxDropdown.selected == index) {
87 // This is to force update real <input> element value even if selection
88 // index has not changed.
89 this.$.listboxDropdown.selectIndex(null);
90 }
91 this.$.listboxDropdown.selectIndex(index);
92 } 58 }
93 59 Oobe.setupSelect(this.$.select,
94 this.observersDisabled_ = false; 60 items,
61 this.onSelected_.bind(this));
95 }, 62 },
96 }); 63 });
97 })(); 64 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698