-
Notifications
You must be signed in to change notification settings - Fork 0
/
direction.min.js
12 lines (12 loc) · 4.84 KB
/
direction.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
direction.js (c) 2015 Ogewan, MIT*/
direction=function d(x,k){x=x||[];k=k||{};var n=document,y=n.body,v=n.documentElement,r=parseInt,z=window.requestAnimationFrame,I=k.overwrite||0,F=k.anchor||y,f=x.slice().map(function(a){return{s:a}}),A=!0,B=-1,p=-1,b=[k.disableSpin?null:n.createElement("canvas"),n.createElement("canvas")],e=b[0]?{ctx:b[0].getContext("2d"),clr:k.color||"#373737",str:Date.now(),lne:k.lines||16,rte:k.rate||1E3/30,dia:k.diameter||250,lbk:k.loaderback||"#FFF"}:null,l={dir:k.dir||"",irb:k.imgprebuffer||5,itb:k.imgpostbuffer||
5,bck:k.back||"#FFF",sz:k.size||0,scl:0},t=[],u=[],g=new Image,D=!0,w=b[1].getContext("2d"),m={run:function(a){for(var c=0;c<m[a].length;c++)m[a][c]()},start:[],slidn:[],slidd:[]},E=function(){if(e){b[0].style.paddingLeft=(b[1].width-300)/2+"px";var a=Math.floor((Date.now()-e.str)/1E3*e.lne)/e.lne,c=e.clr.substr(1);e.ctx.save();e.ctx.clearRect(0,0,300,b[1].height);e.ctx.translate(150,b[1].height/2);e.ctx.rotate(2*Math.PI*a);3==c.length&&(c=c[0]+C[0]+c[1]+c[1]+c[2]+c[2]);a=r(c.substr(0,2),16).toString();
var J=r(c.substr(2,2),16).toString();c=r(c.substr(4,2),16).toString();for(var f=0;f<e.lne;f++)e.ctx.beginPath(),e.ctx.rotate(2*Math.PI/e.lne),e.ctx.moveTo(e.dia/10,0),e.ctx.lineTo(e.dia/4,0),e.ctx.lineWidth=e.dia/30,e.ctx.strokeStyle="rgba("+a+","+J+","+c+","+f/e.lne+")",e.ctx.stroke();e.ctx.restore();A?z(E):e.ctx.clearRect(0,0,300,b[1].height)}},G=function(a,c){if(null===a||void 0===a)a={x:0,y:0};else if(isNaN(a)){if(null===a.y||void 0===a.y)a.y=0;if(null===a.x||void 0===a.x)a.x=0}else a={x:0,y:a};
if(null===c||void 0===c||0>=c)c=400;0>a.y&&(a.y=window.innerHeight||v.clientHeight||y.clientHeight);0>a.x&&(a.x=window.innerWidth||v.clientWidth||y.clientWidth);var b={x:void 0!==window.pageXOffset?a.x-window.pageXOffset:a.x-v.scrollLeft,y:void 0!==window.pageYOffset?a.y-window.pageYOffset:a.y-v.scrollTop};if(b=={x:0,y:0})return b;var f=function(a,c,b){window.scrollBy(Math.floor(a.x)/c,Math.floor(a.y)/c);b+1<5*c&&(B=window.setTimeout(f,5,a,c,b+1))};B=window.setTimeout(f,5,b,Math.floor(c/5),0);return b};
n=function(){f[this.virID].ld=!0};var q=function(a,c){A=!0;z(E);m.run("start");0>c&&(c=0);c>=f.length&&(c=f.length-1);if(!(0>c)){f[c].ld||w.clearRect(0,0,b[1].width,b[1].height);a.virID=c;a.src=l.dir+f[c].s;p=c;var e=0,g;for(g=c-1;g>c-l.irb-1&&0<=g;g--)f[g].ld||(u[e].virID=g,u[e].src=l.dir+f[g].s,e++);e=0;for(g=c+1;g<l.itb+c+1&&g<f.length;g++)f[g].ld||(t[e].virID=g,t[e].src=l.dir+f[g].s,e++)}},H=function(a,c){if(a)for(var b in c)a.hasOwnProperty(b)&&(a[b]=c[b])},h=function(){try{jQuery.fn.direction=
function(a,c){return this.each(function(){c.anchor=$(this);d(a,c)})}}catch(a){console.log(a)}};window.jQuery&&h();this.canvi=b;this.cb=m;this.cnl=function(){window.clearTimeout(B)};this.swap=function(a,c,b){f=Array.isArray(a)?a.slice().map(function(c,b){return{s:c,d:b?b==a.length-1?1:0:-1}}):f;c&&(H(e,c),H(l,c));this.go(b||0)};this.count=function(){return f.length};this.current=function(){return p};this.callback=function(a,c,b,e){if(null===a||void 0===a)return m.slidn;a={"-1":m.start,0:m.slidn,1:m.slidd}[b||
0];if(e)return a.splice(b||a.length-1,1);if(null===c||void 0===c)return null===b||void 0===b?a:a[b];null===b||void 0===b?a.push(c):a[b]=c;return 1};this.go=function(a){a=null===a||void 0===a?0:r(a,10);a=isNaN(a)?0:a;q(g,Math.floor(Math.max(0,Math.min(f.length-1,a))));return a};this.prev=function(){var a=p-1;0<=a&&q(g,a);return a};this.next=function(){var a=p+1;a<f.length&&q(g,a);return a};this.frst=function(){0<=p&&q(g,0);return 0};this.last=function(){q(g,f.length-1);return f.length-1};this.rand=
function(){var a=Math.floor(Math.random()*(f.length-1));q(g,a);return a};this.data=function(a){a=null===a||void 0===a?p:r(a,10);return isNaN(a)?f[p]:f[Math.floor(Math.max(0,Math.min(f.length-1,a)))]};this.scroll=function(a){null!==a&&void 0!==a&&(D=a);return D};this.scrollTo=function(a,b){return G(a,b)};e&&(b[0].height=480,b[0].style.background=e.lbk,b[0].style.paddingLeft="170px",b[0].style.zIndex=0,b[0].style.position="absolute");e&&F.appendChild(b[0]);z(E);g=new Image;g.virID=-1;g.addEventListener("load",
function(){f[g.virID].ld?w.clearRect(0,0,b[1].width,b[1].height):f[g.virID].ld=!0;m.run("slidn");if(l.sz)var a=[l.sz.w,l.sz.h];else switch(l.scl){case 1:a=b[1].width/g.width;a=[b[1].width,g.height*a];break;case 2:a=b[1].height/g.height;a=[g.width*a,b[1].height];break;default:a=l.scl?[b[1].width,b[1].height]:[g.width,g.height]}b[1].width=a[0];b[1].height=a[1];e&&(b[0].height=a[1]);w.drawImage.apply(w,[g,0,0].concat(a));A=0;D&&G();m.run("slidd")},!1);for(h=0;h<f.length;h++)f[h].d=h?h==f.length-1?1:
0:-1,f[h].ld=!1;for(h=0;h<l.irb;h++)u.push(new Image),u[h].virID=-1,u[h].addEventListener("load",n,!1);for(h=0;h<l.itb;h++)t.push(new Image),t[h].virID=-1,t[h].addEventListener("load",n,!1);q(g,l.startpage||I);b[1].height=480;b[1].width=640;b[1].background=l.bck;b[1].style.zIndex=1;b[1].style.position="relative";F.appendChild(b[1])};