| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 if (typeof Polymer == 'undefined') | 5 if (typeof Polymer == 'undefined') |
| 6 Polymer = {dom: 'shadow'}; | 6 Polymer = {dom: 'shadow'}; |
| 7 else | 7 else |
| 8 console.error('Polymer is already defined.'); | 8 console.error('Polymer is already defined.'); |
| 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 10 // Use of this source code is governed by a BSD-style license that can be | 10 // Use of this source code is governed by a BSD-style license that can be |
| (...skipping 16860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16871 }, | 16871 }, |
| 16872 | 16872 |
| 16873 clearLabel: { | 16873 clearLabel: { |
| 16874 type: String, | 16874 type: String, |
| 16875 value: '', | 16875 value: '', |
| 16876 }, | 16876 }, |
| 16877 | 16877 |
| 16878 showingSearch_: { | 16878 showingSearch_: { |
| 16879 type: Boolean, | 16879 type: Boolean, |
| 16880 value: false, | 16880 value: false, |
| 16881 observer: 'showingSearchChanged_', |
| 16881 }, | 16882 }, |
| 16882 }, | 16883 }, |
| 16883 | 16884 |
| 16885 /** |
| 16886 * Returns the value of the search field. |
| 16887 * @return {string} |
| 16888 */ |
| 16889 getValue: function() { |
| 16890 var searchInput = this.getSearchInput_(); |
| 16891 return searchInput ? searchInput.value : ''; |
| 16892 }, |
| 16893 |
| 16884 /** @param {SearchFieldDelegate} delegate */ | 16894 /** @param {SearchFieldDelegate} delegate */ |
| 16885 setDelegate: function(delegate) { | 16895 setDelegate: function(delegate) { |
| 16886 this.delegate_ = delegate; | 16896 this.delegate_ = delegate; |
| 16887 }, | 16897 }, |
| 16888 | 16898 |
| 16889 /** | 16899 showAndFocus: function() { |
| 16890 * Returns the value of the search field. | 16900 this.showingSearch_ = true; |
| 16891 * @return {string} | 16901 this.focus_(); |
| 16892 */ | |
| 16893 getValue: function() { | |
| 16894 var searchInput = this.$$('#search-input'); | |
| 16895 return searchInput ? searchInput.value : ''; | |
| 16896 }, | 16902 }, |
| 16897 | 16903 |
| 16898 /** @private */ | 16904 /** @private */ |
| 16905 focus_: function() { |
| 16906 this.async(function() { |
| 16907 if (!this.showingSearch_) |
| 16908 return; |
| 16909 |
| 16910 var searchInput = this.getSearchInput_(); |
| 16911 if (searchInput) |
| 16912 searchInput.focus(); |
| 16913 }); |
| 16914 }, |
| 16915 |
| 16916 /** |
| 16917 * @return {?HTMLElement} |
| 16918 * @private |
| 16919 */ |
| 16920 getSearchInput_: function() { |
| 16921 return this.$$('#search-input'); |
| 16922 }, |
| 16923 |
| 16924 /** @private */ |
| 16899 onSearchTermSearch_: function() { | 16925 onSearchTermSearch_: function() { |
| 16900 if (this.delegate_) | 16926 if (this.delegate_) |
| 16901 this.delegate_.onSearchTermSearch(this.getValue()); | 16927 this.delegate_.onSearchTermSearch(this.getValue()); |
| 16902 }, | 16928 }, |
| 16903 | 16929 |
| 16904 /** @private */ | 16930 /** @private */ |
| 16905 onSearchTermKeydown_: function(e) { | 16931 onSearchTermKeydown_: function(e) { |
| 16906 assert(this.showingSearch_); | |
| 16907 if (e.keyIdentifier == 'U+001B') // Escape. | 16932 if (e.keyIdentifier == 'U+001B') // Escape. |
| 16908 this.toggleShowingSearch_(); | 16933 this.showingSearch_ = false; |
| 16934 }, |
| 16935 |
| 16936 /** @private */ |
| 16937 showingSearchChanged_: function() { |
| 16938 if (this.showingSearch_) { |
| 16939 this.focus_(); |
| 16940 return; |
| 16941 } |
| 16942 |
| 16943 var searchInput = this.getSearchInput_(); |
| 16944 if (!searchInput) |
| 16945 return; |
| 16946 |
| 16947 searchInput.value = ''; |
| 16948 this.onSearchTermSearch_(); |
| 16909 }, | 16949 }, |
| 16910 | 16950 |
| 16911 /** @private */ | 16951 /** @private */ |
| 16912 toggleShowingSearch_: function() { | 16952 toggleShowingSearch_: function() { |
| 16913 this.showingSearch_ = !this.showingSearch_; | 16953 this.showingSearch_ = !this.showingSearch_; |
| 16914 this.async(function() { | |
| 16915 var searchInput = this.$$('#search-input'); | |
| 16916 if (this.showingSearch_) { | |
| 16917 searchInput.focus(); | |
| 16918 } else { | |
| 16919 searchInput.value = ''; | |
| 16920 this.onSearchTermSearch_(); | |
| 16921 } | |
| 16922 }); | |
| 16923 }, | 16954 }, |
| 16924 }); | 16955 }); |
| 16925 // Copyright 2015 The Chromium Authors. All rights reserved. | 16956 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 16926 // Use of this source code is governed by a BSD-style license that can be | 16957 // Use of this source code is governed by a BSD-style license that can be |
| 16927 // found in the LICENSE file. | 16958 // found in the LICENSE file. |
| 16928 | 16959 |
| 16929 cr.define('downloads', function() { | 16960 cr.define('downloads', function() { |
| 16930 var Toolbar = Polymer({ | 16961 var Toolbar = Polymer({ |
| 16931 is: 'downloads-toolbar', | 16962 is: 'downloads-toolbar', |
| 16932 | 16963 |
| 16933 attached: function() { | 16964 attached: function() { |
| 16934 // isRTL() only works after i18n_template.js runs to set <html dir>. | 16965 // isRTL() only works after i18n_template.js runs to set <html dir>. |
| 16935 this.overflowAlign_ = isRTL() ? 'left' : 'right'; | 16966 this.overflowAlign_ = isRTL() ? 'left' : 'right'; |
| 16936 | 16967 |
| 16937 /** @private {!SearchFieldDelegate} */ | 16968 /** @private {!SearchFieldDelegate} */ |
| 16938 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this); | 16969 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this); |
| 16939 this.$['search-input'].setDelegate(this.searchFieldDelegate_); | 16970 this.$['search-input'].setDelegate(this.searchFieldDelegate_); |
| 16940 }, | 16971 }, |
| 16941 | 16972 |
| 16942 properties: { | 16973 properties: { |
| 16943 downloadsShowing: { | 16974 downloadsShowing: { |
| 16944 reflectToAttribute: true, | 16975 reflectToAttribute: true, |
| 16945 type: Boolean, | 16976 type: Boolean, |
| 16946 value: false, | 16977 value: false, |
| 16947 observer: 'onDownloadsShowingChange_', | 16978 observer: 'downloadsShowingChanged_', |
| 16948 }, | 16979 }, |
| 16949 | 16980 |
| 16950 overflowAlign_: { | 16981 overflowAlign_: { |
| 16951 type: String, | 16982 type: String, |
| 16952 value: 'right', | 16983 value: 'right', |
| 16953 }, | 16984 }, |
| 16954 }, | 16985 }, |
| 16955 | 16986 |
| 16956 /** @return {boolean} Whether removal can be undone. */ | 16987 /** @return {boolean} Whether removal can be undone. */ |
| 16957 canUndo: function() { | 16988 canUndo: function() { |
| 16958 return this.$['search-input'] != this.shadowRoot.activeElement; | 16989 return this.$['search-input'] != this.shadowRoot.activeElement; |
| 16959 }, | 16990 }, |
| 16960 | 16991 |
| 16961 /** @return {boolean} Whether "Clear all" should be allowed. */ | 16992 /** @return {boolean} Whether "Clear all" should be allowed. */ |
| 16962 canClearAll: function() { | 16993 canClearAll: function() { |
| 16963 return !this.$['search-input'].getValue() && this.downloadsShowing; | 16994 return !this.$['search-input'].getValue() && this.downloadsShowing; |
| 16964 }, | 16995 }, |
| 16965 | 16996 |
| 16997 onFindCommand: function() { |
| 16998 this.$['search-input'].showAndFocus(); |
| 16999 }, |
| 17000 |
| 16966 /** @private */ | 17001 /** @private */ |
| 16967 onClearAllTap_: function() { | 17002 onClearAllTap_: function() { |
| 16968 assert(this.canClearAll()); | 17003 assert(this.canClearAll()); |
| 16969 downloads.ActionService.getInstance().clearAll(); | 17004 downloads.ActionService.getInstance().clearAll(); |
| 16970 }, | 17005 }, |
| 16971 | 17006 |
| 16972 /** @private */ | 17007 /** @private */ |
| 16973 onDownloadsShowingChange_: function() { | 17008 downloadsShowingChanged_: function() { |
| 16974 this.updateClearAll_(); | 17009 this.updateClearAll_(); |
| 16975 }, | 17010 }, |
| 16976 | 17011 |
| 16977 /** @param {string} searchTerm */ | 17012 /** @param {string} searchTerm */ |
| 16978 onSearchTermSearch: function(searchTerm) { | 17013 onSearchTermSearch: function(searchTerm) { |
| 16979 downloads.ActionService.getInstance().search(searchTerm); | 17014 downloads.ActionService.getInstance().search(searchTerm); |
| 16980 this.updateClearAll_(); | 17015 this.updateClearAll_(); |
| 16981 }, | 17016 }, |
| 16982 | 17017 |
| 16983 /** @private */ | 17018 /** @private */ |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17092 */ | 17127 */ |
| 17093 onCanExecute_: function(e) { | 17128 onCanExecute_: function(e) { |
| 17094 e = /** @type {cr.ui.CanExecuteEvent} */(e); | 17129 e = /** @type {cr.ui.CanExecuteEvent} */(e); |
| 17095 switch (e.command.id) { | 17130 switch (e.command.id) { |
| 17096 case 'undo-command': | 17131 case 'undo-command': |
| 17097 e.canExecute = this.$.toolbar.canUndo(); | 17132 e.canExecute = this.$.toolbar.canUndo(); |
| 17098 break; | 17133 break; |
| 17099 case 'clear-all-command': | 17134 case 'clear-all-command': |
| 17100 e.canExecute = this.$.toolbar.canClearAll(); | 17135 e.canExecute = this.$.toolbar.canClearAll(); |
| 17101 break; | 17136 break; |
| 17137 case 'find-command': |
| 17138 e.canExecute = true; |
| 17139 break; |
| 17102 } | 17140 } |
| 17103 }, | 17141 }, |
| 17104 | 17142 |
| 17105 /** | 17143 /** |
| 17106 * @param {Event} e | 17144 * @param {Event} e |
| 17107 * @private | 17145 * @private |
| 17108 */ | 17146 */ |
| 17109 onCommand_: function(e) { | 17147 onCommand_: function(e) { |
| 17110 if (e.command.id == 'clear-all-command') | 17148 if (e.command.id == 'clear-all-command') |
| 17111 downloads.ActionService.getInstance().clearAll(); | 17149 downloads.ActionService.getInstance().clearAll(); |
| 17112 else if (e.command.id == 'undo-command') | 17150 else if (e.command.id == 'undo-command') |
| 17113 downloads.ActionService.getInstance().undo(); | 17151 downloads.ActionService.getInstance().undo(); |
| 17152 else if (e.command.id == 'find-command') |
| 17153 this.$.toolbar.onFindCommand(); |
| 17114 }, | 17154 }, |
| 17115 | 17155 |
| 17116 /** @private */ | 17156 /** @private */ |
| 17117 onListScroll_: function() { | 17157 onListScroll_: function() { |
| 17118 var list = this.$['downloads-list']; | 17158 var list = this.$['downloads-list']; |
| 17119 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) { | 17159 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) { |
| 17120 // Approaching the end of the scrollback. Attempt to load more items. | 17160 // Approaching the end of the scrollback. Attempt to load more items. |
| 17121 downloads.ActionService.getInstance().loadMore(); | 17161 downloads.ActionService.getInstance().loadMore(); |
| 17122 } | 17162 } |
| 17123 }, | 17163 }, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17194 Manager.get().updateItem_(index, data); | 17234 Manager.get().updateItem_(index, data); |
| 17195 }; | 17235 }; |
| 17196 | 17236 |
| 17197 return {Manager: Manager}; | 17237 return {Manager: Manager}; |
| 17198 }); | 17238 }); |
| 17199 // Copyright 2015 The Chromium Authors. All rights reserved. | 17239 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 17200 // Use of this source code is governed by a BSD-style license that can be | 17240 // Use of this source code is governed by a BSD-style license that can be |
| 17201 // found in the LICENSE file. | 17241 // found in the LICENSE file. |
| 17202 | 17242 |
| 17203 window.addEventListener('load', downloads.Manager.onLoad); | 17243 window.addEventListener('load', downloads.Manager.onLoad); |
| OLD | NEW |