Index: ui/webui/resources/cr_elements/v1_0/cr_search_field/cr_search_field.js |
diff --git a/ui/webui/resources/cr_elements/v1_0/cr_search_field/cr_search_field.js b/ui/webui/resources/cr_elements/v1_0/cr_search_field/cr_search_field.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8f6fdf5bdecc57c24453e5e51ecac347940a5d76 |
--- /dev/null |
+++ b/ui/webui/resources/cr_elements/v1_0/cr_search_field/cr_search_field.js |
@@ -0,0 +1,58 @@ |
+// Copyright 2015 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. |
+ |
+var SearchField = Polymer({ |
+ is: 'cr-search-field', |
+ |
+ properties: { |
+ showingSearch_: { |
+ type: Boolean, |
+ value: false, |
+ }, |
+ }, |
+ |
+ setDelegate: function(delegate) { |
+ this.delegate_ = delegate; |
+ }, |
+ |
+ getValue: function() { |
+ return this.$['search-input'].value; |
+ }, |
+ |
+ /** @private */ |
+ onSearchTermSearch_: function() { |
+ if (this.delegate_) |
+ this.delegate_.onSearchTermSearch(this.$['search-input'].value); |
+ }, |
+ |
+ /** @private */ |
+ onSearchTermKeydown_: function(e) { |
+ assert(this.showingSearch_); |
+ if (e.keyIdentifier == 'U+001B') // Escape. |
+ this.toggleShowingSearch_(); |
+ }, |
+ |
+ /** @private */ |
+ toggleShowingSearch_: function() { |
+ this.showingSearch_ = !this.showingSearch_; |
+ this.$['search-button'].disabled = this.showingSearch_; |
Dan Beam
2015/09/14 23:16:06
L39 could be done in the HTML if you want
Devlin
2015/09/15 17:24:06
More consistent with the hiding code, so I like it
|
+ |
+ if (this.showingSearch_) { |
+ this.$['search-input'].focus(); |
+ } else { |
+ this.$['search-input'].value = ''; |
+ this.onSearchTermSearch_(); |
+ } |
+ }, |
+}); |
+ |
+/** @interface */ |
+SearchField.Delegate = function() {}; |
+ |
+SearchField.Delegate.prototype = { |
+ /** |
+ * @param {string} value |
+ */ |
+ onSearchTermSearch: assertNotReached, |
+}; |