Repository navigation
Expand file tree
/
Copy pathpace.min.js
More file actions
5 lines (5 loc) · 13.4 KB
/
Copy pathpace.min.js
File metadata and controls
5 lines (5 loc) · 13.4 KB
1
2
3
4
5
/*!
* pace.js v1.3.0
* https://github.com/CodeByZach/pace/
* Licensed MIT © HubSpot, Inc.
*/(function(){var O,Y,Q,V,Z,$,ee,C,q,u,te,re,F,ne,se,E,w,ie,g,R,x,X,v,L,oe,U,D,y,ue,d,l,T,I,ae,b,H,P,p,_,W,k,M,z,A,j,le,ce,B,fe,pe,S=[].slice,he={}.hasOwnProperty,ge=function(t,e){for(var r in e)he.call(e,r)&&(t[r]=e[r]);function n(){this.constructor=t}return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t},we=[].indexOf||function(t){for(var e=0,r=this.length;e<r;e++)if(e in this&&this[e]===t)return e;return-1},de=function(t,e){return function(){return t.apply(e,arguments)}};for(X={className:"",catchupTime:100,initialRate:.03,minTime:250,ghostTime:100,maxProgressPerFrame:20,easeFactor:1.25,startOnPageLoad:!0,restartOnPushState:!0,restartOnRequestAfter:500,target:"body",elements:{checkInterval:100,selectors:["body"]},eventLag:{minSamples:10,sampleCount:3,lagThreshold:3},ajax:{trackMethods:["GET"],trackWebSockets:!0,ignoreURLs:[]}},d=function(){var t;return(t=typeof performance!="undefined"&&performance!==null&&typeof performance.now=="function"?performance.now():void 0)!=null?t:+new Date},T=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,x=window.cancelAnimationFrame||window.mozCancelAnimationFrame,E=function(t,e,r){return typeof t.addEventListener=="function"?t.addEventListener(e,r,!1):(function(){if(typeof t["on"+e]!="function"||typeof t["on"+e].eventListeners!="object"){var n=new C;typeof t["on"+e]=="function"&&n.on(e,t["on"+e]),t["on"+e]=function(s){return n.trigger(e,s)},t["on"+e].eventListeners=n}else var n=t["on"+e].eventListeners;n.on(e,r)})()},T==null&&(T=function(t){return setTimeout(t,50)},x=function(t){return clearTimeout(t)}),ae=function(t){var e,r;return e=d(),r=function(){var n;return n=d()-e,n>=33?(e=d(),t(n,function(){return T(r)})):setTimeout(r,33-n)},r()},I=function(){var t,e,r;return r=arguments[0],e=arguments[1],t=3<=arguments.length?S.call(arguments,2):[],typeof r[e]=="function"?r[e].apply(r,t):r[e]},v=function(){var t,e,r,n,s,i,o;for(e=arguments[0],n=2<=arguments.length?S.call(arguments,1):[],i=0,o=n.length;i<o;i++)if(r=n[i],r)for(t in r)he.call(r,t)&&(t==="__proto__"||t==="constructor"||t==="prototype"||(s=r[t],e[t]!=null&&typeof e[t]=="object"&&s!=null&&typeof s=="object"?v(e[t],s):e[t]=s));return e},ie=function(t){var e,r,n,s,i;for(r=e=0,s=0,i=t.length;s<i;s++)n=t[s],r+=Math.abs(n),e++;return r/e},oe=function(t,e){var r,n,s;if(t==null&&(t="options"),e==null&&(e=!0),s=document.querySelector("script[data-pace-"+t+"]"),!!s){if(r=s.getAttribute("data-pace-"+t),!e)return r;try{return JSON.parse(r)}catch(i){return n=i,typeof console!="undefined"&&console!==null?console.error("Error parsing inline pace options",n):void 0}}},ee=(function(){function t(){}return t.prototype.on=function(e,r,n,s){var i;return s==null&&(s=!1),this.bindings==null&&(this.bindings={}),(i=this.bindings)[e]==null&&(i[e]=[]),this.bindings[e].push({handler:r,ctx:n,once:s})},t.prototype.once=function(e,r,n){return this.on(e,r,n,!0)},t.prototype.off=function(e,r){var n,s,i;if(((s=this.bindings)!=null?s[e]:void 0)!=null){if(r==null)return delete this.bindings[e];for(n=0,i=[];n<this.bindings[e].length;)this.bindings[e][n].handler===r?i.push(this.bindings[e].splice(n,1)):i.push(n++);return i}},t.prototype.trigger=function(){var e,r,n,s,i,o,a,f,c;if(n=arguments[0],e=2<=arguments.length?S.call(arguments,1):[],(a=this.bindings)!=null&&a[n]){for(i=0,c=[];i<this.bindings[n].length;)f=this.bindings[n][i],s=f.handler,r=f.ctx,o=f.once,s.apply(r!=null?r:this,e),o?c.push(this.bindings[n].splice(i,1)):c.push(i++);return c}},t})(),u=window.Pace||{},window.Pace=u,v(u,ee.prototype),l=u.options=v({},X,window.paceOptions,oe()),B=["ajax","document","eventLag","elements"],A=0,le=B.length;A<le;A++)p=B[A],l[p]===!0&&(l[p]=X[p]);q=(function(t){ge(e,t);function e(){return fe=e.__super__.constructor.apply(this,arguments),fe}return e})(Error),Y=(function(){function t(){this.progress=0}return t.prototype.getElement=function(){var e,r,n,s;if(this.el==null){if(s=document.querySelector(l.target),!s)throw new q;this.el=document.createElement("div"),this.el.className="pace pace-active",document.body.className=document.body.className.replace(/(pace-done )|/,"pace-running "),n=document.createElement("div"),n.className="pace-progress"+(l.className!==""?" "+l.className:""),r=document.createElement("div"),r.className="pace-progress-inner",n.appendChild(r),e=document.createElement("div"),e.className="pace-activity",this.el.appendChild(n),this.el.appendChild(e),s.firstChild!=null?s.insertBefore(this.el,s.firstChild):s.appendChild(this.el)}return this.el},t.prototype.finish=function(){var e;return e=this.getElement(),e.className=e.className.replace("pace-active","pace-inactive"),document.body.className=document.body.className.replace("pace-running ","pace-done ")},t.prototype.update=function(e){return this.progress=e,u.trigger("progress",e),this.render()},t.prototype.destroy=function(){try{this.getElement().parentNode.removeChild(this.getElement())}catch(e){q=e}return this.el=void 0},t.prototype.render=function(){var e,r,n,s,i,o,a;if(document.querySelector(l.target)==null)return!1;for(e=this.getElement(),s="translate3d("+this.progress+"%, 0, 0)",a=["webkitTransform","msTransform","transform"],i=0,o=a.length;i<o;i++)r=a[i],e.children[0].style[r]=s;return(!this.lastRenderedProgress||this.lastRenderedProgress|this.progress!==0|0)&&(e.children[0].setAttribute("data-progress-text",""+(this.progress|0)+"%"),this.progress>=100?n="99":(n=this.progress<10?"0":"",n+=this.progress|0),e.children[0].setAttribute("data-progress",""+n)),u.trigger("change",this.progress),this.lastRenderedProgress=this.progress},t.prototype.done=function(){return this.progress>=100},t})(),C=(function(){function t(){this.bindings={}}return t.prototype.trigger=function(e,r){var n,s,i,o,a;if(this.bindings[e]!=null){for(o=this.bindings[e],a=[],s=0,i=o.length;s<i;s++)n=o[s],a.push(n.call(this,r));return a}},t.prototype.on=function(e,r){var n;return(n=this.bindings)[e]==null&&(n[e]=[]),this.bindings[e].push(r)},t})(),z=window.XMLHttpRequest,M=window.XDomainRequest,k=window.WebSocket,L=function(t,e){var r,n,s;s=[];for(n in e.prototype)try{t[n]==null&&typeof e[n]!="function"?typeof Object.defineProperty=="function"?s.push(Object.defineProperty(t,n,{get:(function(i){return function(){return e.prototype[i]}})(n),configurable:!0,enumerable:!0})):s.push(t[n]=e.prototype[n]):s.push(void 0)}catch(i){r=i}return s},y=[],u.ignore=function(){var t,e,r;return e=arguments[0],t=2<=arguments.length?S.call(arguments,1):[],y.unshift("ignore"),r=e.apply(null,t),y.shift(),r},u.track=function(){var t,e,r;return e=arguments[0],t=2<=arguments.length?S.call(arguments,1):[],y.unshift("track"),r=e.apply(null,t),y.shift(),r},P=function(t){var e;if(t==null&&(t="GET"),y[0]==="track")return"force";if(!y.length&&l.ajax){if(t==="socket"&&l.ajax.trackWebSockets)return!0;if(e=t.toUpperCase(),we.call(l.ajax.trackMethods,e)>=0)return!0}return!1},te=(function(t){ge(e,t);function e(){var r,n=this;e.__super__.constructor.apply(this,arguments),r=function(s){var i;return i=s.open,s.open=function(o,a,f){return P(o)&&n.trigger("request",{type:o,url:a,request:s}),i.apply(s,arguments)}},window.XMLHttpRequest=function(s){var i;return i=new z(s),r(i),i};try{L(window.XMLHttpRequest,z)}catch(s){}if(M!=null){window.XDomainRequest=function(){var s;return s=new M,r(s),s};try{L(window.XDomainRequest,M)}catch(s){}}if(k!=null&&l.ajax.trackWebSockets){window.WebSocket=function(s,i){var o;return i!=null?o=new k(s,i):o=new k(s),P("socket")&&n.trigger("request",{type:"socket",url:s,protocols:i,request:o}),o};try{L(window.WebSocket,k)}catch(s){}}}return e})(C),j=null,U=function(){return j==null&&(j=new te),j},H=function(t){var e,r,n,s;for(s=l.ajax.ignoreURLs,r=0,n=s.length;r<n;r++)if(e=s[r],typeof e=="string"){if(t.indexOf(e)!==-1)return!0}else if(e.test(t))return!0;return!1},U().on("request",function(t){var e,r,n,s,i;if(s=t.type,n=t.request,i=t.url,!H(i)&&!u.running&&(l.restartOnRequestAfter!==!1||P(s)==="force"))return r=arguments,e=l.restartOnRequestAfter||0,typeof e=="boolean"&&(e=0),setTimeout(function(){var o,a,f,c,h,m;if(s==="socket"?o=n.readyState<1:o=0<(c=n.readyState)&&c<4,o){for(u.restart(),h=u.sources,m=[],a=0,f=h.length;a<f;a++)if(p=h[a],p instanceof O){p.watch.apply(p,r);break}else m.push(void 0);return m}},e)}),O=(function(){function t(){this.complete=de(this.complete,this);var e=this;this.elements=[],U().on("request",function(){return e.watch.apply(e,arguments)})}return t.prototype.watch=function(e){var r,n,s,i;if(s=e.type,r=e.request,i=e.url,!H(i))return s==="socket"?n=new ne(r,this.complete):n=new se(r,this.complete),this.elements.push(n)},t.prototype.complete=function(e){return this.elements=this.elements.filter(function(r){return r!==e})},t})(),se=(function(){function t(e,r){var n,s,i,o,a,f,c=this;if(this.progress=0,window.ProgressEvent!=null)for(s=null,E(e,"progress",function(h){return h.lengthComputable?c.progress=100*h.loaded/h.total:c.progress=c.progress+(100-c.progress)/2},!1),f=["load","abort","timeout","error"],i=0,o=f.length;i<o;i++)n=f[i],E(e,n,function(){return r(c),c.progress=100},!1);else a=e.onreadystatechange,e.onreadystatechange=function(){var h;return(h=e.readyState)===0||h===4?(r(c),c.progress=100):e.readyState===3&&(c.progress=50),typeof a=="function"?a.apply(null,arguments):void 0}}return t})(),ne=(function(){function t(e,r){var n,s,i,o,a=this;for(this.progress=0,o=["error","open"],s=0,i=o.length;s<i;s++)n=o[s],E(e,n,function(){return r(a),a.progress=100},!1)}return t})(),V=(function(){function t(e){var r,n,s,i;for(e==null&&(e={}),this.complete=de(this.complete,this),this.elements=[],e.selectors==null&&(e.selectors=[]),i=e.selectors,n=0,s=i.length;n<s;n++)r=i[n],this.elements.push(new Z(r,this.complete))}return t.prototype.complete=function(e){return this.elements=this.elements.filter(function(r){return r!==e})},t})(),Z=(function(){function t(e,r){this.selector=e,this.completeCallback=r,this.progress=0,this.check()}return t.prototype.check=function(){var e=this;return document.querySelector(this.selector)?this.done():setTimeout((function(){return e.check()}),l.elements.checkInterval)},t.prototype.done=function(){return this.completeCallback(this),this.completeCallback=null,this.progress=100},t})(),Q=(function(){t.prototype.states={loading:0,interactive:50,complete:100};function t(){var e,r,n=this;this.progress=(r=this.states[document.readyState])!=null?r:100,e=document.onreadystatechange,document.onreadystatechange=function(){return n.states[document.readyState]!=null&&(n.progress=n.states[document.readyState]),typeof e=="function"?e.apply(null,arguments):void 0}}return t})(),$=(function(){function t(){var e,r,n,s,i,o=this;this.progress=0,e=0,i=[],s=0,n=d(),r=setInterval(function(){var a;return a=d()-n-50,n=d(),i.push(a),i.length>l.eventLag.sampleCount&&i.shift(),e=ie(i),++s>=l.eventLag.minSamples&&e<l.eventLag.lagThreshold?(o.progress=100,clearInterval(r)):o.progress=100*(3/(e+3))},50)}return t})(),F=(function(){function t(e){this.source=e,this.last=this.sinceLastUpdate=0,this.rate=l.initialRate,this.catchup=0,this.progress=this.lastProgress=0,this.source!=null&&(this.progress=I(this.source,"progress"))}return t.prototype.tick=function(e,r){var n;return r==null&&(r=I(this.source,"progress")),r>=100&&(this.done=!0),r===this.last?this.sinceLastUpdate+=e:(this.sinceLastUpdate&&(this.rate=(r-this.last)/this.sinceLastUpdate),this.catchup=(r-this.progress)/l.catchupTime,this.sinceLastUpdate=0,this.last=r),r>this.progress&&(this.progress+=this.catchup*e),n=1-Math.pow(this.progress/100,l.easeFactor),this.progress+=n*this.rate*e,this.progress=Math.min(this.lastProgress+l.maxProgressPerFrame,this.progress),this.progress=Math.max(0,this.progress),this.progress=Math.min(100,this.progress),this.lastProgress=this.progress,this.progress},t})(),_=null,b=null,g=null,W=null,w=null,R=null,u.running=!1,D=function(){if(l.restartOnPushState)return u.restart()},window.history.pushState!=null&&(ce=window.history.pushState,window.history.pushState=function(){return D(),ce.apply(window.history,arguments)}),window.history.replaceState!=null&&(pe=window.history.replaceState,window.history.replaceState=function(){return D(),pe.apply(window.history,arguments)}),re={ajax:O,elements:V,document:Q,eventLag:$},(ue=function(){var t,e,r,n,s,i,o,a;for(u.sources=_=[],i=["ajax","elements","document","eventLag"],e=0,n=i.length;e<n;e++)t=i[e],l[t]!==!1&&_.push(new re[t](l[t]));for(a=(o=l.extraSources)!=null?o:[],r=0,s=a.length;r<s;r++)p=a[r],_.push(new p(l));return u.bar=g=new Y,b=[],W=new F})(),u.stop=function(){return u.trigger("stop"),u.running=!1,g.destroy(),R=!0,w!=null&&(typeof x=="function"&&x(w),w=null),ue()},u.restart=function(){return u.trigger("restart"),u.stop(),u.start()},u.go=function(){var t;return u.running=!0,g.render(),t=d(),R=!1,w=ae(function(e,r){var n,s,i,o,a,f,c,h,m,N,G,J,K,me,ye,_e;for(h=100-g.progress,s=G=0,i=!0,f=J=0,me=_.length;J<me;f=++J)for(p=_[f],N=b[f]!=null?b[f]:b[f]=[],a=(_e=p.elements)!=null?_e:[p],c=K=0,ye=a.length;K<ye;c=++K)o=a[c],m=N[c]!=null?N[c]:N[c]=new F(o),i&=m.done,!m.done&&(s++,G+=m.tick(e));return n=G/s,g.update(W.tick(e,n)),g.done()||i||R?(g.update(100),u.trigger("done"),setTimeout(function(){return g.finish(),u.running=!1,u.trigger("hide")},Math.max(l.ghostTime,Math.max(l.minTime-(d()-t),0)))):r()})},u.start=function(t){v(l,t),u.running=!0;try{g.render()}catch(e){q=e}return document.querySelector(".pace")?(u.trigger("start"),u.go()):setTimeout(u.start,50)},typeof define=="function"&&define.amd?define(function(){return u}):typeof exports=="object"?module.exports=u:l.startOnPageLoad&&u.start()}).call(this);