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

Side by Side Diff: chrome/browser/resources/print_preview/search/search_box.js

Issue 10450022: Print Preview Print Destination Search Widget (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addresses CSS and style comments. Created 8 years, 6 months 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('print_preview', function() {
6 'use strict';
7
8 /**
9 * Component that renders a search box for searching through destinations.
10 * @constructor
11 * @extends {print_preview.Component}
12 */
13 function SearchBox() {
14 print_preview.Component.call(this);
15
16 /**
17 * Timeout used to control incremental search.
18 * @type {?number}
19 * @private
20 */
21 this.timeout_ = null;
22
23 /**
24 * Input box where the query is entered.
25 * @type {HTMLInputElement}
Dan Beam 2012/05/29 23:36:10 ?HTMLInputElement
Robert Toscano 2012/05/30 21:08:00 The '?' is extraneous.
26 * @private
27 */
28 this.input_ = null;
29 };
30
31 /**
32 * Enumeration of event types dispatched from the search box.
33 * @enum {string}
34 */
35 SearchBox.EventType = {
36 SEARCH: 'print_preview.SearchBox.SEARCH'
37 };
38
39 /**
40 * CSS classes used by the search box.
41 * @enum {string}
42 * @private
43 */
44 SearchBox.Classes_ = {
45 INPUT: 'search-box-input'
46 };
47
48 /**
49 * Delay in milliseconds before dispatching a SEARCH event.
50 * @type {number}
Dan Beam 2012/05/29 23:36:10 @type {!number} @const
Robert Toscano 2012/05/30 21:08:00 The "!" is extraneous, but I'll add the const.
51 * @private
52 */
53 SearchBox.SEARCH_DELAY_ = 150;
54
55 SearchBox.prototype = {
56 __proto__: print_preview.Component.prototype,
57
58 /** @param {string} New query to set the search box's query to. */
59 setQuery: function(query) {
60 query = query || '';
61 this.input_.value = query.trim();
62 },
63
64 /** Sets the input element of the search box in focus. */
65 focus: function() {
66 this.input_.focus();
67 },
68
69 /** @override */
70 enterDocument: function() {
71 print_preview.Component.prototype.enterDocument.call(this);
72 this.tracker.add(this.input_, 'keydown', this.onInputKeyDown_.bind(this));
73 },
74
75 /** @override */
76 exitDocument: function() {
77 print_preview.Component.prototype.exitDocument.call(this);
78 this.input_ = null;
79 },
80
81 /** @override */
82 decorateInternal: function() {
83 this.input_ = this.getElement().getElementsByClassName(
84 SearchBox.Classes_.INPUT)[0];
85 },
86
87 /**
88 * @return {string} The current query of the search box.
89 * @private
90 */
91 getQuery_: function() {
92 return this.input_.value.trim();
93 },
94
95 /**
96 * Dispatches a SEARCH event.
97 * @private
98 */
99 dispatchSearchEvent_: function() {
100 this.timeout_ = null;
101 var searchEvent = new cr.Event(SearchBox.EventType.SEARCH);
102 searchEvent.query = this.getQuery_();
103 this.dispatchEvent(searchEvent);
104 },
105
106 /**
107 * Called when the input element's value changes. Dispatches a search event.
108 * @private
109 */
110 onInputKeyDown_: function() {
111 if (this.timeout_) {
112 clearTimeout(this.timeout_);
113 }
114 this.timeout_ = setTimeout(
115 this.dispatchSearchEvent_.bind(this), SearchBox.SEARCH_DELAY_);
116 }
117 };
118
119 // Export
120 return {
121 SearchBox: SearchBox
122 };
123 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698