| 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 * Specifies a custom vendor capability. | 5 * Specifies a custom vendor capability. |
| 6 * @typedef {{ | 6 * @typedef {{ |
| 7 * id: (string), | 7 * id: (string), |
| 8 * display_name: (string), | 8 * display_name: (string), |
| 9 * localized_display_name: (string | undefined), | 9 * localized_display_name: (string | undefined), |
| 10 * type: (string), | 10 * type: (string), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 /** @private {!EventTracker} */ | 69 /** @private {!EventTracker} */ |
| 70 this.tracker_ = new EventTracker(); | 70 this.tracker_ = new EventTracker(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 AdvancedSettingsItem.prototype = { | 73 AdvancedSettingsItem.prototype = { |
| 74 __proto__: print_preview.Component.prototype, | 74 __proto__: print_preview.Component.prototype, |
| 75 | 75 |
| 76 /** @override */ | 76 /** @override */ |
| 77 createDom: function() { | 77 createDom: function() { |
| 78 this.setElementInternal(this.cloneTemplateInternal( | 78 this.setElementInternal( |
| 79 'advanced-settings-item-template')); | 79 this.cloneTemplateInternal('advanced-settings-item-template')); |
| 80 | 80 |
| 81 this.tracker_.add( | 81 this.tracker_.add( |
| 82 this.select_, 'change', this.onSelectChange_.bind(this)); | 82 this.select_, 'change', this.onSelectChange_.bind(this)); |
| 83 this.tracker_.add(this.text_, 'input', this.onTextInput_.bind(this)); | 83 this.tracker_.add(this.text_, 'input', this.onTextInput_.bind(this)); |
| 84 | 84 |
| 85 this.initializeValue_(); | 85 this.initializeValue_(); |
| 86 | 86 |
| 87 this.renderCapability_(); | 87 this.renderCapability_(); |
| 88 }, | 88 }, |
| 89 | 89 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 get select_() { | 128 get select_() { |
| 129 return /** @type {!HTMLSelectElement} */ ( | 129 return /** @type {!HTMLSelectElement} */ ( |
| 130 this.getChildElement('.advanced-settings-item-value-select-control')); | 130 this.getChildElement('.advanced-settings-item-value-select-control')); |
| 131 }, | 131 }, |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * @return {!HTMLSelectElement} Text element. | 134 * @return {!HTMLSelectElement} Text element. |
| 135 * @private | 135 * @private |
| 136 */ | 136 */ |
| 137 get text_() { | 137 get text_() { |
| 138 return /** @type {!HTMLSelectElement} */( | 138 return /** @type {!HTMLSelectElement} */ ( |
| 139 this.getChildElement('.advanced-settings-item-value-text-control')); | 139 this.getChildElement('.advanced-settings-item-value-text-control')); |
| 140 }, | 140 }, |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Called when the select element value is changed. | 143 * Called when the select element value is changed. |
| 144 * @private | 144 * @private |
| 145 */ | 145 */ |
| 146 onSelectChange_: function() { | 146 onSelectChange_: function() { |
| 147 this.selectedValue_ = this.select_.value; | 147 this.selectedValue_ = this.select_.value; |
| 148 }, | 148 }, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // Whether capability name matches the query. | 188 // Whether capability name matches the query. |
| 189 var nameMatches = this.query_ ? !!textContent.match(this.query_) : true; | 189 var nameMatches = this.query_ ? !!textContent.match(this.query_) : true; |
| 190 // An array of text segments of the capability value matching the query. | 190 // An array of text segments of the capability value matching the query. |
| 191 var optionMatches = null; | 191 var optionMatches = null; |
| 192 if (this.query_) { | 192 if (this.query_) { |
| 193 if (this.capability_.type == 'SELECT') { | 193 if (this.capability_.type == 'SELECT') { |
| 194 // Look for the first option that matches the query. | 194 // Look for the first option that matches the query. |
| 195 for (var i = 0; i < this.select_.length && !optionMatches; i++) | 195 for (var i = 0; i < this.select_.length && !optionMatches; i++) |
| 196 optionMatches = this.select_.options[i].text.match(this.query_); | 196 optionMatches = this.select_.options[i].text.match(this.query_); |
| 197 } else { | 197 } else { |
| 198 optionMatches = (this.text_.value || this.text_.placeholder || '') | 198 optionMatches = (this.text_.value || this.text_.placeholder || |
| 199 .match(this.query_); | 199 '').match(this.query_); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 var matches = nameMatches || !!optionMatches; | 202 var matches = nameMatches || !!optionMatches; |
| 203 | 203 |
| 204 if (!optionMatches) | 204 if (!optionMatches) |
| 205 this.hideSearchBubble_(); | 205 this.hideSearchBubble_(); |
| 206 | 206 |
| 207 setIsVisible(this.getElement(), matches); | 207 setIsVisible(this.getElement(), matches); |
| 208 if (!matches) | 208 if (!matches) |
| 209 return; | 209 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 this.initializeSelectValue_(); | 260 this.initializeSelectValue_(); |
| 261 else | 261 else |
| 262 this.initializeTextValue_(); | 262 this.initializeTextValue_(); |
| 263 }, | 263 }, |
| 264 | 264 |
| 265 /** | 265 /** |
| 266 * Initializes the select element. | 266 * Initializes the select element. |
| 267 * @private | 267 * @private |
| 268 */ | 268 */ |
| 269 initializeSelectValue_: function() { | 269 initializeSelectValue_: function() { |
| 270 setIsVisible(assert(this.getChildElement( | 270 setIsVisible( |
| 271 '.advanced-settings-item-value-select')), true); | 271 assert(this.getChildElement('.advanced-settings-item-value-select')), |
| 272 true); |
| 272 var selectEl = this.select_; | 273 var selectEl = this.select_; |
| 273 var indexToSelect = 0; | 274 var indexToSelect = 0; |
| 274 this.capability_.select_cap.option.forEach(function(option, index) { | 275 this.capability_.select_cap.option.forEach(function(option, index) { |
| 275 var item = document.createElement('option'); | 276 var item = document.createElement('option'); |
| 276 item.text = this.getEntityDisplayName_(option); | 277 item.text = this.getEntityDisplayName_(option); |
| 277 item.value = option.value; | 278 item.value = option.value; |
| 278 if (option.is_default) | 279 if (option.is_default) |
| 279 indexToSelect = index; | 280 indexToSelect = index; |
| 280 selectEl.appendChild(item); | 281 selectEl.appendChild(item); |
| 281 }, this); | 282 }, this); |
| 282 for (var i = 0, option; (option = selectEl.options[i]); i++) { | 283 for (var i = 0, option; (option = selectEl.options[i]); i++) { |
| 283 if (option.value == this.selectedValue_) { | 284 if (option.value == this.selectedValue_) { |
| 284 indexToSelect = i; | 285 indexToSelect = i; |
| 285 break; | 286 break; |
| 286 } | 287 } |
| 287 } | 288 } |
| 288 selectEl.selectedIndex = indexToSelect; | 289 selectEl.selectedIndex = indexToSelect; |
| 289 }, | 290 }, |
| 290 | 291 |
| 291 /** | 292 /** |
| 292 * Initializes the text element. | 293 * Initializes the text element. |
| 293 * @private | 294 * @private |
| 294 */ | 295 */ |
| 295 initializeTextValue_: function() { | 296 initializeTextValue_: function() { |
| 296 setIsVisible(assert(this.getChildElement( | 297 setIsVisible( |
| 297 '.advanced-settings-item-value-text')), true); | 298 assert(this.getChildElement('.advanced-settings-item-value-text')), |
| 299 true); |
| 298 | 300 |
| 299 var defaultValue = null; | 301 var defaultValue = null; |
| 300 if (this.capability_.type == 'TYPED_VALUE' && | 302 if (this.capability_.type == 'TYPED_VALUE' && |
| 301 this.capability_.typed_value_cap) { | 303 this.capability_.typed_value_cap) { |
| 302 defaultValue = this.capability_.typed_value_cap.default || null; | 304 defaultValue = this.capability_.typed_value_cap.default || null; |
| 303 } else if (this.capability_.type == 'RANGE' && | 305 } else if ( |
| 304 this.capability_.range_cap) { | 306 this.capability_.type == 'RANGE' && this.capability_.range_cap) { |
| 305 defaultValue = this.capability_.range_cap.default || null; | 307 defaultValue = this.capability_.range_cap.default || null; |
| 306 } | 308 } |
| 307 | 309 |
| 308 this.text_.placeholder = defaultValue || ''; | 310 this.text_.placeholder = defaultValue || ''; |
| 309 | 311 |
| 310 this.text_.value = this.selectedValue; | 312 this.text_.value = this.selectedValue; |
| 311 }, | 313 }, |
| 312 | 314 |
| 313 /** | 315 /** |
| 314 * Adds text to parent element wrapping search query matches in highlighted | 316 * Adds text to parent element wrapping search query matches in highlighted |
| (...skipping 10 matching lines...) Expand all Loading... |
| 325 var span = document.createElement('span'); | 327 var span = document.createElement('span'); |
| 326 span.className = 'advanced-settings-item-query-highlight'; | 328 span.className = 'advanced-settings-item-query-highlight'; |
| 327 span.textContent = section; | 329 span.textContent = section; |
| 328 parent.appendChild(span); | 330 parent.appendChild(span); |
| 329 } | 331 } |
| 330 }); | 332 }); |
| 331 } | 333 } |
| 332 }; | 334 }; |
| 333 | 335 |
| 334 // Export | 336 // Export |
| 335 return { | 337 return {AdvancedSettingsItem: AdvancedSettingsItem}; |
| 336 AdvancedSettingsItem: AdvancedSettingsItem | |
| 337 }; | |
| 338 }); | 338 }); |
| OLD | NEW |