@brandocms/jupiter 3.51.1 → 3.53.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/package.json +1 -1
- package/src/modules/Moonwalk/index.js +52 -20
package/package.json
CHANGED
|
@@ -42,6 +42,11 @@ const DEFAULT_OPTIONS = {
|
|
|
42
42
|
*/
|
|
43
43
|
clearNestedSections: true,
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Clear out all nested [data-moonwalk]s
|
|
47
|
+
*/
|
|
48
|
+
clearNestedWalks: true,
|
|
49
|
+
|
|
45
50
|
/**
|
|
46
51
|
* If page is linked with an anchor, remove moonwalk for the page
|
|
47
52
|
*/
|
|
@@ -103,19 +108,24 @@ export default class Moonwalk {
|
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
initialize(container = document.body) {
|
|
106
|
-
if (this.opts.clearMoonwalkOnAnchors) {
|
|
107
|
-
if (window.location.hash) {
|
|
108
|
-
this.removeAllWalks()
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
111
|
if (this.opts.clearNestedSections) {
|
|
114
112
|
container
|
|
115
113
|
.querySelectorAll('[data-moonwalk-section] [data-moonwalk-section]')
|
|
116
114
|
.forEach(ms => ms.removeAttribute('data-moonwalk-section'))
|
|
117
115
|
}
|
|
118
116
|
|
|
117
|
+
if (this.opts.clearNestedWalks) {
|
|
118
|
+
container
|
|
119
|
+
.querySelectorAll('[data-moonwalk] [data-moonwalk]')
|
|
120
|
+
.forEach(ms => ms.removeAttribute('data-moonwalk'))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (this.opts.clearMoonwalkOnAnchors) {
|
|
124
|
+
if (window.location.hash) {
|
|
125
|
+
this.walkToThisPoint(window.location.hash)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
119
129
|
this.addClass()
|
|
120
130
|
this.sections = this.initializeSections(container)
|
|
121
131
|
this.runs = this.initializeRuns(container)
|
|
@@ -140,16 +150,43 @@ export default class Moonwalk {
|
|
|
140
150
|
document.documentElement.classList.add('moonwalk')
|
|
141
151
|
}
|
|
142
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Matching moonwalk elements before the element matching the hash should be set to visible
|
|
155
|
+
* by setting the `data-moonwalked` attribute on `data-moonwalk` elements and
|
|
156
|
+
* `data-moonwalk-section-ready` on `data-moonwalk-section` elements.
|
|
157
|
+
*/
|
|
158
|
+
walkToThisPoint(hash) {
|
|
159
|
+
// Find the target element using the hash
|
|
160
|
+
const targetElement = document.querySelector(hash)
|
|
161
|
+
if (!targetElement) return // Exit if the element is not found
|
|
162
|
+
|
|
163
|
+
// Get all elements with the 'data-moonwalk' attribute
|
|
164
|
+
const moonwalkElements = document.querySelectorAll('[data-moonwalk]')
|
|
165
|
+
moonwalkElements.forEach(el => {
|
|
166
|
+
const position = el.compareDocumentPosition(targetElement)
|
|
167
|
+
// Check if 'el' comes before 'targetElement' or is the same element
|
|
168
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING || el === targetElement) {
|
|
169
|
+
el.setAttribute('data-moonwalked', '')
|
|
170
|
+
el.classList.add('moonwalked')
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
// Get all elements with the 'data-moonwalk-section' attribute
|
|
175
|
+
const moonwalkSectionElements = document.querySelectorAll('[data-moonwalk-section]')
|
|
176
|
+
moonwalkSectionElements.forEach(el => {
|
|
177
|
+
const position = el.compareDocumentPosition(targetElement)
|
|
178
|
+
// Check if 'el' comes before 'targetElement' or is the same element
|
|
179
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING || el === targetElement) {
|
|
180
|
+
el.setAttribute('data-moonwalk-section-ready', '')
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
143
185
|
/**
|
|
144
186
|
* Remove all moonwalks. Useful for clients who prefer reduced motion
|
|
145
187
|
*/
|
|
146
|
-
removeAllWalks(container = document.body) {
|
|
147
|
-
const keys = [
|
|
148
|
-
'data-moonwalk',
|
|
149
|
-
'data-moonwalk-run',
|
|
150
|
-
'data-moonwalk-section',
|
|
151
|
-
'data-moonwalk-children'
|
|
152
|
-
]
|
|
188
|
+
removeAllWalks(container = document.body, beforeEl = nil) {
|
|
189
|
+
const keys = ['data-moonwalk', 'data-moonwalk-section', 'data-moonwalk-children']
|
|
153
190
|
keys.forEach(key => {
|
|
154
191
|
const elems = container.querySelectorAll(`[${key}]`)
|
|
155
192
|
Array.from(elems).forEach(el => el.removeAttribute(key))
|
|
@@ -158,12 +195,7 @@ export default class Moonwalk {
|
|
|
158
195
|
}
|
|
159
196
|
|
|
160
197
|
removeFor(container = document.body, selector) {
|
|
161
|
-
const keys = [
|
|
162
|
-
'data-moonwalk',
|
|
163
|
-
'data-moonwalk-run',
|
|
164
|
-
'data-moonwalk-section',
|
|
165
|
-
'data-moonwalk-children'
|
|
166
|
-
]
|
|
198
|
+
const keys = ['data-moonwalk', 'data-moonwalk-section', 'data-moonwalk-children']
|
|
167
199
|
keys.forEach(key => {
|
|
168
200
|
const elems = container.querySelectorAll(`${selector}[${key}]`)
|
|
169
201
|
Array.from(elems).forEach(el => el.removeAttribute(key))
|