blob: b1e9591692eb74e96c9684f8e39299d4367f1ed0 [file] [log] [blame]
/**
* @module RD Parallax
* @author Evgeniy Gusarov
* @see https://ua.linkedin.com/pub/evgeniy-gusarov/8a/a40/54a
* @version 3.5.0
*/
(function(){(function(n,l,e){var u,w,x,p,m,h,v,r;h=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);x=/Chrome/.test(navigator.userAgent);r=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)||/Safari/.test(navigator.userAgent)&&/Apple Computer/.test(navigator.vendor);p=h&&/crios/i.test(navigator.userAgent);v=/iPhone|iPad|iPod/i.test(navigator.userAgent)&&!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/);m=-1!==navigator.appVersion.indexOf("MSIE")||
0<navigator.appVersion.indexOf("Trident/");w=null!=l.body.classList;(function(){var h,m,l,b,a;m=0;a=["ms","moz","webkit","o"];h=0;for(l=a.length;h<l;h++)b=a[h],e.requestAnimationFrame=e[b+"RequestAnimationFrame"],e.cancelAnimationFrame=e[b+"CancelAnimationFrame"]||e[b+"CancelRequestAnimationFrame"];e.requestAnimationFrame||(e.requestAnimationFrame=function(a,c){var d,b,g;d=(new Date).getTime();g=Math.max(0,16-(d-m));b=e.setTimeout(function(){a(d+g)},g);m=d+g;return b});if(!e.cancelAnimationFrame)return e.cancelAnimationFrame=
function(a){return clearTimeout(a)}});u=function(){function t(b){this.options=n.extend(!0,{},this.Defaults,b);this.scenes=[];this.initialize();this.scrollY=e.scrollY||e.pageYOffset;this.lastScrollY=-1;this.inputFocus=!1}var y,u;y=function(){function b(a,f,c,d,b,g,k){this.amend=r||m||h?60:0;this.element=a;this.aliases=f;this.type=a.getAttribute("data-type")||"html";"html"===this.type&&(this.holder=this.createHolder());this.direction="normal"===a.getAttribute("data-direction")||null==a.getAttribute("data-direction")?
1:-1;this.fade="true"===a.getAttribute("data-fade");this.blur="true"===a.getAttribute("data-blur");this.boundTo=l.querySelector(a.getAttribute("data-bound-to"));"media"===this.type&&(this.url=a.getAttribute("data-url"));this.responsive=this.getResponsiveOptions();this.element.style.position=!m&&!h||p?"absolute":"fixed";switch(this.type){case "media":null!=this.url&&(this.element.style["background-image"]="url("+this.url+")");break;case "html":m&&h&&(this.element.style["z-index"]=1)}this.refresh(c,
d,b,g,k)}b.prototype.refresh=function(a,f,c,d,b){this.speed=this.getOption("speed",a)||0;this.offset=this.getOption("offset",a)||0;!m&&!h||p||(this.element.style.position=b?"fixed":"absolute");switch(this.type){case "media":return this.offsetHeight=this.getMediaHeight(f,d,this.speed,this.direction),this.element.style.height=this.offsetHeight+"px";case "html":this.element.style.width=this.holder.offsetWidth+"px";this.offsetHeight=this.element.offsetHeight;this.holder.style.height=this.offsetHeight+
"px";if(!m&&!h||p)return this.element.style.left=0,this.element.style.top=0;if(b)return this.element.style.left=this.getOffset(this.holder).left+"px",this.element.style.top=this.getOffset(this.holder).top-c+"px",this.holder.style.position="static";this.element.style.left=0;this.element.style.top=0;return this.holder.style.position="relative";case "custom":return this.offsetHeight=this.element.offsetHeight}};b.prototype.createHolder=function(){var a;a=l.createElement("div");w?a.classList.add("rd-parallax-layer-holder"):
a.className="rd-parallax-layer-holder";this.element.parentNode.insertBefore(a,this.element);a.appendChild(this.element);if(!m&&!h||p)a.style.position="relative";return a};b.prototype.getOption=function(a,f){var c,d;for(c in this.responsive)c<=f&&(d=c);return this.responsive[d][a]};b.prototype.getResponsiveOptions=function(){var a,f,c,d,b,g,k,e,h;e={};k=[];f=[];d=this.aliases;for(c in d)a=d[c],k.push(c),f.push(a);c=d=0;for(b=k.length;d<b;c=++d)for(g=k[c],e[g]={};-1<=(a=c);)!e[g].speed&&(h=this.element.getAttribute("data"+
f[a]+"speed"))&&(e[g].speed=this.getSpeed(h)),!e[g].offset&&(h=this.element.getAttribute("data"+f[a]+"offset"))&&(e[g].offset=parseInt(h)),c--;return e};b.prototype.fuse=function(a,f){var c,d,b;c=this.getOffset(this.element).top+this.element.getBoundingClientRect().top;d=a+f/2;c+=this.offsetHeight/2;b=f/6;d+b>c&&d-b<c?this.element.style.opacity=1:(d=d-b<c?1+(d+b-c)/f/3*10:1-(d-b-c)/f/3*10,this.element.style.opacity=0>d?0:1<d?1:d.toFixed(2))};b.prototype.move=function(a,f,c,d,b,g,e,q,l){e?(e=!m&&!h||
"html"===this.type&&l||p?this.speed*this.direction:this.speed*this.direction-1,f=this.offsetHeight,null!=q?g=(d+c-(q+c))/(c-b):"media"!==this.type?d<c||d>g-c?(g=d<c?d/(c-b):(d+c-g)/(c-b),isFinite(g)||(g=0)):g=.5:g=.5,a=p?(b-f)/2+(c-b)*g*e+this.offset:-(d-a)*e+(b-f)/2+(c-b)*g*e+this.offset,(m||h)&&null!=q&&(this.element.style.top=d-q+"px"),v&&l&&(a+=d),r&&(this.element.style["-webkit-transform"]="translate3d(0,"+a+"px,0)"),this.element.style.transform="translate3d(0,"+a+"px,0)"):(r&&(this.element.style["-webkit-transform"]=
"translate3d(0,0,0)"),this.element.style.transform="translate3d(0,0,0)")};b.prototype.getSpeed=function(a){return Math.min(Math.max(parseFloat(a),0),2)};b.prototype.getMediaHeight=function(a,b,c,d){return b+(-1===d?(b+a)*c:0)+(1>=c?Math.abs(a-b)*c:a*c)+2*this.amend};b.prototype.getOffset=function(a){a=a.getBoundingClientRect();return{top:a.top+(e.scrollY||e.pageYOffset),left:a.left+(e.scrollX||e.pageXOffset)}};return b}();u=function(){function b(a,b,c,d){this.amend=r?60:0;this.element=a;this.aliases=
b;this.on=!0;this.agent=l.querySelector(a.getAttribute("data-agent"));this.anchor=this.findAnchor();this.canvas=this.createCanvas();this.layers=this.createLayers(c);this.fitTo=this.getFitElement();this.responsive=this.getResponsiveOptions();this.refresh(c,d)}b.prototype.getFitElement=function(){var a;return null!=(a=this.element.getAttribute("data-fit-to"))?"parent"===a?this.element.parentNode:l.querySelector(a):null};b.prototype.findAnchor=function(){var a;for(a=this.element.parentNode;null!=a&&
a!==l;){if(this.isTransformed.call(a))return a;a=a.parentNode}return null};b.prototype.createCanvas=function(){var a;a=l.createElement("div");w?a.classList.add("rd-parallax-inner"):a.className="rd-parallax-inner";for(this.element.appendChild(a);this.element.firstChild!==a;)a.appendChild(this.element.firstChild);this.element.style.position="relative";this.element.style.overflow="hidden";m||h?(a.style.position="absolute",a.style.clip="rect(0, auto, auto, 0)",a.style.transform=m?"translate3d(0,0,0)":
"none"):a.style.position="fixed";a.style.left=this.offsetLeft+"px";a.style.top=0;r&&(a.style["margin-top"]="-"+this.amend+"px",a.style.padding=this.amend+"px 0",this.element.style["z-index"]=0);return a};b.prototype.getOption=function(a,b){var c,d;for(c in this.responsive)c<=b&&(d=c);return this.responsive[d][a]};b.prototype.getResponsiveOptions=function(){var a,b,c,d,e,g,k,h,l;h={};k=[];b=[];d=this.aliases;for(c in d)a=d[c],k.push(c),b.push(a);c=d=0;for(e=k.length;d<e;c=++d)for(g=k[c],h[g]={};-1<=
(a=c);)h[g].on||null==(l=this.element.getAttribute("data"+b[a]+"on"))||(h[g].on="false"!==l),null==h[g].on&&0===a&&(h[g].on=!0),c--;return h};b.prototype.createLayers=function(a,b){var c,d,e,g,k;d=n(this.element).find(".rd-parallax-layer").get();g=[];c=e=0;for(k=d.length;e<k;c=++e)c=d[c],g.push(new y(c,this.aliases,a,b,this.offsetTop,this.offsetHeight,this.on));return g};b.prototype.move=function(a){a=null!=this.anchor?this.positionTop:this.offsetTop-a;r&&(this.canvas.style["-webkit-transform"]="translate3d(0,"+
a+"px,0)");return this.canvas.style.transform="translate3d(0,"+a+"px,0)"};b.prototype.refresh=function(a,b){var c,d,e,g,k;g=[];this.on=this.getOption("on",a);this.offsetTop=this.getOffset(this.element).top;this.offsetLeft=this.getOffset(this.element).left;this.width=this.element.offsetWidth;this.canvas.style.width=this.width+"px";null!=this.anchor&&(this.positionTop=this.element.offsetTop);null!=this.agent?(this.agentOffset=this.getOffset(this.agent).top,this.agentHeight=this.agent.offsetHeight):
this.agentOffset=this.agentHeight=null;k=this.layers;c=0;for(e=k.length;c<e;c++)d=k[c],"media"===d.type?g.push(d):d.refresh(a,b,this.offsetTop,this.offsetHeight,this.on);this.offsetHeight=this.canvas.offsetHeight-2*this.amend;this.element.style.height=this.offsetHeight+"px";c=0;for(e=g.length;c<e;c++)d=g[c],d.refresh(a,b,this.offsetTop,this.offsetHeight,this.on)};b.prototype.update=function(a,b,c,d,e){var g,k,l,n,p,r,t;t=this.offsetTop;r=this.offsetHeight;m||h||this.move(a);n=this.layers;p=[];g=0;
for(l=n.length;g<l;g++)k=n[g],k.move(a,b,c,t,r,d,this.on,this.agentOffset,e),k.fade&&!h?p.push(k.fuse(t,r)):p.push(void 0);return p};b.prototype.isTransformed=function(){var a,b,c;c={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};for(a in c)c.hasOwnProperty(a)&&null!=this.style[a]&&(b=e.getComputedStyle(this).getPropertyValue(c[a]));return null!=b&&0<b.length&&"none"!==b?!0:!1};b.prototype.getOffset=function(a){a=
a.getBoundingClientRect();return{top:a.top+(e.scrollY||e.pageYOffset),left:a.left+(e.scrollX||e.pageYOffset)}};return b}();t.prototype.Defaults={selector:".rd-parallax",screenAliases:{0:"-",480:"-xs-",768:"-sm-",992:"-md-",1200:"-lg-",1920:"-xl-",2560:"-xxl-"}};t.prototype.initialize=function(){var b,a,f,c,d,h,g;b=this;f=l.querySelectorAll(b.options.selector);g=e.innerWidth;h=e.innerHeight;a=c=0;for(d=f.length;c<d;a=++c)a=f[a],b.scenes.push(new u(a,b.options.screenAliases,g,h));n(e).on("resize",n.proxy(b.resize,
b));if(v)n("input").on("focusin focus",function(a){a.preventDefault();b.activeOffset=n(this).offset().top;return e.scrollTo(e.scrollX||e.pageXOffset,b.activeOffset-this.offsetHeight-100)});n(e).trigger("resize");b.update()};t.prototype.resize=function(){var b,a,f,c;if((b=e.innerWidth)!==this.windowWidth||!h){this.windowWidth=b;this.windowHeight=e.innerHeight;this.documentHeight=l.body.offsetHeight;f=this.scenes;b=0;for(a=f.length;b<a;b++)c=f[b],c.refresh(this.windowWidth,this.windowHeight);return this.update(!0)}};
t.prototype.update=function(b){var a,f,c,d,m,g,k,q,n,p;f=this;b||requestAnimationFrame(function(){f.update()});q=e.scrollY||e.pageYOffset;v&&null!=(a=l.activeElement)&&(a.tagName.match(/(input)|(select)|(textarea)/i)?(f.activeElement=a,f.inputFocus=!0):(f.activeElement=null,f.inputFocus=!1,b=!0));h&&x&&(a=e.innerHeight-f.windowHeight,f.deltaHeight=a,q-=f.deltaHeight);if((q!==f.lastScrollY||b)&&!f.isActing){f.isActing=!0;p=f.windowWidth;n=f.windowHeight;c=f.documentHeight;a=q-f.lastScrollY;v&&null!=
f.activeElement&&(f.activeElement.value+=" ",f.activeElement.value=f.activeElement.value.trim());g=f.scenes;d=0;for(m=g.length;d<m;d++)k=g[d],(f.inputFocus||b||q+n>=(k.agentOffset||k.offsetTop)+a&&q<=(k.agentOffset||k.offsetTop)+(k.agentHeight||k.offsetHeight)+a)&&k.update(q,p,n,c,f.inputFocus);f.lastScrollY=q;return f.isActing=!1}};return t}();n.RDParallax=function(e){var h;h=n(l);if(!h.data("RDParallax"))return h.data("RDParallax",new u(e))};return e.RDParallax=u})(window.jQuery,document,window);
"undefined"!==typeof module&&null!==module?module.exports=window.RDParallax:"function"===typeof define&&define.amd&&define(["jquery"],function(){return window.RDParallax})}).call(this);