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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/search/search_box.js
diff --git a/chrome/browser/resources/print_preview/search/search_box.js b/chrome/browser/resources/print_preview/search/search_box.js
new file mode 100644
index 0000000000000000000000000000000000000000..d15094aac08a95665ffb616a61fca314316066b9
--- /dev/null
+++ b/chrome/browser/resources/print_preview/search/search_box.js
@@ -0,0 +1,107 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('print_preview', function() {
+ 'use strict';
+
+ /**
+ * Component that renders a search box for searching through destinations.
+ *
+ * @constructor
+ * @extends {print_preview.Component}
+ */
+ function SearchBox() {
+ print_preview.Component.call(this);
+
+ /**
+ * Timeout used to control incremental search.
+ * @type {Object}
+ * @private
+ */
+ this.timeout_ = null;
+ };
+
+ /**
+ * Enumeration of events dispatched from the search box.
+ * @enum {string}
+ */
+ SearchBox.Event = {
+ SEARCH: 'print_preview.SearchBox.SEARCH'
+ };
+
+ /**
+ * CSS classes used by the search box.
+ * @enum {string}
+ * @private
+ */
+ SearchBox.Classes_ = {
+ INPUT: 'search-box-input'
+ };
+
+ /**
+ * Delay in milliseconds before dispatching a SEARCH event.
+ * @type {number}
+ * @private
+ */
+ SearchBox.SEARCH_DELAY_ = 150;
+
+ SearchBox.prototype = {
+ __proto__: print_preview.Component.prototype,
+
+ get query() {
+ var inputEl = this.getElement().getElementsByClassName(
+ SearchBox.Classes_.INPUT)[0];
+ return inputEl.value.trim();
+ },
+
+ set query(query) {
+ query = query || '';
+ var inputEl = this.getElement().getElementsByClassName(
+ SearchBox.Classes_.INPUT)[0];
+ inputEl.value = query.trim();
+ },
+
+ /** @override */
+ createDom: function() {
+ this.setElementInternal(this.cloneTemplateInternal(
+ 'search-box-template'));
+ },
+
+ /** @override */
+ enterDocument: function() {
+ print_preview.Component.prototype.enterDocument.call(this);
+ var inputEl = this.getElement().getElementsByClassName(
+ SearchBox.Classes_.INPUT)[0];
+ this.tracker.add(inputEl, 'keydown', this.onInputKeyDown_.bind(this));
+ },
+
+ /**
+ * Dispatches a SEARCH event.
+ * @private
+ */
+ dispatchSearchEvent_: function() {
+ this.timeout_ = null;
+ var searchEvt = new cr.Event(SearchBox.Event.SEARCH);
+ searchEvt.query = this.query;
+ this.dispatchEvent(searchEvt);
+ },
+
+ /**
+ * Called when the input element's value changes. Dispatches a search event.
+ * @private
+ */
+ onInputKeyDown_: function() {
+ if (this.timeout_) {
+ clearTimeout(this.timeout_);
+ }
+ this.timeout_ = setTimeout(
+ this.dispatchSearchEvent_.bind(this), SearchBox.SEARCH_DELAY_);
+ }
+ };
+
+ // Export
+ return {
+ SearchBox: SearchBox
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698