@odopod/odo-reveal
Version:
Reveal elements on the page as they come into view.
3 lines (2 loc) • 2.54 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@odopod/odo-device"),require("@odopod/odo-viewport"),require("@odopod/odo-helpers")):"function"==typeof define&&define.amd?define(["@odopod/odo-device","@odopod/odo-viewport","@odopod/odo-helpers"],t):e.OdoReveal=t(e.OdoDevice,e.OdoViewport,e.OdoHelpers)}(this,function(e,t,o){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e,t=t&&t.hasOwnProperty("default")?t.default:t;var i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function n(e){var r=this;i(this,n),this.element=e,this.images=this._getDependentImages(),this._numImages=this.images.length,this._loadedImages=0,this._imageCompleteHandler=this._imageComplete.bind(this),this._ready=new Promise(function(e){r._resolve=e}),this._numImages>0?this.images.forEach(function(e){e.addEventListener("load",r._imageCompleteHandler),e.addEventListener("error",r._imageCompleteHandler)}):this._resolve(),n.HAS_SCROLL_ANIMATION?this.id=t.add({element:e,threshold:o.getPercentageOption(e.getAttribute("data-threshold"),"25%"),enter:this._enteredView.bind(this)}):this._show()}return n.prototype._getDependentImages=function(){return Array.from(this.element.querySelectorAll("img")).filter(function(e){return null===e.closest("."+n.ClassName.IGNORE)})},n.prototype._enteredView=function(){this._ready.then(this._show.bind(this))},n.prototype._show=function(){var t=this;this.element.classList.add(n.ClassName.IN);var i="."+n.ClassName.TARGET;Array.from(this.element.querySelectorAll(i)).forEach(function(i){o.onTransitionEnd(i,t._handleShown,null,e.Dom.TRANSFORM)}),this.dispose()},n.prototype._handleShown=function(e){e.target.classList.add(n.ClassName.DONE)},n.prototype._imageComplete=function(){this._loadedImages+=1,this._loadedImages===this._numImages&&this._resolve()},n.prototype.dispose=function(){var e=this;t.remove(this.id),this.images.forEach(function(t){t.removeEventListener("load",e._imageCompleteHandler),t.removeEventListener("error",e._imageCompleteHandler)}),this.images=null,this.element=null},n.initializeAll=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document;return Array.from(e.querySelectorAll(".odo-reveal"),function(e){return new n(e)})},n}();return n.HAS_SCROLL_ANIMATION=!o.isNativeAndroid(navigator.userAgent),n.ClassName={TARGET:"odo-reveal__target",IN:"odo-reveal--shown",DONE:"odo-reveal--done",IGNORE:"odo-reveal__ignore"},n});
//# sourceMappingURL=odo-reveal.min.js.map