all files / lib/src/instance/ constructor.js

93.18% Statements 41/44
83.33% Branches 15/18
77.78% Functions 7/9
97.3% Lines 36/37
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91                                  15× 15×           15×     11× 11×           11×       19×                                              
import defaults from './defaults'
import noop from './noop'
 
import clean from './methods/clean'
import destroy from './methods/destroy'
import reveal from './methods/reveal'
import sync from './methods/sync'
 
import delegate from './functions/delegate'
 
import { isMobile, transformSupported, transitionSupported } from '../utils/browser'
import { getNode, logger } from '../utils/core'
import { deepAssign } from '../utils/generic'
 
import { version } from '../../package.json'
 
 
export default function ScrollReveal (options) {
	var this$1 = this;
	if ( options === void 0 ) options = {};
 
 
	/**
	 * Support instantiation without the `new` keyword.
	 */
	if (typeof this === 'undefined' || Object.getPrototypeOf(this) !== ScrollReveal.prototype) {
		return new ScrollReveal(options)
	}
 
	var _debug = false
	Object.defineProperty(this, 'debug', {
		get: function () { return _debug; },
		set: function (value) {
			if (typeof value === 'boolean') { _debug = value }
		},
	})
 
	if (!ScrollReveal.isSupported()) {
		logger.call(this, 'Instantiation aborted.', 'This browser is not supported.')
		return noop
	}
 
	try {
		Object.defineProperty(this, 'defaults', {
			get: (function () {
				var config = {}
				deepAssign(config, defaults, options)
				return function () { return config; }
			})(),
		})
	} catch (e) {
		logger.call(this, 'Instantiation failed.', 'Invalid configuration.', e.message)
		return noop
	}
 
	try {
		var container = getNode(this.defaults.container)
		if (!container) {
			throw new Error('Invalid container.')
		}
	} catch (e) {
		logger.call(this, 'Instantiation failed.', e.message)
		return noop
	}
 
	Eif (this.defaults.mobile === isMobile() || this.defaults.desktop === !isMobile()) {
		document.documentElement.classList.add('sr')
	}
 
	this.store = {
		containers: {},
		elements: {},
		history: [],
		sequences: {},
	}
 
	this.pristine = true
 
	Object.defineProperty(this, 'delegate', { get: function () { return delegate.bind(this$1); } })
	Object.defineProperty(this, 'version', { get: function () { return version; } })
	Object.defineProperty(this, 'noop', { get: function () { return false; } })
}
 
ScrollReveal.isSupported = function () { return transformSupported() && transitionSupported(); }
 
ScrollReveal.prototype.clean = clean
ScrollReveal.prototype.destroy = destroy
ScrollReveal.prototype.reveal = reveal
ScrollReveal.prototype.sync = sync