all files / library/src/instance/functions/ initialize.js

3.23% Statements 1/31
0% Branches 0/14
0% Functions 0/4
3.23% Lines 1/31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73                                                                                                                                               
import { each } from '../../utils/generic'
 
 
export default function initialize () {
	var this$1 = this;
 
 
	var activeContainerIds = []
	var activeSequenceIds = []
 
	each(this.store.elements, function (element) {
		if (activeContainerIds.indexOf(element.containerId) === -1) {
			activeContainerIds.push(element.containerId)
		}
		if (element.sequence && activeSequenceIds.indexOf(element.sequence.id) === -1) {
			activeSequenceIds.push(element.sequence.id)
		}
 
		var styles = [element.styles.inline]
 
		if (element.visible) {
			styles.push(element.styles.opacity.computed)
			styles.push(element.styles.transform.generated.final)
		} else {
			styles.push(element.styles.opacity.generated)
			styles.push(element.styles.transform.generated.initial)
		}
 
		element.node.setAttribute('style', styles.join(' '))
	})
 
	/**
	 * Remove unused sequences.
	 */
	each(this.store.sequences, function (sequence) {
		if (activeSequenceIds.indexOf(sequence.id) === -1) {
			delete this$1.store.sequences[sequence.id]
		}
	})
 
	each(this.store.containers, function (container) {
 
		/**
		 * Remove unused containers.
		 */
		if (activeContainerIds.indexOf(container.id) === -1) {
			container.node.removeEventListener('scroll', this$1.delegate)
			container.node.removeEventListener('resize', this$1.delegate)
			delete this$1.store.containers[container.id]
 
		/**
		 * Bind event listeners
		 */
		} else if (container.node === document.documentElement) {
			window.addEventListener('scroll', this$1.delegate)
			window.addEventListener('resize', this$1.delegate)
		} else {
			container.node.addEventListener('scroll', this$1.delegate)
			container.node.addEventListener('resize', this$1.delegate)
		}
	})
 
	/**
	 * Manually invoke delegate once to capture
	 * element and container dimensions, container
	 * scroll position, and trigger any valid reveals
	 */
	this.delegate()
 
	this.initTimeout = null
}