Skip to content

Instantly share code, notes, and snippets.

@CGastrell
Created December 20, 2014 18:19
Show Gist options
  • Save CGastrell/cd81e7eee77a23e74278 to your computer and use it in GitHub Desktop.
Save CGastrell/cd81e7eee77a23e74278 to your computer and use it in GitHub Desktop.
found at popcorntime.io
var popcorn={initialize:function(){this.polyfill(),analytics.initialize({"Google Analytics":{trackingId:"UA-38440155-3",domain:"popcorntime.io",universalClient:!0}}),analytics.pageview()},polyfill:function(){for(var a=["ms","moz","webkit","o"],b=0;b<a.length&&!window.requestAnimationFrame;b++)window.requestAnimationFrame=window[a[b]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[a[b]+"CancelAnimationFrame"]||window[a[b]+"CancelRequestAnimationFrame"]},detectUA:function(a){return/Mac/.test(a)?"mac":/Win/.test(a)?"win":/Lin/.test(a)?/x86_64/.test(a)?"lin-64":"lin-32":void 0},updateDownloads:function(a){document.body.className+=" "+(this.detectUA(a)||"nope")},updateStatus:function(a,b){$.get(b,function(b){$(a).addClass(b.status.indicator)},"json")},smoothScroll:function(){$("a[data-scroll][href*=#]:not([href=#])").click(function(){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var a=$(this.hash);if(a=a.length?a:$("[name="+this.hash.slice(1)+"]"),a.length)return $("html,body").animate({scrollTop:a.offset().top},800),!1}})},snow:function(){function a(){for(var a=0;h>a;a++)j.push({x:Math.random()*k,y:Math.random()*l,size:1+3*Math.random(),weight:Math.random()*h,angle:360*Math.random()});b(),window.addEventListener("resize",b),window.addEventListener("mousemove",c),void 0!==window.orientation&&window.addEventListener("deviceorientation",d),document.body.insertBefore(o,document.body.firstChild),window.requestAnimationFrame(e)}function b(){k=window.innerWidth,l=window.innerHeight,m=k/2,o.width=k,o.height=l}function c(a){n.x=a.x||a.clientX,n.y=a.y||a.clientY,i.x=f(n.x-m,-m,m,4,-4)}function d(a){null!==a.gamma&&(i.x=window.orientation%180?f(a.beta,-60,60,4,-4):f(a.gamma,-60,60,-4,4),q&&(window.removeEventListener("mousemove",mousemove),q=!1))}function e(){p.clearRect(0,0,k,l),p.fillStyle="rgba(250,250,250,0.8)",p.beginPath();for(var a=0;h>a;a++){var b=j[a];p.moveTo(b.x,b.y),p.arc(b.x,b.y,b.size,0,2*Math.PI,!0)}p.fill(),g(),requestAnimationFrame(e)}function f(a,b,c,d,e){return(a-b)*(e-d)/(c-b)+d}function g(){for(var a=0;h>a;a++){var b=j[a];b.angle+=.01,b.y+=Math.cos(b.weight)+i.y+b.size/2,b.x+=Math.sin(b.angle)+i.x,(b.x>k+5||b.x<-5||b.y>l)&&(a%3>0?(b.x=Math.random()*k,b.y=-5):b.x>m?(b.x=-5,b.y=Math.random()*l):(b.x=k+5,b.y=Math.random()*l))}}var h=75,i={x:2,y:1},j=[],k=window.innerWidth,l=window.innerHeight,m=k/2,n={x:0,y:0},o=document.createElement("canvas"),p=o.getContext("2d");o.className="snow",a();var q=!0}};popcorn.initialize(),popcorn.updateDownloads(navigator.platform),popcorn.updateStatus("#status","https://popcorntime.statuspage.io/api/v1/status.json"),popcorn.smoothScroll(),(11===(mnth=(new Date).getMonth())||0===mnth)&&popcorn.snow();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment