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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return this.input_.value.trim(); | 90 return this.input_.value.trim(); |
91 }, | 91 }, |
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 searchEvent.query = this.getQuery_(); | 100 var query = this.getQuery_(); |
| 101 searchEvent.query = query; |
| 102 // Generate regexp-safe query by escaping metacharacters. |
| 103 var safeQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); |
| 104 searchEvent.queryRegExp = new RegExp('(' + safeQuery + ')', 'ig'); |
101 this.dispatchEvent(searchEvent); | 105 this.dispatchEvent(searchEvent); |
102 }, | 106 }, |
103 | 107 |
104 /** | 108 /** |
105 * Called when the input element's value changes. Dispatches a search event. | 109 * Called when the input element's value changes. Dispatches a search event. |
106 * @private | 110 * @private |
107 */ | 111 */ |
108 onInputInput_: function() { | 112 onInputInput_: function() { |
109 if (this.timeout_) | 113 if (this.timeout_) |
110 clearTimeout(this.timeout_); | 114 clearTimeout(this.timeout_); |
111 this.timeout_ = setTimeout( | 115 this.timeout_ = setTimeout( |
112 this.dispatchSearchEvent_.bind(this), SearchBox.SEARCH_DELAY_); | 116 this.dispatchSearchEvent_.bind(this), SearchBox.SEARCH_DELAY_); |
113 } | 117 } |
114 }; | 118 }; |
115 | 119 |
116 // Export | 120 // Export |
117 return { | 121 return { |
118 SearchBox: SearchBox | 122 SearchBox: SearchBox |
119 }; | 123 }; |
120 }); | 124 }); |
OLD | NEW |