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 search box for searching through destinations. | 9 * Component that renders a search box for searching through destinations. |
10 * @param {string} searchBoxPlaceholderText Search box placeholder text. | 10 * @param {string} searchBoxPlaceholderText Search box placeholder text. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 /** | 93 /** |
94 * Dispatches a SEARCH event. | 94 * Dispatches a SEARCH event. |
95 * @private | 95 * @private |
96 */ | 96 */ |
97 dispatchSearchEvent_: function() { | 97 dispatchSearchEvent_: function() { |
98 this.timeout_ = null; | 98 this.timeout_ = null; |
99 var searchEvent = new Event(SearchBox.EventType.SEARCH); | 99 var searchEvent = new Event(SearchBox.EventType.SEARCH); |
100 var query = this.getQuery_(); | 100 var query = this.getQuery_(); |
101 searchEvent.query = query; | 101 searchEvent.query = query; |
102 // Generate regexp-safe query by escaping metacharacters. | 102 if (query) { |
103 var safeQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); | 103 // Generate regexp-safe query by escaping metacharacters. |
104 searchEvent.queryRegExp = new RegExp('(' + safeQuery + ')', 'ig'); | 104 var safeQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); |
| 105 searchEvent.queryRegExp = new RegExp('(' + safeQuery + ')', 'ig'); |
| 106 } else { |
| 107 searchEvent.queryRegExp = null; |
| 108 } |
105 this.dispatchEvent(searchEvent); | 109 this.dispatchEvent(searchEvent); |
106 }, | 110 }, |
107 | 111 |
108 /** | 112 /** |
109 * Called when the input element's value changes. Dispatches a search event. | 113 * Called when the input element's value changes. Dispatches a search event. |
110 * @private | 114 * @private |
111 */ | 115 */ |
112 onInputInput_: function() { | 116 onInputInput_: function() { |
113 if (this.timeout_) | 117 if (this.timeout_) |
114 clearTimeout(this.timeout_); | 118 clearTimeout(this.timeout_); |
115 this.timeout_ = setTimeout( | 119 this.timeout_ = setTimeout( |
116 this.dispatchSearchEvent_.bind(this), SearchBox.SEARCH_DELAY_); | 120 this.dispatchSearchEvent_.bind(this), SearchBox.SEARCH_DELAY_); |
117 } | 121 } |
118 }; | 122 }; |
119 | 123 |
120 // Export | 124 // Export |
121 return { | 125 return { |
122 SearchBox: SearchBox | 126 SearchBox: SearchBox |
123 }; | 127 }; |
124 }); | 128 }); |
OLD | NEW |