@brandocms/jupiter 3.52.0 → 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 +41 -20
package/package.json
CHANGED
|
@@ -108,13 +108,6 @@ export default class Moonwalk {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
initialize(container = document.body) {
|
|
111
|
-
if (this.opts.clearMoonwalkOnAnchors) {
|
|
112
|
-
if (window.location.hash) {
|
|
113
|
-
this.removeAllWalks()
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
111
|
if (this.opts.clearNestedSections) {
|
|
119
112
|
container
|
|
120
113
|
.querySelectorAll('[data-moonwalk-section] [data-moonwalk-section]')
|
|
@@ -127,6 +120,12 @@ export default class Moonwalk {
|
|
|
127
120
|
.forEach(ms => ms.removeAttribute('data-moonwalk'))
|
|
128
121
|
}
|
|
129
122
|
|
|
123
|
+
if (this.opts.clearMoonwalkOnAnchors) {
|
|
124
|
+
if (window.location.hash) {
|
|
125
|
+
this.walkToThisPoint(window.location.hash)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
130
129
|
this.addClass()
|
|
131
130
|
this.sections = this.initializeSections(container)
|
|
132
131
|
this.runs = this.initializeRuns(container)
|
|
@@ -151,16 +150,43 @@ export default class Moonwalk {
|
|
|
151
150
|
document.documentElement.classList.add('moonwalk')
|
|
152
151
|
}
|
|
153
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
|
+
|
|
154
185
|
/**
|
|
155
186
|
* Remove all moonwalks. Useful for clients who prefer reduced motion
|
|
156
187
|
*/
|
|
157
|
-
removeAllWalks(container = document.body) {
|
|
158
|
-
const keys = [
|
|
159
|
-
'data-moonwalk',
|
|
160
|
-
'data-moonwalk-run',
|
|
161
|
-
'data-moonwalk-section',
|
|
162
|
-
'data-moonwalk-children'
|
|
163
|
-
]
|
|
188
|
+
removeAllWalks(container = document.body, beforeEl = nil) {
|
|
189
|
+
const keys = ['data-moonwalk', 'data-moonwalk-section', 'data-moonwalk-children']
|
|
164
190
|
keys.forEach(key => {
|
|
165
191
|
const elems = container.querySelectorAll(`[${key}]`)
|
|
166
192
|
Array.from(elems).forEach(el => el.removeAttribute(key))
|
|
@@ -169,12 +195,7 @@ export default class Moonwalk {
|
|
|
169
195
|
}
|
|
170
196
|
|
|
171
197
|
removeFor(container = document.body, selector) {
|
|
172
|
-
const keys = [
|
|
173
|
-
'data-moonwalk',
|
|
174
|
-
'data-moonwalk-run',
|
|
175
|
-
'data-moonwalk-section',
|
|
176
|
-
'data-moonwalk-children'
|
|
177
|
-
]
|
|
198
|
+
const keys = ['data-moonwalk', 'data-moonwalk-section', 'data-moonwalk-children']
|
|
178
199
|
keys.forEach(key => {
|
|
179
200
|
const elems = container.querySelectorAll(`${selector}[${key}]`)
|
|
180
201
|
Array.from(elems).forEach(el => el.removeAttribute(key))
|