Socialify

Folder ..

Viewing scrollreveal.min.js
1 lines (1 loc) • 13.3 KB

1
var ScrollReveal=function(){"use strict";function e(i){for(var o=[],r=arguments.length-1;r-- >0;)o[r]=arguments[r+1];if(t(i))return n(o,function(o){n(o,function(n,o){t(n)?(i[o]&&t(i[o])||(i[o]={}),e(i[o],n)):i[o]=n})}),i;throw new TypeError("Expected an object literal.")}function t(e){return null!==e&&"object"==typeof e&&(e.constructor===Object||"[object Object]"===Object.prototype.toString.call(e))}function n(e,n){if(t(e))for(var i=Object.keys(e),o=0;o<i.length;o++)n(e[i[o]],i[o],e);else{if(!Array.isArray(e))throw new TypeError("Expected either an array or object literal.");for(var r=0;r<e.length;r++)n(e[r],r,e)}}function i(e){return void 0===e&&(e=navigator.userAgent),/Android|iPhone|iPad|iPod/i.test(e)}function o(e){return"object"==typeof window.Node?e instanceof window.Node:null!==e&&"object"==typeof e&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName}function r(e){var t=Object.prototype.toString.call(e),n=/^\[object (HTMLCollection|NodeList|Object)\]$/;return"object"==typeof window.NodeList?e instanceof window.NodeList:"object"==typeof e&&"number"==typeof e.length&&n.test(t)&&(0===e.length||o(e[0]))}function s(){var e=document.documentElement.style;return"transform"in e||"WebkitTransform"in e}function a(){var e=document.documentElement.style;return"transition"in e||"WebkitTransition"in e}function l(e){var t=this.store.containers[e.containerId],n=e.config.viewFactor,i=e.config.viewOffset,o={top:e.geometry.bounds.top+e.geometry.height*n,right:e.geometry.bounds.right-e.geometry.width*n,bottom:e.geometry.bounds.bottom-e.geometry.height*n,left:e.geometry.bounds.left+e.geometry.width*n},r={top:t.geometry.bounds.top+t.scroll.top+i.top,right:t.geometry.bounds.right+t.scroll.left+i.right,bottom:t.geometry.bounds.bottom+t.scroll.top+i.bottom,left:t.geometry.bounds.left+t.scroll.left+i.left};return o.top<r.bottom&&o.right>r.left&&o.bottom>r.top&&o.left<r.right||"fixed"===e.styles.position}function c(e,t){var n=t?e.node.clientHeight:e.node.offsetHeight,i=t?e.node.clientWidth:e.node.offsetWidth,o=0,r=0,s=e.node;do{isNaN(s.offsetTop)||(o+=s.offsetTop),isNaN(s.offsetLeft)||(r+=s.offsetLeft),s=s.offsetParent}while(s);return{bounds:{top:o,right:r+i,bottom:o+n,left:r},height:n,width:i}}function d(e,t){void 0===t&&(t=document);var n=null;if("string"==typeof e)try{n=t.querySelector(e)}catch(e){}return o(e)?e:n}function u(e,t){if(void 0===t&&(t=document),o(e))return[e];if(r(e))return Array.prototype.slice.call(e);if("string"==typeof e)try{var n=t.querySelectorAll(e),i=Array.prototype.slice.call(n);if(i.length)return i}catch(e){}return[]}function f(e){return e.node===document.documentElement?{top:window.pageYOffset,left:window.pageXOffset}:{top:e.node.scrollTop,left:e.node.scrollLeft}}function p(){var e=this,t={active:[],stale:[]},i={active:[],stale:[]},o={active:[],stale:[]};n(u("[data-sr-id]"),function(e){var n=parseInt(e.getAttribute("data-sr-id"));t.active.push(n)}),n(this.store.elements,function(e){-1===t.active.indexOf(e.id)&&t.stale.push(e.id)}),n(t.stale,function(t){return delete e.store.elements[t]}),n(this.store.elements,function(e){-1===i.active.indexOf(e.containerId)&&i.active.push(e.containerId),e.hasOwnProperty("sequence")&&-1===o.active.indexOf(e.sequence.id)&&o.active.push(e.sequence.id)}),n(this.store.containers,function(e){-1===i.active.indexOf(e.id)&&i.stale.push(e.id)}),n(i.stale,function(t){e.store.containers[t].node.removeEventListener("scroll",e.delegate),e.store.containers[t].node.removeEventListener("resize",e.delegate),delete e.store.containers[t]}),n(this.store.sequences,function(e){-1===o.active.indexOf(e.id)&&o.stale.push(e.id)}),n(o.stale,function(t){return delete e.store.sequences[t]})}function h(e){var t,i=this;n(u(e),function(e){var n=e.getAttribute("data-sr-id");null!==n&&(t=!0,e.setAttribute("style",i.store.elements[n].styles.inline),e.removeAttribute("data-sr-id"),delete i.store.elements[n])}),t&&p.call(this)}function y(){var e=this;n(this.store.elements,function(e){e.node.setAttribute("style",e.styles.inline),e.node.removeAttribute("data-sr-id")}),n(this.store.containers,function(t){t.node===document.documentElement?(window.removeEventListener("scroll",e.delegate),window.removeEventListener("resize",e.delegate)):(t.node.removeEventListener("scroll",e.delegate),t.node.removeEventListener("resize",e.delegate))}),this.store={containers:{},elements:{},history:[],sequences:{}}}function m(e){if(e.constructor!==Array)throw new TypeError("Expected array.");if(16===e.length)return e;if(6===e.length){var t=g();return t[0]=e[0],t[1]=e[1],t[4]=e[2],t[5]=e[3],t[12]=e[4],t[13]=e[5],t}throw new RangeError("Expected array with either 6 or 16 values.")}function g(){for(var e=[],t=0;t<16;t++)t%5==0?e.push(1):e.push(0);return e}function v(e,t){for(var n=m(e),i=m(t),o=[],r=0;r<4;r++)for(var s=[n[r],n[r+4],n[r+8],n[r+12]],a=0;a<4;a++){var l=4*a,c=[i[l],i[l+1],i[l+2],i[l+3]],d=s[0]*c[0]+s[1]*c[1]+s[2]*c[2]+s[3]*c[3];o[r+l]=d}return o}function b(e){if("string"==typeof e){var t=e.match(/matrix(3d)?\(([^)]+)\)/);if(t){return m(t[2].split(", ").map(function(e){return parseFloat(e)}))}}return g()}function w(e){var t=Math.PI/180*e,n=g();return n[5]=n[10]=Math.cos(t),n[6]=n[9]=Math.sin(t),n[9]*=-1,n}function x(e){var t=Math.PI/180*e,n=g();return n[0]=n[10]=Math.cos(t),n[2]=n[8]=Math.sin(t),n[2]*=-1,n}function k(e){var t=Math.PI/180*e,n=g();return n[0]=n[5]=Math.cos(t),n[1]=n[4]=Math.sin(t),n[4]*=-1,n}function E(e,t){var n=g();return n[0]=e,n[5]=t||e,n}function j(e){var t=g();return t[12]=e,t}function T(e){var t=g();return t[13]=e,t}function A(e){var t=window.getComputedStyle(e.node),n=t.position,i=e.config,o=/.+[^;]/g,r=e.node.getAttribute("style")||"",s=o.exec(r),a=s?s[0]+";":"";-1===a.indexOf("visibility: visible")&&(a+=a.length?" ":"",a+="visibility: visible;");var l=parseFloat(t.opacity),c=isNaN(parseFloat(i.opacity))?parseFloat(t.opacity):parseFloat(i.opacity),d={computed:l!==c?"opacity: "+l+";":"",generated:l!==c?"opacity: "+c+";":""},u=[];if(parseFloat(i.distance)){var f="top"===i.origin||"bottom"===i.origin?"Y":"X",p=i.distance;"top"!==i.origin&&"left"!==i.origin||(p=/^-/.test(p)?p.substr(1):"-"+p);var h=p.match(/(^-?\d+\.?\d?)|(em$|px$|\%$)/g),y=h[0];switch(h[1]){case"em":p=parseInt(t.fontSize)*y;break;case"px":p=y;break;case"%":p="Y"===f?e.node.getBoundingClientRect().height*y/100:e.node.getBoundingClientRect().width*y/100;break;default:throw new RangeError("Unrecognized or missing distance unit.")}"Y"===f?u.push(T(p)):u.push(j(p))}i.rotate.x&&u.push(w(i.rotate.x)),i.rotate.y&&u.push(x(i.rotate.y)),i.rotate.z&&u.push(k(i.rotate.z)),1!==i.scale&&u.push(E(i.scale));var m={};if(u.length){m.property=S("transform"),m.computed={raw:t[m.property],matrix:b(t[m.property])},u.unshift(m.computed.matrix);var g=u.reduce(v);m.generated={initial:m.property+": matrix3d("+g.join(", ")+");",final:m.property+": matrix3d("+m.computed.matrix.join(", ")+");"}}else m.generated={initial:"",final:""};var A={};if(d.generated||m.generated.initial){A.property=S("transition"),A.computed=t[A.property],A.fragments=[];var O=i.delay,q=i.duration,L=i.easing;d.generated&&A.fragments.push({delayed:"opacity "+q/1e3+"s "+L+" "+O/1e3+"s",instant:"opacity "+q/1e3+"s "+L+" 0s"}),m.generated.initial&&A.fragments.push({delayed:m.property+" "+q/1e3+"s "+L+" "+O/1e3+"s",instant:m.property+" "+q/1e3+"s "+L+" 0s"}),A.computed&&!A.computed.match(/all 0s/)&&A.fragments.unshift({delayed:A.computed,instant:A.computed});var R=A.fragments.reduce(function(e,t,n){return e.delayed+=0===n?t.delayed:", "+t.delayed,e.instant+=0===n?t.instant:", "+t.instant,e},{delayed:"",instant:""});A.generated={delayed:A.property+": "+R.delayed+";",instant:A.property+": "+R.instant+";"}}return{inline:a,opacity:d,position:n,transform:m,transition:A}}function O(){var e=this;p.call(this),n(this.store.elements,function(e){var t=[e.styles.inline];e.visible?(t.push(e.styles.opacity.computed),t.push(e.styles.transform.generated.final)):(t.push(e.styles.opacity.generated),t.push(e.styles.transform.generated.initial)),e.node.setAttribute("style",t.join(" "))}),n(this.store.containers,function(t){t.node===document.documentElement?(window.addEventListener("scroll",e.delegate),window.addEventListener("resize",e.delegate)):(t.node.addEventListener("scroll",e.delegate),t.node.addEventListener("resize",e.delegate))}),this.delegate(),this.initTimeout=null}function q(t,o,r,s){var a=this;"number"==typeof o?(r=Math.abs(parseInt(o)),o={}):(r=Math.abs(parseInt(r)),o=o||{});var l=e({},this.defaults,o),c=this.store.containers,f=d(l.container),p=u(t,f);if(p.length&&(l.mobile||!i())&&(l.desktop||i())){var h;if(r){if(!(r>=16))return;var y=F();h={elementIds:[],head:{index:null,blocked:!1},tail:{index:null,blocked:!1},id:y,interval:Math.abs(r)}}var m;n(c,function(e){m||e.node!==f||(m=e.id)}),isNaN(m)&&(m=F());try{n(p.map(function(t){var n={},i=t.getAttribute("data-sr-id");return i?(e(n,a.store.elements[i]),n.node.setAttribute("style",n.styles.inline)):(n.id=F(),n.node=t,n.seen=!1,n.visible=!1),n.config=l,n.containerId=m,n.styles=A(n),h&&(n.sequence={id:h.id,index:h.elementIds.length},h.elementIds.push(n.id)),n}),function(e){a.store.elements[e.id]=e,e.node.setAttribute("data-sr-id",e.id)})}catch(e){return}c[m]=c[m]||{id:m,node:f},h&&(this.store.sequences[h.id]=h),s||(this.store.history.push({target:t,options:o,interval:r}),this.initTimeout&&window.clearTimeout(this.initTimeout),this.initTimeout=window.setTimeout(O.bind(this),0))}}function L(){var e=this;n(this.store.history,function(t){q.call(e,t.target,t.options,t.interval,!0)}),O.call(this)}function R(e){var t=this,n="always"===e.config.useDelay||"onload"===e.config.useDelay&&this.pristine||"once"===e.config.useDelay&&!e.seen,i=e.sequence?this.store.sequences[e.sequence.id]:null,o=[e.styles.inline];if(l.call(this,e)&&!e.visible){if(null!==i){if(null===i.head.index&&null===i.tail.index)i.head.index=i.tail.index=e.sequence.index,i.head.blocked=i.tail.blocked=!0;else if(i.head.index-1!==e.sequence.index||i.head.blocked){if(i.tail.index+1!==e.sequence.index||i.tail.blocked)return;i.tail.index++,i.tail.blocked=!0}else i.head.index--,i.head.blocked=!0;window.setTimeout(function(){i.head.blocked=i.tail.blocked=!1,t.delegate()},i.interval)}o.push(e.styles.opacity.computed),o.push(e.styles.transform.generated.final),n?o.push(e.styles.transition.generated.delayed):o.push(e.styles.transition.generated.instant),e.seen=!0,e.visible=!0,I.call(this,e,n),e.node.setAttribute("style",o.join(" "))}else if(!l.call(this,e)&&e.visible&&e.config.reset){if(i)if(i.head.index===e.sequence.index)i.head.index++;else{if(i.tail.index!==e.sequence.index)return;i.tail.index--}o.push(e.styles.opacity.generated),o.push(e.styles.transform.generated.initial),o.push(e.styles.transition.generated.instant),e.visible=!1,I.call(this,e),e.node.setAttribute("style",o.join(" "))}}function I(e,t){var n,i=this,o=t?e.config.duration+e.config.delay:e.config.duration;e.visible?(e.config.beforeReveal(e.node),n=e.config.afterReveal):(e.config.beforeReset(e.node),n=e.config.afterReset);var r=0;e.callbackTimer&&(r=Date.now()-e.callbackTimer.start,window.clearTimeout(e.callbackTimer.clock)),e.callbackTimer={start:Date.now(),clock:window.setTimeout(function(){n(e.node),e.callbackTimer=null,e.visible&&!e.config.reset&&h.call(i,e.node)},o-r)}}function N(e){var t=this;void 0===e&&(e={}),C(function(){var i=t.store.containers,o=t.store.elements;switch(e.type){case"scroll":n(i,function(e){return e.scroll=f.call(t,e)}),n(o,function(e){return R.call(t,e)});break;case"resize":default:n(i,function(e){e.geometry=c.call(t,e,!0),e.scroll=f.call(t,e)}),n(o,function(e){e.geometry=c.call(t,e),R.call(t,e)})}t.pristine=!1})}function z(t){if(void 0===t&&(t={}),void 0===this||Object.getPrototypeOf(this)!==z.prototype)return new z(t);if(!z.isSupported())return P;try{Object.defineProperty(this,"defaults",{get:function(){var n={};return e(n,M,t),function(){return n}}()})}catch(e){return P}if(!d(this.defaults.container))return P;this.defaults.mobile!==i()&&this.defaults.desktop!==!i()||document.documentElement.classList.add("sr"),this.store={containers:{},elements:{},history:[],sequences:{}},this.pristine=!0,this.delegate=N.bind(this),Object.defineProperty(this,"version",{get:function(){return W}}),Object.defineProperty(this,"noop",{get:function(){return!1}})}var M={origin:"bottom",distance:"0",duration:600,delay:0,rotate:{x:0,y:0,z:0},opacity:0,scale:1,easing:"cubic-bezier(0.6, 0.2, 0.1, 1)",container:document.documentElement,desktop:!0,mobile:!0,reset:!1,useDelay:"always",viewFactor:0,viewOffset:{top:0,right:0,bottom:0,left:0},beforeReveal:function(){},beforeReset:function(){},afterReveal:function(){},afterReset:function(){}},P={clean:function(){},destroy:function(){},reveal:function(){},sync:function(){},get noop(){return!0}},F=function(){var e=0;return function(){return e++}}(),S=function(){function e(e,i){if(void 0===i&&(i=n),e&&"string"==typeof e){if(t[e])return t[e];if("string"==typeof i[e])return t[e]=e;if("string"==typeof i["-webkit-"+e])return t[e]="-webkit-"+e;throw new RangeError('Unable to find "'+e+'" style property.')}throw new TypeError("Expected a string.")}var t={},n=document.documentElement.style;return e.clearCache=function(){return t={}},e}(),D=function(){var e=Date.now();return function(t){var n=Date.now();n-e>16?(e=n,t(n)):setTimeout(function(){return D(t)},0)}}(),C=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||D,W="4.0.0-beta.2";return z.isSupported=function(){return s()&&a()},z.prototype.clean=h,z.prototype.destroy=y,z.prototype.reveal=q,z.prototype.sync=L,z}();