Chromium Code Reviews| 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 /** | 5 /** |
| 6 * @fileoverview |GlobalScrollTargetBehavior| allows an element to be aware of | 6 * @fileoverview |GlobalScrollTargetBehavior| allows an element to be aware of |
| 7 * the global scroll target. |scrollTarget| will be populated async by | 7 * the global scroll target. |scrollTarget| will be populated async by |
|
michaelpg
2016/12/02 20:37:26
update comments: when should scrollTarget be used
hcarmona
2016/12/05 15:57:35
Done.
| |
| 8 * |setGlobalScrollTarget|. |setGlobalScrollTarget| should only be called once. | 8 * |setGlobalScrollTarget|. |setGlobalScrollTarget| should only be called once. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 cr.define('settings', function() { | 11 cr.define('settings', function() { |
| 12 var scrollTargetResolver = new PromiseResolver(); | 12 var scrollTargetResolver = new PromiseResolver(); |
| 13 | 13 |
| 14 /** @polymerBehavior */ | 14 /** @polymerBehavior */ |
| 15 var GlobalScrollTargetBehavior = { | 15 var GlobalScrollTargetBehaviorImpl = { |
| 16 properties: { | 16 properties: { |
| 17 /** | 17 /** |
| 18 * Read only property for the scroll target. | 18 * Read only property for the scroll target. |
| 19 * @type {HTMLElement} | 19 * @type {HTMLElement} |
| 20 */ | 20 */ |
| 21 scrollTarget: { | 21 scrollTarget: { |
| 22 type: Object, | 22 type: Object, |
| 23 readOnly: true, | 23 readOnly: true, |
| 24 }, | 24 }, |
| 25 | |
| 26 /** | |
| 27 * Property that is populated only when the |activeRoute| is navigated to. | |
| 28 * @type {HTMLElement} | |
| 29 */ | |
| 30 activeTarget: { | |
|
michaelpg
2016/12/02 20:37:26
nit: can you use something other than "active" for
hcarmona
2016/12/05 15:57:35
Updated names to make it more apparent that these
| |
| 31 type: Object, | |
| 32 computed: 'getActiveTarget_(scrollTarget, active_)', | |
| 33 }, | |
| 34 | |
| 35 /** | |
| 36 * The route that controls the active state. | |
| 37 * @type {settings.Route} | |
| 38 * @private | |
| 39 */ | |
| 40 activeRoute: Object, | |
| 41 | |
| 42 /** Whether the |activeRoute| is active or not. */ | |
| 43 active_: Boolean, | |
| 25 }, | 44 }, |
| 26 | 45 |
| 27 /** @override */ | 46 /** @override */ |
| 28 attached: function() { | 47 attached: function() { |
| 29 scrollTargetResolver.promise.then(this._setScrollTarget.bind(this)); | 48 scrollTargetResolver.promise.then(this._setScrollTarget.bind(this)); |
| 30 }, | 49 }, |
| 50 | |
| 51 currentRouteChanged: function(route) { | |
| 52 this.active_ = route == this.activeRoute; | |
| 53 }, | |
| 54 | |
| 55 getActiveTarget_: function(target, active) { | |
| 56 return active ? target : null; | |
| 57 }, | |
| 31 }; | 58 }; |
| 32 | 59 |
| 33 /** | 60 /** |
| 34 * This should only be called once. | 61 * This should only be called once. |
| 35 * @param {HTMLElement} scrollTarget | 62 * @param {HTMLElement} scrollTarget |
| 36 */ | 63 */ |
| 37 var setGlobalScrollTarget = function(scrollTarget) { | 64 var setGlobalScrollTarget = function(scrollTarget) { |
| 38 scrollTargetResolver.resolve(scrollTarget); | 65 scrollTargetResolver.resolve(scrollTarget); |
| 39 }; | 66 }; |
| 40 | 67 |
| 41 return { | 68 return { |
| 42 GlobalScrollTargetBehavior: GlobalScrollTargetBehavior, | 69 GlobalScrollTargetBehaviorImpl: GlobalScrollTargetBehaviorImpl, |
| 43 setGlobalScrollTarget: setGlobalScrollTarget, | 70 setGlobalScrollTarget: setGlobalScrollTarget, |
| 71 scrollTargetResolver: scrollTargetResolver, | |
| 44 }; | 72 }; |
| 45 }); | 73 }); |
| 74 | |
| 75 // This is done to make the closure compiler happy: it needs fully qualified | |
| 76 // names when specifying an array of behaviors. | |
| 77 /** @polymerBehavior */ | |
| 78 settings.GlobalScrollTargetBehavior = | |
| 79 [settings.RouteObserverBehavior, settings.GlobalScrollTargetBehaviorImpl]; | |
|
michaelpg
2016/12/02 20:37:26
4-space indent
hcarmona
2016/12/05 15:57:35
Done.
| |
| OLD | NEW |