OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 Polymer({ | 5 Polymer({ |
6 is: 'cr-toolbar', | 6 is: 'cr-toolbar', |
7 | 7 |
8 properties: { | 8 properties: { |
9 // Name to display in the toolbar, in titlecase. | 9 // Name to display in the toolbar, in titlecase. |
10 pageName: String, | 10 pageName: String, |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 /** @private */ | 22 /** @private */ |
23 narrow_: { | 23 narrow_: { |
24 type: Boolean, | 24 type: Boolean, |
25 reflectToAttribute: true | 25 reflectToAttribute: true |
26 }, | 26 }, |
27 | 27 |
28 /** @private */ | 28 /** @private */ |
29 showingSearch_: { | 29 showingSearch_: { |
30 type: Boolean, | 30 type: Boolean, |
31 reflectToAttribute: true, | 31 observer: 'onShowingSearchChanged_', |
| 32 reflectToAttribute: true |
32 }, | 33 }, |
33 }, | 34 }, |
34 | 35 |
| 36 /** @const {number} */ |
| 37 SEARCH_FIELD_DEFAULT_WIDTH: 580, |
| 38 |
| 39 /** |
| 40 * @type {?function()} |
| 41 * @private |
| 42 */ |
| 43 resizeListener_: null, |
| 44 |
| 45 /** @override */ |
| 46 attached: function() { |
| 47 this.resizeListener_ = this.setSearchFieldPosition_.bind(this); |
| 48 window.addEventListener('resize', this.resizeListener_); |
| 49 this.setSearchFieldPosition_(); |
| 50 }, |
| 51 |
| 52 /** @override */ |
| 53 detached: function() { |
| 54 window.removeEventListener('resize', this.resizeListener_); |
| 55 }, |
| 56 |
35 /** @return {!CrToolbarSearchFieldElement} */ | 57 /** @return {!CrToolbarSearchFieldElement} */ |
36 getSearchField: function() { | 58 getSearchField: function() { |
37 return this.$.search; | 59 return this.$.search; |
38 } | 60 }, |
| 61 |
| 62 /** |
| 63 * @param {boolean} showingSearch |
| 64 * @private |
| 65 */ |
| 66 onShowingSearchChanged_: function(showingSearch) { |
| 67 var searchField = this.$.search; |
| 68 if (showingSearch) { |
| 69 searchField.style.left = 0; |
| 70 return; |
| 71 } |
| 72 |
| 73 var left = (window.innerWidth - this.SEARCH_FIELD_DEFAULT_WIDTH) / 2 - |
| 74 this.$.centeredContent.offsetLeft; |
| 75 searchField.style.left = left + 'px'; |
| 76 }, |
| 77 |
| 78 /** @private */ |
| 79 setSearchFieldPosition_: function() { |
| 80 var searchFieldStyle = this.$.search.style; |
| 81 searchFieldStyle.transition = 'none'; |
| 82 this.onShowingSearchChanged_(this.showingSearch_); |
| 83 setTimeout(function() { |
| 84 searchFieldStyle.transition = ''; |
| 85 }, 0); |
| 86 }, |
| 87 |
| 88 /** @private */ |
| 89 onMenuClick_: function(e) { |
| 90 this.fire('cr-toolbar-menu-click'); |
| 91 }, |
39 }); | 92 }); |
OLD | NEW |