@carbon/ibmdotcom-utilities 2.10.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/utilities/StickyHeader/StickyHeader.js +380 -163
- package/es/utilities/focuswrap/focuswrap.js +4 -4
- package/es/utilities/ipcinfoCookie/ipcinfoCookie.js +3 -3
- package/es/utilities/settings/settings.js +2 -2
- package/lib/utilities/StickyHeader/StickyHeader.js +381 -164
- package/lib/utilities/StickyHeader/index.js +1 -1
- package/lib/utilities/altlangs/altlangs.js +1 -1
- package/lib/utilities/altlangs/index.js +1 -1
- package/lib/utilities/calculateTotalWidth/index.js +1 -1
- package/lib/utilities/decodeString/index.js +1 -1
- package/lib/utilities/deprecate/index.js +1 -1
- package/lib/utilities/escaperegexp/index.js +1 -1
- package/lib/utilities/featureflag/index.js +1 -1
- package/lib/utilities/focuswrap/focuswrap.js +4 -4
- package/lib/utilities/ipcinfoCookie/index.js +1 -1
- package/lib/utilities/ipcinfoCookie/ipcinfoCookie.js +4 -4
- package/lib/utilities/loadNonLatinPlex/index.js +1 -1
- package/lib/utilities/markdownToHtml/index.js +1 -1
- package/lib/utilities/markdownToHtml/markdownToHtml.js +1 -1
- package/lib/utilities/on/index.js +1 -1
- package/lib/utilities/parseAspectRatio/index.js +1 -1
- package/lib/utilities/removeHtmlTagEntities/index.js +1 -1
- package/lib/utilities/removeHtmlTagEntities/removeHtmlTagEntities.js +1 -1
- package/lib/utilities/sameHeight/index.js +1 -1
- package/lib/utilities/serialize/index.js +1 -1
- package/lib/utilities/settings/index.js +1 -1
- package/lib/utilities/settings/settings.js +2 -2
- package/lib/utilities/smoothScroll/index.js +1 -1
- package/lib/utilities/stripHTML/index.js +1 -1
- package/lib/utilities/uniqueid/index.js +1 -1
- package/package.json +2 -2
- package/umd/ibmdotcom-utilities.js +34 -29
- package/umd/ibmdotcom-utilities.min.js +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _classCallCheck(
|
|
3
|
-
function _defineProperties(
|
|
4
|
-
function _createClass(
|
|
2
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
3
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
4
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
/**
|
|
@@ -16,25 +16,39 @@ import root from 'window-or-global';
|
|
|
16
16
|
import settings from '../settings/settings.js';
|
|
17
17
|
var prefix = settings.prefix,
|
|
18
18
|
c4dPrefix = settings.stablePrefix;
|
|
19
|
+
var ddsPrefix = 'dds';
|
|
20
|
+
var bxPrefix = 'bx';
|
|
19
21
|
var gridBreakpoint = parseFloat(breakpoints.lg.width) * baseFontSize;
|
|
20
22
|
var StickyHeader = /*#__PURE__*/function () {
|
|
21
23
|
function StickyHeader() {
|
|
22
24
|
_classCallCheck(this, StickyHeader);
|
|
23
25
|
this.ownerDocument = root.document;
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
this._state = {
|
|
27
|
+
cumulativeOffset: 0,
|
|
28
|
+
hasBanner: false,
|
|
29
|
+
leadspaceSearchThreshold: 0,
|
|
30
|
+
mastheadL0IsActive: false,
|
|
31
|
+
mastheadL1IsActive: false,
|
|
32
|
+
maxScrollaway: 0,
|
|
33
|
+
scrollPosPrevious: 0,
|
|
34
|
+
scrollPos: 0,
|
|
35
|
+
searchIsAtTop: false,
|
|
36
|
+
tocShouldStick: false,
|
|
37
|
+
tocIsAtTop: false,
|
|
38
|
+
tocIsAtSearch: false
|
|
39
|
+
};
|
|
40
|
+
this._elements = {
|
|
41
|
+
banner: undefined,
|
|
42
|
+
leadspaceSearch: undefined,
|
|
43
|
+
leadspaceSearchBar: undefined,
|
|
44
|
+
leadspaceSearchInput: undefined,
|
|
45
|
+
localeModal: undefined,
|
|
46
|
+
masthead: undefined,
|
|
47
|
+
mastheadL0: undefined,
|
|
48
|
+
mastheadL1: undefined,
|
|
49
|
+
tableOfContents: undefined,
|
|
50
|
+
tableOfContentsInnerBar: undefined
|
|
51
|
+
};
|
|
38
52
|
this._throttled = false;
|
|
39
53
|
this._resizeObserver = new ResizeObserver(this._handleResize.bind(this));
|
|
40
54
|
root.addEventListener('scroll', this._throttledHandler.bind(this));
|
|
@@ -46,7 +60,7 @@ var StickyHeader = /*#__PURE__*/function () {
|
|
|
46
60
|
return _createClass(StickyHeader, [{
|
|
47
61
|
key: "height",
|
|
48
62
|
get: function get() {
|
|
49
|
-
return this.
|
|
63
|
+
return this._state.cumulativeOffset;
|
|
50
64
|
}
|
|
51
65
|
|
|
52
66
|
/**
|
|
@@ -62,78 +76,176 @@ var StickyHeader = /*#__PURE__*/function () {
|
|
|
62
76
|
value: function _validateComponent(component, expected) {
|
|
63
77
|
var received = component.tagName.toLowerCase();
|
|
64
78
|
if (received !== expected) {
|
|
65
|
-
|
|
79
|
+
// TODO: don't check for v1/v2 compatibility after v1 EOL.
|
|
80
|
+
if (received.split('-').splice(1).join('-') !== expected.split('-').splice(1).join('-')) {
|
|
81
|
+
throw new TypeError("".concat(expected, " expected, ").concat(received, " provided"));
|
|
82
|
+
} else {
|
|
83
|
+
var message = ["Mixed prefixes detected.\n", "expected ".concat(expected, ", found ").concat(received, ".")];
|
|
84
|
+
console.warn(message.join(''));
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
66
87
|
} else {
|
|
67
88
|
return true;
|
|
68
89
|
}
|
|
69
90
|
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Helper method to query for either C4IBM v1.x or v2.x sub-elements;
|
|
94
|
+
*
|
|
95
|
+
* @param {*} element The C4IBM element.
|
|
96
|
+
* @param {*} v1Func The querying function to run if using a C4IBM v1.x element.
|
|
97
|
+
* @param {*} v2Func The querying function to run if using a C4IBM v2.x element.
|
|
98
|
+
*/
|
|
70
99
|
}, {
|
|
71
|
-
key: "
|
|
72
|
-
value: function
|
|
73
|
-
var
|
|
100
|
+
key: "_updateRefsV1orV2",
|
|
101
|
+
value: function _updateRefsV1orV2(element, v1Func, v2Func) {
|
|
102
|
+
var elementPrefix = element.tagName.toLowerCase().split('-')[0];
|
|
103
|
+
if (elementPrefix === ddsPrefix) {
|
|
104
|
+
v1Func.bind(this)();
|
|
105
|
+
} else if (elementPrefix === c4dPrefix) {
|
|
106
|
+
v2Func.bind(this)();
|
|
107
|
+
} else {
|
|
108
|
+
throw new Error("\n Could not find sub-elements for ".concat(element.tagName.toLowerCase(), ".\n "));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Temporary method to find v1 leadspace sub-elements.
|
|
114
|
+
*/
|
|
115
|
+
}, {
|
|
116
|
+
key: "_updateLeadspaceRefsV1",
|
|
117
|
+
value: function _updateLeadspaceRefsV1() {
|
|
118
|
+
var leadspaceSearch = this._elements.leadspaceSearch;
|
|
119
|
+
this._elements.leadspaceSearchBar = leadspaceSearch.shadowRoot.querySelector(".".concat(bxPrefix, "--search-container"));
|
|
120
|
+
this._elements.leadspaceSearchInput = leadspaceSearch.querySelector("".concat(ddsPrefix, "-search-with-typeahead"));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Temporary method to find v2 leadspace sub-elements.
|
|
125
|
+
*/
|
|
126
|
+
}, {
|
|
127
|
+
key: "_updateLeadspaceRefsV2",
|
|
128
|
+
value: function _updateLeadspaceRefsV2() {
|
|
129
|
+
var leadspaceSearch = this._elements.leadspaceSearch;
|
|
130
|
+
this._elements.leadspaceSearchBar = leadspaceSearch.shadowRoot.querySelector(".".concat(prefix, "--search-container"));
|
|
131
|
+
this._elements.leadspaceSearchInput = leadspaceSearch.querySelector("".concat(c4dPrefix, "-search-with-typeahead"));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Temporary method to find v1 masthead sub-elements.
|
|
136
|
+
*/
|
|
137
|
+
}, {
|
|
138
|
+
key: "_updateMastheadRefsV1",
|
|
139
|
+
value: function _updateMastheadRefsV1() {
|
|
140
|
+
var masthead = this._elements.masthead;
|
|
141
|
+
this._elements.mastheadL0 = masthead.shadowRoot.querySelector(".".concat(bxPrefix, "--masthead__l0"));
|
|
142
|
+
this._elements.mastheadL1 = masthead.querySelector("".concat(ddsPrefix, "-masthead-l1"));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Temporary method to find v2 masthead sub-elements.
|
|
147
|
+
*/
|
|
148
|
+
}, {
|
|
149
|
+
key: "_updateMastheadRefsV2",
|
|
150
|
+
value: function _updateMastheadRefsV2() {
|
|
151
|
+
var masthead = this._elements.masthead;
|
|
152
|
+
this._elements.mastheadL0 = masthead.shadowRoot.querySelector(".".concat(prefix, "--masthead__l0"));
|
|
153
|
+
this._elements.mastheadL1 = masthead.querySelector("".concat(c4dPrefix, "-masthead-l1"));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Temporary method to find v1 table of contents sub-elements.
|
|
158
|
+
*/
|
|
159
|
+
}, {
|
|
160
|
+
key: "_updateTableOfContentsRefsV1",
|
|
161
|
+
value: function _updateTableOfContentsRefsV1() {
|
|
162
|
+
var toc = this._elements.tableOfContents;
|
|
74
163
|
var tocRoot = toc.shadowRoot;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
164
|
+
var selectors = {
|
|
165
|
+
desktop: {
|
|
166
|
+
vertical: ".".concat(ddsPrefix, "-ce--table-of-contents__items-container"),
|
|
167
|
+
horizontal: ".".concat(bxPrefix, "--tableofcontents__navbar")
|
|
168
|
+
},
|
|
169
|
+
mobile: {
|
|
170
|
+
vertical: ".".concat(bxPrefix, "--tableofcontents__sidebar"),
|
|
171
|
+
horizontal: ".".concat(bxPrefix, "--tableofcontents__navbar")
|
|
81
172
|
}
|
|
82
|
-
}
|
|
173
|
+
};
|
|
174
|
+
var viewportDimension = window.innerWidth >= gridBreakpoint ? 'desktop' : 'mobile';
|
|
175
|
+
this._elements.tableOfContentsInnerBar = tocRoot.querySelector(selectors[viewportDimension][toc.layout || 'vertical']);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Temporary method to find v2 table of contents sub-elements.
|
|
180
|
+
*/
|
|
181
|
+
}, {
|
|
182
|
+
key: "_updateTableOfContentsRefsV2",
|
|
183
|
+
value: function _updateTableOfContentsRefsV2() {
|
|
184
|
+
var toc = this._elements.tableOfContents;
|
|
185
|
+
var tocRoot = toc.shadowRoot;
|
|
186
|
+
this._elements.tableOfContentsInnerBar = tocRoot.querySelector(window.innerWidth >= gridBreakpoint && (toc === null || toc === void 0 ? void 0 : toc.layout) !== 'horizontal' ? ".".concat(c4dPrefix, "-ce--table-of-contents__items-container") : ".".concat(prefix, "--tableofcontents__navbar"));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Stores references to TOC sub-elements that are relevant to current viewport
|
|
191
|
+
* dimensions.
|
|
192
|
+
*/
|
|
193
|
+
}, {
|
|
194
|
+
key: "_updateTableOfContentsRefs",
|
|
195
|
+
value: function _updateTableOfContentsRefs() {
|
|
196
|
+
var toc = this._elements.tableOfContents;
|
|
197
|
+
this._updateRefsV1orV2(toc, this._updateTableOfContentsRefsV1, this._updateTableOfContentsRefsV2);
|
|
83
198
|
}
|
|
84
199
|
}, {
|
|
85
200
|
key: "banner",
|
|
86
201
|
set: function set(component) {
|
|
87
202
|
if (this._validateComponent(component, "".concat(c4dPrefix, "-global-banner"))) {
|
|
88
|
-
this.
|
|
89
|
-
this.hasBanner = true;
|
|
90
|
-
if (this.
|
|
91
|
-
this.
|
|
203
|
+
this._elements.banner = component;
|
|
204
|
+
this._state.hasBanner = true;
|
|
205
|
+
if (this._elements.masthead) {
|
|
206
|
+
this._elements.masthead.setAttribute('with-banner', '');
|
|
92
207
|
}
|
|
93
|
-
this.
|
|
208
|
+
this._manageStickyElements();
|
|
94
209
|
}
|
|
95
210
|
}
|
|
96
211
|
}, {
|
|
97
|
-
key: "
|
|
212
|
+
key: "leadspaceSearch",
|
|
98
213
|
set: function set(component) {
|
|
99
214
|
if (this._validateComponent(component, "".concat(c4dPrefix, "-leadspace-with-search"))) {
|
|
100
|
-
this.
|
|
101
|
-
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
104
|
-
this._leadspaceWithSearchStickyThreshold = parseInt(window.getComputedStyle(leadspaceSearchBar).paddingBottom) - 16;
|
|
105
|
-
this._calculateCumulativeHeight();
|
|
215
|
+
this._elements.leadspaceSearch = component;
|
|
216
|
+
this._updateRefsV1orV2(component, this._updateLeadspaceRefsV1, this._updateLeadspaceRefsV2);
|
|
217
|
+
this._state.leadspaceSearchThreshold = parseInt(window.getComputedStyle(this._elements.leadspaceSearchBar).paddingBottom) - 16;
|
|
218
|
+
this._manageStickyElements();
|
|
106
219
|
}
|
|
107
220
|
}
|
|
108
221
|
}, {
|
|
109
222
|
key: "localeModal",
|
|
110
223
|
set: function set(component) {
|
|
111
224
|
if (this._validateComponent(component, "".concat(c4dPrefix, "-locale-modal"))) {
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
225
|
+
this._elements.localeModal = component;
|
|
226
|
+
this._manageStickyElements();
|
|
114
227
|
}
|
|
115
228
|
}
|
|
116
229
|
}, {
|
|
117
230
|
key: "masthead",
|
|
118
231
|
set: function set(component) {
|
|
119
232
|
if (this._validateComponent(component, "".concat(c4dPrefix, "-masthead"))) {
|
|
120
|
-
this.
|
|
121
|
-
if (this.
|
|
122
|
-
this.
|
|
233
|
+
this._elements.masthead = component;
|
|
234
|
+
if (this._elements.banner) {
|
|
235
|
+
this._elements.masthead.setAttribute('with-banner', '');
|
|
123
236
|
}
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
126
|
-
this._calculateCumulativeHeight();
|
|
237
|
+
this._updateRefsV1orV2(component, this._updateMastheadRefsV1, this._updateMastheadRefsV2);
|
|
238
|
+
this._manageStickyElements();
|
|
127
239
|
}
|
|
128
240
|
}
|
|
129
241
|
}, {
|
|
130
242
|
key: "tableOfContents",
|
|
131
243
|
set: function set(component) {
|
|
132
244
|
if (this._validateComponent(component, "".concat(c4dPrefix, "-table-of-contents"))) {
|
|
133
|
-
this.
|
|
134
|
-
this.
|
|
135
|
-
this._resizeObserver.observe(this.
|
|
136
|
-
this.
|
|
245
|
+
this._elements.tableOfContents = component;
|
|
246
|
+
this._updateTableOfContentsRefs();
|
|
247
|
+
this._resizeObserver.observe(this._elements.tableOfContents);
|
|
248
|
+
this._manageStickyElements();
|
|
137
249
|
}
|
|
138
250
|
}
|
|
139
251
|
|
|
@@ -146,7 +258,7 @@ var StickyHeader = /*#__PURE__*/function () {
|
|
|
146
258
|
var _this = this;
|
|
147
259
|
if (!this._throttled) {
|
|
148
260
|
this._throttled = true;
|
|
149
|
-
this.
|
|
261
|
+
this._manageStickyElements();
|
|
150
262
|
setTimeout(function () {
|
|
151
263
|
_this._throttled = false;
|
|
152
264
|
}, 20);
|
|
@@ -155,95 +267,197 @@ var StickyHeader = /*#__PURE__*/function () {
|
|
|
155
267
|
}, {
|
|
156
268
|
key: "_handleResize",
|
|
157
269
|
value: function _handleResize() {
|
|
158
|
-
var hasBanner = this._hasBanner
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
leadspaceSearchBar =
|
|
270
|
+
var hasBanner = this._state._hasBanner;
|
|
271
|
+
var _this$_elements = this._elements,
|
|
272
|
+
masthead = _this$_elements.masthead,
|
|
273
|
+
toc = _this$_elements.tableOfContents,
|
|
274
|
+
leadspaceSearchBar = _this$_elements.leadspaceSearchBar;
|
|
163
275
|
if (toc && masthead) {
|
|
164
|
-
this.
|
|
165
|
-
if (window.innerWidth >= gridBreakpoint &&
|
|
166
|
-
masthead.style.
|
|
276
|
+
this._updateTableOfContentsRefs();
|
|
277
|
+
if (window.innerWidth >= gridBreakpoint && toc.layout !== 'horizontal' && !hasBanner) {
|
|
278
|
+
masthead.style.insetBlockStart = '0';
|
|
167
279
|
} else {
|
|
168
|
-
// This has to happen after the
|
|
169
|
-
var tocInner = this.
|
|
280
|
+
// This has to happen after the _updateTableOfContentsRefs method.
|
|
281
|
+
var tocInner = this._elements.tableOfContentsInnerBar;
|
|
170
282
|
if (masthead.offsetTop === 0) {
|
|
171
|
-
tocInner.style.
|
|
283
|
+
tocInner.style.insetBlockStart = "".concat(masthead.offsetHeight, "px");
|
|
172
284
|
}
|
|
173
285
|
}
|
|
174
|
-
this.
|
|
286
|
+
this._manageStickyElements();
|
|
175
287
|
}
|
|
176
288
|
if (leadspaceSearchBar) {
|
|
177
|
-
this.
|
|
289
|
+
this._state.leadspaceSearchThreshold = parseInt(window.getComputedStyle(leadspaceSearchBar).paddingBottom) - 16;
|
|
178
290
|
}
|
|
179
291
|
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Handles the banner given the current scroll position.
|
|
295
|
+
*/
|
|
180
296
|
}, {
|
|
181
|
-
key: "
|
|
182
|
-
value: function
|
|
183
|
-
var
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
mastheadL0 = _StickyHeader$global._mastheadL0,
|
|
188
|
-
mastheadL1 = _StickyHeader$global._mastheadL1,
|
|
189
|
-
localeModal = _StickyHeader$global._localeModal,
|
|
190
|
-
toc = _StickyHeader$global._tableOfContents,
|
|
191
|
-
tocInner = _StickyHeader$global._tableOfContentsInnerBar,
|
|
192
|
-
leadspaceSearch = _StickyHeader$global._leadspaceWithSearch,
|
|
193
|
-
leadspaceSearchBar = _StickyHeader$global._leadspaceSearchBar,
|
|
194
|
-
leadspaceSearchInput = _StickyHeader$global._leadspaceWithSearchInput,
|
|
195
|
-
leadspaceSearchThreshold = _StickyHeader$global._leadspaceWithSearchStickyThreshold;
|
|
196
|
-
var customPropertyName = this.constructor.customPropertyName;
|
|
197
|
-
if (localeModal && localeModal.hasAttribute('open')) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
var newY = window.scrollY;
|
|
201
|
-
this._lastScrollPosition = Math.max(0, newY);
|
|
297
|
+
key: "_handleBanner",
|
|
298
|
+
value: function _handleBanner() {
|
|
299
|
+
var banner = this._elements.banner;
|
|
300
|
+
var scrollPos = this._state.scrollPos;
|
|
301
|
+
this._state.cumulativeOffset += Math.max(banner.offsetHeight - scrollPos, 0);
|
|
302
|
+
}
|
|
202
303
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
* - The TOC in horizontal bar form
|
|
213
|
-
* - The leadspace with search (if no TOC)
|
|
214
|
-
*/
|
|
215
|
-
var maxScrollaway = 0;
|
|
304
|
+
/**
|
|
305
|
+
* Handles the masthead given the current scroll position.
|
|
306
|
+
*/
|
|
307
|
+
}, {
|
|
308
|
+
key: "_handleMasthead",
|
|
309
|
+
value: function _handleMasthead() {
|
|
310
|
+
var masthead = this._elements.masthead;
|
|
311
|
+
masthead.style.transition = 'none';
|
|
312
|
+
masthead.style.insetBlockStart = "".concat(this._state.cumulativeOffset, "px");
|
|
216
313
|
|
|
217
|
-
//
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
314
|
+
// Masthead always sticks, therefore always add its height.
|
|
315
|
+
this._state.cumulativeOffset += masthead.offsetHeight;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Handles the table of contents given the current scroll position.
|
|
320
|
+
*/
|
|
321
|
+
}, {
|
|
322
|
+
key: "_handleToc",
|
|
323
|
+
value: function _handleToc() {
|
|
324
|
+
var tableOfContentsInnerBar = this._elements.tableOfContentsInnerBar;
|
|
325
|
+
var tocShouldStick = this._state.tocShouldStick;
|
|
326
|
+
tableOfContentsInnerBar.style.transition = 'none';
|
|
327
|
+
tableOfContentsInnerBar.style.insetBlockStart = "".concat(this._state.cumulativeOffset, "px");
|
|
328
|
+
var tocIsStuck = Math.round(tableOfContentsInnerBar.getBoundingClientRect().top) <= this._state.cumulativeOffset + 1;
|
|
329
|
+
if (tocShouldStick && tocIsStuck) {
|
|
330
|
+
this._state.cumulativeOffset += tableOfContentsInnerBar.offsetHeight;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Handles the leadspace search given the current scroll position.
|
|
336
|
+
*/
|
|
337
|
+
}, {
|
|
338
|
+
key: "_handleLeadspaceSearch",
|
|
339
|
+
value: function _handleLeadspaceSearch() {
|
|
340
|
+
var _this$_elements2 = this._elements,
|
|
341
|
+
leadspaceSearch = _this$_elements2.leadspaceSearch,
|
|
342
|
+
leadspaceSearchBar = _this$_elements2.leadspaceSearchBar,
|
|
343
|
+
leadspaceSearchInput = _this$_elements2.leadspaceSearchInput;
|
|
344
|
+
var leadspaceSearchThreshold = this._state.leadspaceSearchThreshold;
|
|
345
|
+
var searchShouldBeSticky = leadspaceSearch.getBoundingClientRect().bottom <= leadspaceSearchThreshold;
|
|
346
|
+
var searchIsSticky = leadspaceSearch.hasAttribute('sticky-search');
|
|
347
|
+
if (searchShouldBeSticky) {
|
|
348
|
+
if (!searchIsSticky) {
|
|
349
|
+
leadspaceSearch.style.paddingBottom = "".concat(leadspaceSearchBar.offsetHeight, "px");
|
|
350
|
+
leadspaceSearch.setAttribute('sticky-search', '');
|
|
351
|
+
leadspaceSearchInput.setAttribute('large', '');
|
|
352
|
+
window.requestAnimationFrame(function () {
|
|
353
|
+
leadspaceSearchBar.style.transitionDuration = '110ms';
|
|
354
|
+
leadspaceSearchBar.style.transform = 'translateY(0)';
|
|
355
|
+
});
|
|
230
356
|
}
|
|
357
|
+
leadspaceSearchBar.style.insetBlockStart = "".concat(this._state.cumulativeOffset, "px");
|
|
358
|
+
this._state.cumulativeOffset += leadspaceSearchBar.offsetHeight;
|
|
359
|
+
} else if (searchIsSticky) {
|
|
360
|
+
leadspaceSearch.style.paddingBottom = '';
|
|
361
|
+
leadspaceSearch.removeAttribute('sticky-search');
|
|
362
|
+
leadspaceSearchInput.removeAttribute('large');
|
|
363
|
+
leadspaceSearchBar.style.transitionDuration = '';
|
|
364
|
+
leadspaceSearchBar.style.transform = '';
|
|
365
|
+
leadspaceSearchBar.style.insetBlockStart = '';
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Calculates a value matching the height of all components that are allowed
|
|
371
|
+
* to hide above the viewport.
|
|
372
|
+
*
|
|
373
|
+
* Adding an item's height to this value indicates we expect it to be hidden
|
|
374
|
+
* above the viewport.
|
|
375
|
+
*
|
|
376
|
+
* Items that stick, in order
|
|
377
|
+
* - L0
|
|
378
|
+
* - L1
|
|
379
|
+
* - The TOC in horizontal bar form
|
|
380
|
+
* - The leadspace with search (if no TOC)
|
|
381
|
+
*/
|
|
382
|
+
}, {
|
|
383
|
+
key: "_calculateMaxScrollaway",
|
|
384
|
+
value: function _calculateMaxScrollaway() {
|
|
385
|
+
var _this$_elements3 = this._elements,
|
|
386
|
+
masthead = _this$_elements3.masthead,
|
|
387
|
+
mastheadL0 = _this$_elements3.mastheadL0,
|
|
388
|
+
mastheadL1 = _this$_elements3.mastheadL1,
|
|
389
|
+
tableOfContents = _this$_elements3.tableOfContents,
|
|
390
|
+
tableOfContentsInnerBar = _this$_elements3.tableOfContentsInnerBar,
|
|
391
|
+
leadspaceSearchBar = _this$_elements3.leadspaceSearchBar;
|
|
392
|
+
|
|
393
|
+
// Reset the value before performing any further calculations.
|
|
394
|
+
this._state.maxScrollaway = 0;
|
|
395
|
+
|
|
396
|
+
// Collect conditions we may want to test for to make logic easier to read.
|
|
397
|
+
this._state.tocShouldStick = tableOfContents ? tableOfContents.layout === 'horizontal' || window.innerWidth < gridBreakpoint : false;
|
|
398
|
+
this._state.tocIsAtTop = tableOfContentsInnerBar ? tableOfContentsInnerBar.getBoundingClientRect().top <= this.height + 1 : false;
|
|
399
|
+
this._state.searchIsAtTop = leadspaceSearchBar ? leadspaceSearchBar.getBoundingClientRect().top <= this.height + 1 : false;
|
|
400
|
+
this._state.tocIsAtSearch = leadspaceSearchBar && tableOfContentsInnerBar ? tableOfContentsInnerBar.getBoundingClientRect().top <= leadspaceSearchBar.getBoundingClientRect().bottom : false;
|
|
401
|
+
this._state.mastheadL0IsActive = Boolean(masthead === null || masthead === void 0 ? void 0 : masthead.querySelector('[expanded]'));
|
|
402
|
+
this._state.mastheadL1IsActive = mastheadL1 && mastheadL1.hasAttribute('active');
|
|
403
|
+
var _this$_state = this._state,
|
|
404
|
+
tocShouldStick = _this$_state.tocShouldStick,
|
|
405
|
+
tocIsAtTop = _this$_state.tocIsAtTop,
|
|
406
|
+
searchIsAtTop = _this$_state.searchIsAtTop,
|
|
407
|
+
tocIsAtSearch = _this$_state.tocIsAtSearch,
|
|
408
|
+
mastheadL0IsActive = _this$_state.mastheadL0IsActive,
|
|
409
|
+
mastheadL1IsActive = _this$_state.mastheadL1IsActive;
|
|
410
|
+
|
|
411
|
+
// Begin calculating maxScrollAway.
|
|
412
|
+
|
|
413
|
+
// If L0 is open, lock it to the top of the page.
|
|
414
|
+
if (mastheadL0 && mastheadL0IsActive) {
|
|
415
|
+
this._state.maxScrollaway = 0;
|
|
231
416
|
}
|
|
417
|
+
// If L1 is open, lock it to the top of the page.
|
|
418
|
+
else if (mastheadL1IsActive && mastheadL0) {
|
|
419
|
+
this._state.maxScrollaway = mastheadL0.offsetHeight;
|
|
420
|
+
} else {
|
|
421
|
+
// In cases where we have both an eligible ToC and leadspace search, we want
|
|
422
|
+
// the ToC to take precedence. Scroll away leadspace search.
|
|
423
|
+
if (searchIsAtTop && tocIsAtSearch && tocShouldStick) {
|
|
424
|
+
this._state.maxScrollaway += leadspaceSearchBar.offsetHeight;
|
|
425
|
+
}
|
|
232
426
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (
|
|
237
|
-
|
|
427
|
+
// Scroll away entire masthead if either ToC or leadspace search is eligible
|
|
428
|
+
// to be the stuck element (unless L1 is open). Otherwise, scroll away the
|
|
429
|
+
// L0 if we have an L1.
|
|
430
|
+
if (searchIsAtTop || tocIsAtTop && tocShouldStick) {
|
|
431
|
+
if (masthead) {
|
|
432
|
+
this._state.maxScrollaway += masthead.offsetHeight;
|
|
433
|
+
}
|
|
434
|
+
} else if (masthead && mastheadL0 && mastheadL1) {
|
|
435
|
+
this._state.maxScrollaway += mastheadL0.offsetHeight;
|
|
238
436
|
}
|
|
239
437
|
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Positions sticky elements. Does so by checking the scroll position and where
|
|
442
|
+
* tracked elements are in relation to it, then applying the correct styles to
|
|
443
|
+
* each element in succession to ensure that only one element is stuck to the
|
|
444
|
+
* top of the page, and all other elements that have been scrolled past can be
|
|
445
|
+
* revealed when scrolling back up.
|
|
446
|
+
*/
|
|
447
|
+
}, {
|
|
448
|
+
key: "_positionElements",
|
|
449
|
+
value: function _positionElements() {
|
|
450
|
+
var _this$_elements4 = this._elements,
|
|
451
|
+
banner = _this$_elements4.banner,
|
|
452
|
+
masthead = _this$_elements4.masthead,
|
|
453
|
+
tocInner = _this$_elements4.tableOfContentsInnerBar,
|
|
454
|
+
leadspaceSearchBar = _this$_elements4.leadspaceSearchBar;
|
|
455
|
+
var oldY = this._state.scrollPosPrevious;
|
|
240
456
|
|
|
241
457
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* This value is equal to the difference between the previous scrollY and
|
|
246
|
-
* the current scrollY values, but is positively and negatively limited.
|
|
458
|
+
* Reset to a value that is equal to the difference between the previous
|
|
459
|
+
* scrollY and the current scrollY values, but is positively and negatively
|
|
460
|
+
* limited.
|
|
247
461
|
*
|
|
248
462
|
* Positive limit: 0
|
|
249
463
|
* all elements visible, starting at the top of the viewport.
|
|
@@ -253,55 +467,58 @@ var StickyHeader = /*#__PURE__*/function () {
|
|
|
253
467
|
* with the elements that should be visible starting at the top of the
|
|
254
468
|
* viewport.
|
|
255
469
|
*/
|
|
256
|
-
|
|
470
|
+
this._state.cumulativeOffset = Math.max(Math.min((masthead ? masthead.offsetTop : 0) + oldY - this._state.scrollPos, 0), this._state.maxScrollaway * -1);
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Handle each potentially sticky element in the order we expect them to
|
|
474
|
+
* appear on the page. Important to do this sequentially for
|
|
475
|
+
* cumulativeOffset to be correctly calculated by the time each of these
|
|
476
|
+
* methods accesses it.
|
|
477
|
+
*
|
|
478
|
+
* To-do: One idea for improving this so the execution order doesn't matter
|
|
479
|
+
* is to collect our elements into an array ordered by document position,
|
|
480
|
+
* then loop over that array and execute a corresponding handler method.
|
|
481
|
+
*/
|
|
257
482
|
if (banner) {
|
|
258
|
-
|
|
483
|
+
this._handleBanner();
|
|
259
484
|
}
|
|
260
485
|
if (masthead) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
486
|
+
this._handleMasthead();
|
|
487
|
+
}
|
|
488
|
+
if (leadspaceSearchBar) {
|
|
489
|
+
this._handleLeadspaceSearch();
|
|
264
490
|
}
|
|
265
491
|
if (tocInner) {
|
|
266
|
-
|
|
267
|
-
tocInner.style.top = "".concat(cumulativeOffset, "px");
|
|
268
|
-
tocShouldStick = toc.layout === 'horizontal' || window.innerWidth < gridBreakpoint;
|
|
269
|
-
var tocIsStuck = Math.round(tocInner.getBoundingClientRect().top) <= cumulativeOffset + 1;
|
|
270
|
-
if (tocShouldStick && tocIsStuck) {
|
|
271
|
-
cumulativeOffset += tocInner.offsetHeight;
|
|
272
|
-
}
|
|
492
|
+
this._handleToc();
|
|
273
493
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (!searchShouldBeSticky && searchIsSticky) {
|
|
291
|
-
leadspaceSearch.removeAttribute('sticky-search');
|
|
292
|
-
leadspaceSearch.style.paddingBottom = '';
|
|
293
|
-
leadspaceSearchBar.style.top = '';
|
|
294
|
-
leadspaceSearchBar.style.transitionDuration = '';
|
|
295
|
-
leadspaceSearchBar.style.transform = '';
|
|
296
|
-
leadspaceSearchInput.removeAttribute('large');
|
|
297
|
-
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Manages which elements are stuck and where they are positioned. We should
|
|
498
|
+
* only have one element stuck to the top of the viewport as the page scrolls
|
|
499
|
+
* down.
|
|
500
|
+
*/
|
|
501
|
+
}, {
|
|
502
|
+
key: "_manageStickyElements",
|
|
503
|
+
value: function _manageStickyElements() {
|
|
504
|
+
var localeModal = this._elements.localeModal;
|
|
505
|
+
var scrollPosPrevious = this._state.scrollPos;
|
|
506
|
+
|
|
507
|
+
// Exit early if locale modal is open.
|
|
508
|
+
if (localeModal && localeModal.hasAttribute('open')) {
|
|
509
|
+
return;
|
|
298
510
|
}
|
|
299
511
|
|
|
300
|
-
//
|
|
301
|
-
this.
|
|
512
|
+
// Store scroll positions.
|
|
513
|
+
this._state.scrollPosPrevious = scrollPosPrevious;
|
|
514
|
+
this._state.scrollPos = Math.max(0, window.scrollY);
|
|
515
|
+
|
|
516
|
+
// Given the current state, calculate how elements should be positioned.
|
|
517
|
+
this._calculateMaxScrollaway();
|
|
518
|
+
this._positionElements();
|
|
302
519
|
|
|
303
520
|
// Set custom property for use in stylesheets
|
|
304
|
-
root.document.documentElement.style.setProperty(customPropertyName, "".concat(this.
|
|
521
|
+
root.document.documentElement.style.setProperty(this.constructor.customPropertyName, "".concat(this._state.cumulativeOffset, "px"));
|
|
305
522
|
}
|
|
306
523
|
}], [{
|
|
307
524
|
key: "global",
|