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 10296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10307 | 10307 |
10308 _altChanged: function(newValue, oldValue) { | 10308 _altChanged: function(newValue, oldValue) { |
10309 var label = this.getAttribute('aria-label'); | 10309 var label = this.getAttribute('aria-label'); |
10310 | 10310 |
10311 // Don't stomp over a user-set aria-label. | 10311 // Don't stomp over a user-set aria-label. |
10312 if (!label || oldValue == label) { | 10312 if (!label || oldValue == label) { |
10313 this.setAttribute('aria-label', newValue); | 10313 this.setAttribute('aria-label', newValue); |
10314 } | 10314 } |
10315 } | 10315 } |
10316 }); | 10316 }); |
| 10317 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 10318 // Use of this source code is governed by a BSD-style license that can be |
| 10319 // found in the LICENSE file. |
| 10320 |
| 10321 /** @interface */ |
| 10322 var SearchFieldDelegate = function() {}; |
| 10323 |
| 10324 SearchFieldDelegate.prototype = { |
| 10325 /** |
| 10326 * @param {string} value |
| 10327 */ |
| 10328 onSearchTermSearch: assertNotReached, |
| 10329 }; |
| 10330 |
| 10331 /** |
| 10332 * Implements an incremental search field which can be shown and hidden. |
| 10333 * Canonical implementation is <cr-search-field>. |
| 10334 * @polymerBehavior |
| 10335 */ |
| 10336 var CrSearchFieldBehavior = { |
| 10337 properties: { |
| 10338 label: { |
| 10339 type: String, |
| 10340 value: '', |
| 10341 }, |
| 10342 |
| 10343 clearLabel: { |
| 10344 type: String, |
| 10345 value: '', |
| 10346 }, |
| 10347 |
| 10348 showingSearch: { |
| 10349 type: Boolean, |
| 10350 value: false, |
| 10351 notify: true, |
| 10352 observer: 'showingSearchChanged_', |
| 10353 reflectToAttribute: true |
| 10354 }, |
| 10355 |
| 10356 hasSearchText: Boolean, |
| 10357 }, |
| 10358 |
| 10359 /** |
| 10360 * @return {string} The value of the search field. |
| 10361 */ |
| 10362 getValue: function() { |
| 10363 return this.$.searchInput.value; |
| 10364 }, |
| 10365 |
| 10366 /** |
| 10367 * Sets the value of the search field, if it exists. |
| 10368 * @param {string} value |
| 10369 */ |
| 10370 setValue: function(value) { |
| 10371 // Use bindValue when setting the input value so that changes propagate |
| 10372 // correctly. |
| 10373 this.$.searchInput.bindValue = value; |
| 10374 this.hasSearchText = value != ''; |
| 10375 }, |
| 10376 |
| 10377 /** @param {SearchFieldDelegate} delegate */ |
| 10378 setDelegate: function(delegate) { |
| 10379 this.delegate_ = delegate; |
| 10380 }, |
| 10381 |
| 10382 /** @return {!Promise<boolean>} */ |
| 10383 showAndFocus: function() { |
| 10384 this.showingSearch = true; |
| 10385 return this.focus_(); |
| 10386 }, |
| 10387 |
| 10388 /** |
| 10389 * @return {!Promise<boolean>} |
| 10390 * @private |
| 10391 */ |
| 10392 focus_: function() { |
| 10393 return new Promise(function(resolve) { |
| 10394 this.async(function() { |
| 10395 if (this.showingSearch) { |
| 10396 this.$.searchInput.focus(); |
| 10397 } |
| 10398 resolve(this.showingSearch); |
| 10399 }); |
| 10400 }.bind(this)); |
| 10401 }, |
| 10402 |
| 10403 /** @private */ |
| 10404 onSearchTermSearch_: function() { |
| 10405 this.hasSearchText = this.getValue() != ''; |
| 10406 if (this.delegate_) |
| 10407 this.delegate_.onSearchTermSearch(this.getValue()); |
| 10408 }, |
| 10409 |
| 10410 /** @private */ |
| 10411 onSearchTermKeydown_: function(e) { |
| 10412 if (e.key == 'Escape') |
| 10413 this.showingSearch = false; |
| 10414 }, |
| 10415 |
| 10416 /** @private */ |
| 10417 showingSearchChanged_: function() { |
| 10418 if (this.showingSearch) { |
| 10419 this.focus_(); |
| 10420 return; |
| 10421 } |
| 10422 |
| 10423 this.setValue(''); |
| 10424 this.$.searchInput.blur(); |
| 10425 this.onSearchTermSearch_(); |
| 10426 }, |
| 10427 |
| 10428 /** @private */ |
| 10429 toggleShowingSearch_: function() { |
| 10430 this.showingSearch = !this.showingSearch; |
| 10431 }, |
| 10432 }; |
10317 (function() { | 10433 (function() { |
10318 'use strict'; | 10434 'use strict'; |
10319 | 10435 |
10320 Polymer.IronA11yAnnouncer = Polymer({ | 10436 Polymer.IronA11yAnnouncer = Polymer({ |
10321 is: 'iron-a11y-announcer', | 10437 is: 'iron-a11y-announcer', |
10322 | 10438 |
10323 properties: { | 10439 properties: { |
10324 | 10440 |
10325 /** | 10441 /** |
10326 * The value of mode is used to set the `aria-live` attribute | 10442 * The value of mode is used to set the `aria-live` attribute |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11072 } else if (focused) { | 11188 } else if (focused) { |
11073 cls += ' is-highlighted' | 11189 cls += ' is-highlighted' |
11074 } | 11190 } |
11075 return cls; | 11191 return cls; |
11076 } | 11192 } |
11077 }); | 11193 }); |
11078 // Copyright 2015 The Chromium Authors. All rights reserved. | 11194 // Copyright 2015 The Chromium Authors. All rights reserved. |
11079 // Use of this source code is governed by a BSD-style license that can be | 11195 // Use of this source code is governed by a BSD-style license that can be |
11080 // found in the LICENSE file. | 11196 // found in the LICENSE file. |
11081 | 11197 |
11082 /** @interface */ | |
11083 var SearchFieldDelegate = function() {}; | |
11084 | |
11085 SearchFieldDelegate.prototype = { | |
11086 /** | |
11087 * @param {string} value | |
11088 */ | |
11089 onSearchTermSearch: assertNotReached, | |
11090 }; | |
11091 | |
11092 var SearchField = Polymer({ | 11198 var SearchField = Polymer({ |
11093 is: 'cr-search-field', | 11199 is: 'cr-search-field', |
11094 | 11200 behaviors: [CrSearchFieldBehavior] |
11095 properties: { | |
11096 label: { | |
11097 type: String, | |
11098 value: '', | |
11099 }, | |
11100 | |
11101 clearLabel: { | |
11102 type: String, | |
11103 value: '', | |
11104 }, | |
11105 | |
11106 showingSearch_: { | |
11107 type: Boolean, | |
11108 value: false, | |
11109 observer: 'showingSearchChanged_', | |
11110 }, | |
11111 }, | |
11112 | |
11113 /** | |
11114 * Returns the value of the search field. | |
11115 * @return {string} | |
11116 */ | |
11117 getValue: function() { | |
11118 var searchInput = this.getSearchInput_(); | |
11119 return searchInput ? searchInput.value : ''; | |
11120 }, | |
11121 | |
11122 /** | |
11123 * Sets the value of the search field, if it exists. | |
11124 * @param {string} value | |
11125 */ | |
11126 setValue: function(value) { | |
11127 var searchInput = this.getSearchInput_(); | |
11128 if (searchInput) | |
11129 searchInput.value = value; | |
11130 }, | |
11131 | |
11132 /** @param {SearchFieldDelegate} delegate */ | |
11133 setDelegate: function(delegate) { | |
11134 this.delegate_ = delegate; | |
11135 }, | |
11136 | |
11137 /** @return {Promise<boolean>} */ | |
11138 showAndFocus: function() { | |
11139 this.showingSearch_ = true; | |
11140 return this.focus_(); | |
11141 }, | |
11142 | |
11143 /** | |
11144 * @return {Promise<boolean>} | |
11145 * @private | |
11146 */ | |
11147 focus_: function() { | |
11148 return new Promise(function(resolve) { | |
11149 this.async(function() { | |
11150 if (this.showingSearch_) { | |
11151 var searchInput = this.getSearchInput_(); | |
11152 if (searchInput) | |
11153 searchInput.focus(); | |
11154 } | |
11155 resolve(this.showingSearch_); | |
11156 }); | |
11157 }.bind(this)); | |
11158 }, | |
11159 | |
11160 /** | |
11161 * @return {?Element} | |
11162 * @private | |
11163 */ | |
11164 getSearchInput_: function() { | |
11165 return this.$$('#search-input'); | |
11166 }, | |
11167 | |
11168 /** @private */ | |
11169 onSearchTermSearch_: function() { | |
11170 if (this.delegate_) | |
11171 this.delegate_.onSearchTermSearch(this.getValue()); | |
11172 }, | |
11173 | |
11174 /** @private */ | |
11175 onSearchTermKeydown_: function(e) { | |
11176 if (e.keyIdentifier == 'U+001B') // Escape. | |
11177 this.showingSearch_ = false; | |
11178 }, | |
11179 | |
11180 /** @private */ | |
11181 showingSearchChanged_: function() { | |
11182 if (this.showingSearch_) { | |
11183 this.focus_(); | |
11184 return; | |
11185 } | |
11186 | |
11187 var searchInput = this.getSearchInput_(); | |
11188 if (!searchInput) | |
11189 return; | |
11190 | |
11191 searchInput.value = ''; | |
11192 this.onSearchTermSearch_(); | |
11193 }, | |
11194 | |
11195 /** @private */ | |
11196 toggleShowingSearch_: function() { | |
11197 this.showingSearch_ = !this.showingSearch_; | |
11198 }, | |
11199 }); | 11201 }); |
11200 // Copyright 2015 The Chromium Authors. All rights reserved. | 11202 // Copyright 2015 The Chromium Authors. All rights reserved. |
11201 // Use of this source code is governed by a BSD-style license that can be | 11203 // Use of this source code is governed by a BSD-style license that can be |
11202 // found in the LICENSE file. | 11204 // found in the LICENSE file. |
11203 | 11205 |
11204 cr.define('downloads', function() { | 11206 cr.define('downloads', function() { |
11205 var Toolbar = Polymer({ | 11207 var Toolbar = Polymer({ |
11206 is: 'downloads-toolbar', | 11208 is: 'downloads-toolbar', |
11207 | 11209 |
11208 attached: function() { | 11210 attached: function() { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11479 Manager.get().updateItem_(index, data); | 11481 Manager.get().updateItem_(index, data); |
11480 }; | 11482 }; |
11481 | 11483 |
11482 return {Manager: Manager}; | 11484 return {Manager: Manager}; |
11483 }); | 11485 }); |
11484 // Copyright 2015 The Chromium Authors. All rights reserved. | 11486 // Copyright 2015 The Chromium Authors. All rights reserved. |
11485 // Use of this source code is governed by a BSD-style license that can be | 11487 // Use of this source code is governed by a BSD-style license that can be |
11486 // found in the LICENSE file. | 11488 // found in the LICENSE file. |
11487 | 11489 |
11488 window.addEventListener('load', downloads.Manager.onLoad); | 11490 window.addEventListener('load', downloads.Manager.onLoad); |
OLD | NEW |