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

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

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
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 *
11 * @constructor
12 * @extends {print_preview.Component}
13 */
14 function SearchBox() {
15 print_preview.Component.call(this);
16
17 /**
18 * Timeout used to control incremental search.
19 * @type {Object}
20 * @private
21 */
22 this.timeout_ = null;
23 };
24
25 /**
26 * Enumeration of events dispatched from the search box.
27 * @enum {string}
28 */
29 SearchBox.Event = {
30 SEARCH: 'print_preview.SearchBox.SEARCH'
31 };
32
33 /**
34 * CSS classes used by the search box.
35 * @enum {string}
36 * @private
37 */
38 SearchBox.Classes_ = {
39 INPUT: 'search-box-input'
40 };
41
42 /**
43 * Delay in milliseconds before dispatching a SEARCH event.
44 * @type {number}
45 * @private
46 */
47 SearchBox.SEARCH_DELAY_ = 150;
48
49 SearchBox.prototype = {
50 __proto__: print_preview.Component.prototype,
51
52 get query() {
53 var inputEl = this.getElement().getElementsByClassName(
54 SearchBox.Classes_.INPUT)[0];
55 return inputEl.value.trim();
56 },
57
58 set query(query) {
59 query = query || '';
60 var inputEl = this.getElement().getElementsByClassName(
61 SearchBox.Classes_.INPUT)[0];
62 inputEl.value = query.trim();
63 },
64
65 /** @override */
66 createDom: function() {
67 this.setElementInternal(this.cloneTemplateInternal(
68 'search-box-template'));
69 },
70
71 /** @override */
72 enterDocument: function() {
73 print_preview.Component.prototype.enterDocument.call(this);
74 var inputEl = this.getElement().getElementsByClassName(
75 SearchBox.Classes_.INPUT)[0];
76 this.tracker.add(inputEl, 'keydown', this.onInputKeyDown_.bind(this));
77 },
78
79 /**
80 * Dispatches a SEARCH event.
81 * @private
82 */
83 dispatchSearchEvent_: function() {
84 this.timeout_ = null;
85 var searchEvt = new cr.Event(SearchBox.Event.SEARCH);
86 searchEvt.query = this.query;
87 this.dispatchEvent(searchEvt);
88 },
89
90 /**
91 * Called when the input element's value changes. Dispatches a search event.
92 * @private
93 */
94 onInputKeyDown_: function() {
95 if (this.timeout_) {
96 clearTimeout(this.timeout_);
97 }
98 this.timeout_ = setTimeout(
99 this.dispatchSearchEvent_.bind(this), SearchBox.SEARCH_DELAY_);
100 }
101 };
102
103 // Export
104 return {
105 SearchBox: SearchBox
106 };
107 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698