Index: chrome/browser/resources/settings/global_scroll_target_behavior.js |
diff --git a/chrome/browser/resources/settings/global_scroll_target_behavior.js b/chrome/browser/resources/settings/global_scroll_target_behavior.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..82ca46dadfe9d39ce3cda47d68cacf8d9a42778f |
--- /dev/null |
+++ b/chrome/browser/resources/settings/global_scroll_target_behavior.js |
@@ -0,0 +1,61 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** |
+ * @fileoverview A helper object to be used when an iron-list needs to be aware |
+ * of a global scroll target. |
michaelpg
2016/10/19 19:50:09
I'd add a little more instruction here, e.g. that
hcarmona
2016/10/20 14:27:44
Done.
|
+ */ |
+ |
+/** |
+ * Global object to hold the scroll target. |
+ * @type {{ |
+ * targetPromise: (Promise<HTMLElement>|undefined), |
+ * fulfillPromise: (function(HTMLElement)|undefined), |
+ * }} |
+ */ |
+global.settingsScrollTargetData = {}; |
michaelpg
2016/10/19 19:50:09
where does |global| actually come from? dunno why
hcarmona
2016/10/20 14:27:44
|global| is defined here: https://cs.chromium.org/
|
+/** @type {Promise<HTMLElement>} */ |
+global.settingsScrollTargetData.targetPromise = new Promise(function(accept) { |
michaelpg
2016/10/19 19:50:09
Would our PromiseResolver be more convenient?
hcarmona
2016/10/20 14:27:44
Yes
|
+ global.settingsScrollTargetData.fulfillPromise = accept; |
+}); |
+ |
+/** @polymerBehavior */ |
+var GlobalScrollTargetBehavior = { |
+ properties: { |
+ /** |
+ * Read only property for the scroll target. |
+ * @type {HTMLElement} |
+ */ |
+ scrollTarget: { |
+ type: Object, |
+ notify: true, |
michaelpg
2016/10/19 19:50:09
Shouldn't need notify: true; as we're not 2-way bi
hcarmona
2016/10/20 14:27:44
Done.
|
+ readOnly: true, |
+ }, |
+ }, |
+ |
+ /** |
+ * Reference to the global data. This allows Polymer style data binding. |
michaelpg
2016/10/19 19:50:08
comment outdated
hcarmona
2016/10/20 14:27:44
Acknowledged.
|
+ * @type {{ |
+ * targetPromise: (Promise<HTMLElement>|undefined), |
michaelpg
2016/10/19 19:50:09
make a typedef instead of copying/pasting
hcarmona
2016/10/20 14:27:44
Acknowledged.
|
+ * fulfillPromise: (function(HTMLElement)|undefined), |
+ * }} |
+ * @private |
+ */ |
+ globalData_: global.settingsScrollTargetData, |
+ |
+ /** @override */ |
+ attached: function() { |
+ this.globalData_.targetPromise.then(function(scrollTarget) { |
+ this._setScrollTarget(scrollTarget); |
+ }.bind(this)); |
+ }, |
+ |
+ /** |
+ * This should only be called once. |
+ * @param {HTMLElement} value |
+ */ |
+ setGlobalScrollTarget: function(value) { |
+ this.globalData_.fulfillPromise(value); |
+ }, |
+}; |