| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 /** | 5 /** |
| 6 * @fileoverview Assertion support. | 6 * @fileoverview Assertion support. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Verify |condition| is truthy and return |condition| if so. | 10 * Verify |condition| is truthy and return |condition| if so. |
| (...skipping 10319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10330 // Don't stomp over a user-set aria-label. | 10330 // Don't stomp over a user-set aria-label. |
| 10331 if (!label || oldValue == label) { | 10331 if (!label || oldValue == label) { |
| 10332 this.setAttribute('aria-label', newValue); | 10332 this.setAttribute('aria-label', newValue); |
| 10333 } | 10333 } |
| 10334 } | 10334 } |
| 10335 }); | 10335 }); |
| 10336 // Copyright 2016 The Chromium Authors. All rights reserved. | 10336 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 10337 // Use of this source code is governed by a BSD-style license that can be | 10337 // Use of this source code is governed by a BSD-style license that can be |
| 10338 // found in the LICENSE file. | 10338 // found in the LICENSE file. |
| 10339 | 10339 |
| 10340 /** @interface */ | |
| 10341 var SearchFieldDelegate = function() {}; | |
| 10342 | |
| 10343 SearchFieldDelegate.prototype = { | |
| 10344 /** | |
| 10345 * @param {string} value | |
| 10346 */ | |
| 10347 onSearchTermSearch: assertNotReached, | |
| 10348 }; | |
| 10349 | |
| 10350 /** | 10340 /** |
| 10351 * Implements an incremental search field which can be shown and hidden. | 10341 * Implements an incremental search field which can be shown and hidden. |
| 10352 * Canonical implementation is <cr-search-field>. | 10342 * Canonical implementation is <cr-search-field>. |
| 10353 * @polymerBehavior | 10343 * @polymerBehavior |
| 10354 */ | 10344 */ |
| 10355 var CrSearchFieldBehavior = { | 10345 var CrSearchFieldBehavior = { |
| 10356 properties: { | 10346 properties: { |
| 10357 label: { | 10347 label: { |
| 10358 type: String, | 10348 type: String, |
| 10359 value: '', | 10349 value: '', |
| 10360 }, | 10350 }, |
| 10361 | 10351 |
| 10362 clearLabel: { | 10352 clearLabel: { |
| 10363 type: String, | 10353 type: String, |
| 10364 value: '', | 10354 value: '', |
| 10365 }, | 10355 }, |
| 10366 | 10356 |
| 10367 showingSearch: { | 10357 showingSearch: { |
| 10368 type: Boolean, | 10358 type: Boolean, |
| 10369 value: false, | 10359 value: false, |
| 10370 notify: true, | 10360 notify: true, |
| 10371 observer: 'showingSearchChanged_', | 10361 observer: 'showingSearchChanged_', |
| 10372 reflectToAttribute: true | 10362 reflectToAttribute: true |
| 10373 }, | 10363 }, |
| 10374 | 10364 |
| 10375 hasSearchText: Boolean, | 10365 hasSearchText: Boolean, |
| 10366 |
| 10367 /** @private */ |
| 10368 lastValue_: { |
| 10369 type: String, |
| 10370 value: '', |
| 10371 }, |
| 10376 }, | 10372 }, |
| 10377 | 10373 |
| 10378 /** | 10374 /** |
| 10379 * @return {string} The value of the search field. | 10375 * @return {string} The value of the search field. |
| 10380 */ | 10376 */ |
| 10381 getValue: function() { | 10377 getValue: function() { |
| 10382 return this.$.searchInput.value; | 10378 return this.$.searchInput.value; |
| 10383 }, | 10379 }, |
| 10384 | 10380 |
| 10385 /** | 10381 /** |
| 10386 * Sets the value of the search field, if it exists. | 10382 * Sets the value of the search field, if it exists. |
| 10387 * @param {string} value | 10383 * @param {string} value |
| 10388 */ | 10384 */ |
| 10389 setValue: function(value) { | 10385 setValue: function(value) { |
| 10390 // Use bindValue when setting the input value so that changes propagate | 10386 // Use bindValue when setting the input value so that changes propagate |
| 10391 // correctly. | 10387 // correctly. |
| 10392 this.$.searchInput.bindValue = value; | 10388 this.$.searchInput.bindValue = value; |
| 10393 this.hasSearchText = value != ''; | 10389 this.hasSearchText = value != ''; |
| 10394 }, | 10390 }, |
| 10395 | 10391 |
| 10396 /** @param {SearchFieldDelegate} delegate */ | |
| 10397 setDelegate: function(delegate) { | |
| 10398 this.delegate_ = delegate; | |
| 10399 }, | |
| 10400 | |
| 10401 showAndFocus: function() { | 10392 showAndFocus: function() { |
| 10402 this.showingSearch = true; | 10393 this.showingSearch = true; |
| 10403 this.focus_(); | 10394 this.focus_(); |
| 10404 }, | 10395 }, |
| 10405 | 10396 |
| 10406 /** @private */ | 10397 /** @private */ |
| 10407 focus_: function() { | 10398 focus_: function() { |
| 10408 this.$.searchInput.focus(); | 10399 this.$.searchInput.focus(); |
| 10409 }, | 10400 }, |
| 10410 | 10401 |
| 10411 /** @private */ | 10402 onSearchTermSearch: function() { |
| 10412 onSearchTermSearch_: function() { | 10403 var newValue = this.getValue(); |
| 10413 this.hasSearchText = this.getValue() != ''; | 10404 if (newValue == this.lastValue_) |
| 10414 if (this.delegate_) | 10405 return; |
| 10415 this.delegate_.onSearchTermSearch(this.getValue()); | 10406 |
| 10407 this.hasSearchText = newValue != ''; |
| 10408 this.fire('search-changed', newValue); |
| 10409 this.lastValue_ = newValue; |
| 10416 }, | 10410 }, |
| 10417 | 10411 |
| 10418 /** @private */ | 10412 onSearchTermKeydown: function(e) { |
| 10419 onSearchTermKeydown_: function(e) { | |
| 10420 if (e.key == 'Escape') | 10413 if (e.key == 'Escape') |
| 10421 this.showingSearch = false; | 10414 this.showingSearch = false; |
| 10422 }, | 10415 }, |
| 10423 | 10416 |
| 10424 /** @private */ | 10417 /** @private */ |
| 10425 showingSearchChanged_: function() { | 10418 showingSearchChanged_: function() { |
| 10426 if (this.showingSearch) { | 10419 if (this.showingSearch) { |
| 10427 this.focus_(); | 10420 this.focus_(); |
| 10428 return; | 10421 return; |
| 10429 } | 10422 } |
| 10430 | 10423 |
| 10431 this.setValue(''); | 10424 this.setValue(''); |
| 10432 this.$.searchInput.blur(); | 10425 this.$.searchInput.blur(); |
| 10433 this.onSearchTermSearch_(); | 10426 this.onSearchTermSearch(); |
| 10434 }, | 10427 }, |
| 10435 | 10428 |
| 10436 /** @private */ | 10429 /** @private */ |
| 10437 toggleShowingSearch_: function() { | 10430 toggleShowingSearch_: function() { |
| 10438 this.showingSearch = !this.showingSearch; | 10431 this.showingSearch = !this.showingSearch; |
| 10439 }, | 10432 }, |
| 10440 }; | 10433 }; |
| 10441 (function() { | 10434 (function() { |
| 10442 'use strict'; | 10435 'use strict'; |
| 10443 | 10436 |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11211 // Use of this source code is governed by a BSD-style license that can be | 11204 // Use of this source code is governed by a BSD-style license that can be |
| 11212 // found in the LICENSE file. | 11205 // found in the LICENSE file. |
| 11213 | 11206 |
| 11214 cr.define('downloads', function() { | 11207 cr.define('downloads', function() { |
| 11215 var Toolbar = Polymer({ | 11208 var Toolbar = Polymer({ |
| 11216 is: 'downloads-toolbar', | 11209 is: 'downloads-toolbar', |
| 11217 | 11210 |
| 11218 attached: function() { | 11211 attached: function() { |
| 11219 // isRTL() only works after i18n_template.js runs to set <html dir>. | 11212 // isRTL() only works after i18n_template.js runs to set <html dir>. |
| 11220 this.overflowAlign_ = isRTL() ? 'left' : 'right'; | 11213 this.overflowAlign_ = isRTL() ? 'left' : 'right'; |
| 11221 | |
| 11222 /** @private {!SearchFieldDelegate} */ | |
| 11223 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this); | |
| 11224 this.$['search-input'].setDelegate(this.searchFieldDelegate_); | |
| 11225 }, | 11214 }, |
| 11226 | 11215 |
| 11227 properties: { | 11216 properties: { |
| 11228 downloadsShowing: { | 11217 downloadsShowing: { |
| 11229 reflectToAttribute: true, | 11218 reflectToAttribute: true, |
| 11230 type: Boolean, | 11219 type: Boolean, |
| 11231 value: false, | 11220 value: false, |
| 11232 observer: 'downloadsShowingChanged_', | 11221 observer: 'downloadsShowingChanged_', |
| 11233 }, | 11222 }, |
| 11234 | 11223 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 11256 onClearAllTap_: function() { | 11245 onClearAllTap_: function() { |
| 11257 assert(this.canClearAll()); | 11246 assert(this.canClearAll()); |
| 11258 downloads.ActionService.getInstance().clearAll(); | 11247 downloads.ActionService.getInstance().clearAll(); |
| 11259 }, | 11248 }, |
| 11260 | 11249 |
| 11261 /** @private */ | 11250 /** @private */ |
| 11262 downloadsShowingChanged_: function() { | 11251 downloadsShowingChanged_: function() { |
| 11263 this.updateClearAll_(); | 11252 this.updateClearAll_(); |
| 11264 }, | 11253 }, |
| 11265 | 11254 |
| 11266 /** @param {string} searchTerm */ | 11255 /** |
| 11267 onSearchTermSearch: function(searchTerm) { | 11256 * @param {!CustomEvent} event |
| 11268 downloads.ActionService.getInstance().search(searchTerm); | 11257 * @private |
| 11258 */ |
| 11259 onSearchChanged_: function(event) { |
| 11260 downloads.ActionService.getInstance().search(event.detail); |
| 11269 this.updateClearAll_(); | 11261 this.updateClearAll_(); |
| 11270 }, | 11262 }, |
| 11271 | 11263 |
| 11272 /** @private */ | 11264 /** @private */ |
| 11273 onOpenDownloadsFolderTap_: function() { | 11265 onOpenDownloadsFolderTap_: function() { |
| 11274 downloads.ActionService.getInstance().openDownloadsFolder(); | 11266 downloads.ActionService.getInstance().openDownloadsFolder(); |
| 11275 }, | 11267 }, |
| 11276 | 11268 |
| 11277 /** @private */ | 11269 /** @private */ |
| 11278 updateClearAll_: function() { | 11270 updateClearAll_: function() { |
| 11279 this.$$('#actions .clear-all').hidden = !this.canClearAll(); | 11271 this.$$('#actions .clear-all').hidden = !this.canClearAll(); |
| 11280 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); | 11272 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); |
| 11281 }, | 11273 }, |
| 11282 }); | 11274 }); |
| 11283 | 11275 |
| 11284 /** | |
| 11285 * @constructor | |
| 11286 * @implements {SearchFieldDelegate} | |
| 11287 */ | |
| 11288 // TODO(devlin): This is a bit excessive, and it would be better to just have | |
| 11289 // Toolbar implement SearchFieldDelegate. But for now, we don't know how to | |
| 11290 // make that happen with closure compiler. | |
| 11291 function ToolbarSearchFieldDelegate(toolbar) { | |
| 11292 this.toolbar_ = toolbar; | |
| 11293 } | |
| 11294 | |
| 11295 ToolbarSearchFieldDelegate.prototype = { | |
| 11296 /** @override */ | |
| 11297 onSearchTermSearch: function(searchTerm) { | |
| 11298 this.toolbar_.onSearchTermSearch(searchTerm); | |
| 11299 } | |
| 11300 }; | |
| 11301 | |
| 11302 return {Toolbar: Toolbar}; | 11276 return {Toolbar: Toolbar}; |
| 11303 }); | 11277 }); |
| 11304 | 11278 |
| 11305 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files | 11279 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files |
| 11306 /** @suppress {checkTypes} */ | 11280 /** @suppress {checkTypes} */ |
| 11307 (function() { | 11281 (function() { |
| 11308 Polymer.IronDropdownScrollManager.pushScrollLock = function() {}; | 11282 Polymer.IronDropdownScrollManager.pushScrollLock = function() {}; |
| 11309 })(); | 11283 })(); |
| 11310 // Copyright 2015 The Chromium Authors. All rights reserved. | 11284 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 11311 // Use of this source code is governed by a BSD-style license that can be | 11285 // Use of this source code is governed by a BSD-style license that can be |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11489 Manager.get().updateItem_(index, data); | 11463 Manager.get().updateItem_(index, data); |
| 11490 }; | 11464 }; |
| 11491 | 11465 |
| 11492 return {Manager: Manager}; | 11466 return {Manager: Manager}; |
| 11493 }); | 11467 }); |
| 11494 // Copyright 2015 The Chromium Authors. All rights reserved. | 11468 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 11495 // Use of this source code is governed by a BSD-style license that can be | 11469 // Use of this source code is governed by a BSD-style license that can be |
| 11496 // found in the LICENSE file. | 11470 // found in the LICENSE file. |
| 11497 | 11471 |
| 11498 window.addEventListener('load', downloads.Manager.onLoad); | 11472 window.addEventListener('load', downloads.Manager.onLoad); |
| OLD | NEW |