OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Component that renders a destination item in a destination list. | 9 * Component that renders a destination item in a destination list. |
10 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection | 10 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 return this.select_.value == option.value || option.is_default; | 142 return this.select_.value == option.value || option.is_default; |
143 }.bind(this)); | 143 }.bind(this)); |
144 }, | 144 }, |
145 | 145 |
146 /** | 146 /** |
147 * Called when the text element value is changed. | 147 * Called when the text element value is changed. |
148 * @private | 148 * @private |
149 */ | 149 */ |
150 onTextInput_: function() { | 150 onTextInput_: function() { |
151 this.selectedValue_ = this.text_.value || null; | 151 this.selectedValue_ = this.text_.value || null; |
| 152 |
| 153 if (this.query_) { |
| 154 var optionMatches = (this.selectedValue_ || '').match(this.query_); |
| 155 // Even if there's no match anymore, keep the item visible to do not |
| 156 // surprise user. |
| 157 if (optionMatches) |
| 158 this.showSearchBubble_(optionMatches[0]); |
| 159 else |
| 160 this.hideSearchBubble_(); |
| 161 } |
152 }, | 162 }, |
153 | 163 |
154 /** | 164 /** |
155 * Renders capability properties according to the current state. | 165 * Renders capability properties according to the current state. |
156 * @private | 166 * @private |
157 */ | 167 */ |
158 renderCapability_: function() { | 168 renderCapability_: function() { |
159 var textContent = this.capability_.display_name; | 169 var textContent = this.capability_.display_name; |
160 var nameMatches = this.query_ ? !!textContent.match(this.query_) : true; | 170 var nameMatches = this.query_ ? !!textContent.match(this.query_) : true; |
161 var optionMatches = null; | 171 var optionMatches = null; |
162 if (this.query_) { | 172 if (this.query_) { |
163 if (this.capability_.type == 'SELECT') { | 173 if (this.capability_.type == 'SELECT') { |
164 this.capability_.select_cap.option.some(function(option) { | 174 this.capability_.select_cap.option.some(function(option) { |
165 optionMatches = (option.display_name || '').match(this.query_); | 175 optionMatches = (option.display_name || '').match(this.query_); |
166 return !!optionMatches; | 176 return !!optionMatches; |
167 }.bind(this)); | 177 }.bind(this)); |
168 } else { | 178 } else { |
169 optionMatches = (this.text_.value || '').match(this.query_); | 179 optionMatches = (this.text_.value || '').match(this.query_); |
170 } | 180 } |
171 } | 181 } |
172 var matches = nameMatches || optionMatches; | 182 var matches = nameMatches || optionMatches; |
173 | 183 |
174 if ((!matches || !optionMatches) && this.searchBubble_) { | 184 if (!matches || !optionMatches) |
175 this.searchBubble_.dispose(); | 185 this.hideSearchBubble_(); |
176 this.searchBubble_ = null; | |
177 } | |
178 | 186 |
179 setIsVisible(this.getElement(), matches); | 187 setIsVisible(this.getElement(), matches); |
180 if (!matches) | 188 if (!matches) |
181 return; | 189 return; |
182 | 190 |
183 var nameEl = this.getChildElement('.advanced-settings-item-label'); | 191 var nameEl = this.getChildElement('.advanced-settings-item-label'); |
184 if (this.query_) { | 192 if (this.query_) { |
185 nameEl.textContent = ''; | 193 nameEl.textContent = ''; |
186 this.addTextWithHighlight_(nameEl, textContent); | 194 this.addTextWithHighlight_(nameEl, textContent); |
187 } else { | 195 } else { |
188 nameEl.textContent = textContent; | 196 nameEl.textContent = textContent; |
189 } | 197 } |
190 nameEl.title = textContent; | 198 nameEl.title = textContent; |
191 | 199 |
192 if (optionMatches) { | 200 if (optionMatches) |
193 var element = | 201 this.showSearchBubble_(optionMatches[0]); |
194 this.capability_.type == 'SELECT' ? this.select_ : this.text_; | 202 }, |
195 if (!this.searchBubble_) { | 203 |
196 this.searchBubble_ = new print_preview.SearchBubble(optionMatches[0]); | 204 /** |
197 this.searchBubble_.attachTo(element); | 205 * Shows search bubble for this element. |
198 } else { | 206 * @param {string} text Text to show in the search bubble. |
199 this.searchBubble_.content = optionMatches[0]; | 207 * @private |
200 } | 208 */ |
| 209 showSearchBubble_: function(text) { |
| 210 var element = |
| 211 this.capability_.type == 'SELECT' ? this.select_ : this.text_; |
| 212 if (!this.searchBubble_) { |
| 213 this.searchBubble_ = new print_preview.SearchBubble(text); |
| 214 this.searchBubble_.attachTo(element); |
| 215 } else { |
| 216 this.searchBubble_.content = text; |
201 } | 217 } |
202 }, | 218 }, |
203 | 219 |
| 220 /** |
| 221 * Hides search bubble associated with this element. |
| 222 * @private |
| 223 */ |
| 224 hideSearchBubble_: function() { |
| 225 if (this.searchBubble_) { |
| 226 this.searchBubble_.dispose(); |
| 227 this.searchBubble_ = null; |
| 228 } |
| 229 }, |
| 230 |
204 /** | 231 /** |
205 * Initializes the element's value control. | 232 * Initializes the element's value control. |
206 * @private | 233 * @private |
207 */ | 234 */ |
208 initializeValue_: function() { | 235 initializeValue_: function() { |
209 this.selectedValue_ = | 236 this.selectedValue_ = |
210 this.printTicketStore_.vendorItems.ticketItems[this.id] || null; | 237 this.printTicketStore_.vendorItems.ticketItems[this.id] || null; |
211 | 238 |
212 if (this.capability_.type == 'SELECT') | 239 if (this.capability_.type == 'SELECT') |
213 this.initializeSelectValue_(); | 240 this.initializeSelectValue_(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 297 } |
271 }); | 298 }); |
272 } | 299 } |
273 }; | 300 }; |
274 | 301 |
275 // Export | 302 // Export |
276 return { | 303 return { |
277 AdvancedSettingsItem: AdvancedSettingsItem | 304 AdvancedSettingsItem: AdvancedSettingsItem |
278 }; | 305 }; |
279 }); | 306 }); |
OLD | NEW |