MCPcopy
hub / github.com/jlmakes/scrollreveal / reveal

Function reveal

src/instance/methods/reveal.js:13–138  ·  view source on GitHub ↗
(target, options = {}, syncing = false)

Source from the content-addressed store, hash-verified

11import clean from '../methods/clean'
12
13export default function reveal(target, options = {}, syncing = false) {
14 const containerBuffer = []
15 let sequence
16 let interval = options.interval || defaults.interval
17
18 try {
19 if (interval) {
20 sequence = new Sequence(interval)
21 }
22
23 const nodes = tealight(target)
24 if (!nodes.length) {
25 throw new Error('Invalid reveal target.')
26 }
27
28 const elements = nodes.reduce((elementBuffer, elementNode) => {
29 const element = {}
30 const existingId = elementNode.getAttribute('data-sr-id')
31
32 if (existingId) {
33 deepAssign(element, this.store.elements[existingId])
34
35 /**
36 * In order to prevent previously generated styles
37 * from throwing off the new styles, the style tag
38 * has to be reverted to its pre-reveal state.
39 */
40 applyStyle(element.node, element.styles.inline.computed)
41 } else {
42 element.id = nextUniqueId()
43 element.node = elementNode
44 element.seen = false
45 element.revealed = false
46 element.visible = false
47 }
48
49 const config = deepAssign({}, element.config || this.defaults, options)
50
51 if ((!config.mobile && isMobile()) || (!config.desktop && !isMobile())) {
52 if (existingId) {
53 clean.call(this, element)
54 }
55 return elementBuffer // skip elements that are disabled
56 }
57
58 const containerNode = tealight(config.container)[0]
59 if (!containerNode) {
60 throw new Error('Invalid container.')
61 }
62 if (!containerNode.contains(elementNode)) {
63 return elementBuffer // skip elements found outside the container
64 }
65
66 let containerId
67 {
68 containerId = getContainerId(
69 containerNode,
70 containerBuffer,

Callers

nothing calls this directly

Calls 6

applyStyleFunction · 0.90
deepAssignFunction · 0.85
isMobileFunction · 0.85
getContainerIdFunction · 0.85
styleFunction · 0.85
eachFunction · 0.85

Tested by

no test coverage detected