forked from pisi/Reel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.reel-min.js
35 lines (33 loc) · 11.4 KB
/
jquery.reel-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
Copyright (c) 2009-2012 Petr Vostrel (http://petr.vostrel.cz/)
Dual licensed under the MIT (MIT-LICENSE.txt)
and GPL (GPL-LICENSE.txt) licenses.
jQuery Reel
http://jquery.vostrel.cz/reel
Version: 1.1.4
Updated: 2012-02-27
Requires jQuery 1.4.2 or higher
*/
jQuery.reel||function(h,kb,ja,p){function A(j){return h.reel.instances.length?h.reel.instances.first().data(j):null}function lb(j){return h.reel.instances.push(j[0])&&j}function mb(j){return(h.reel.instances=h.reel.instances.not("#"+j.attr(M)))&&j}function ka(j){return nb&&"data:image/gif;base64,R0lGODlh"+j}function ob(j){return"<"+j+"/>"}function la(j){return"."+j}function ma(j){return"http://code.vostrel.cz/"+j}function na(j){return"url("+j+")"}function H(j){return+j.toFixed(4)}function V(j,a,t){return N(j,
Ma(a,t))}function pb(j){function a(){h.fn[this]||(h.fn[this]=function(){return this})}h.each(j,a)}function oa(j,a){return u(j)*(a?-1:1)}function W(j){return j.originalEvent.touches[0]}h.reel={version:"1.1.4",def:{footage:6,frame:1,frames:36,hint:"",horizontal:true,hotspot:p,indicator:0,klass:"",loops:true,reversed:p,spacing:0,stitched:0,suffix:"-reel",tooltip:"",area:p,brake:0.5,clickfree:false,cw:false,delay:-1,directional:false,draggable:true,entry:p,graph:p,image:p,images:[],inversed:false,laziness:6,
monitor:p,opening:0,orbital:0,path:"",preloader:4,rebound:0.5,revolution:p,row:1,rows:0,speed:0,step:p,steps:p,tempo:36,timeout:2,throwable:true,vertical:false,wheelable:true}};h.fn.reel=function(j){var a=h.extend({},h.reel.def,j);j=function(g){var r=[];g.filter(qb).each(function(){var c=h(this),d=a.images.length&&a.images||a.image||c.attr(Na),v=X(c.css(Oa)),m=X(c.css(Pa));!d||d==Qa||!v||!m||r.push(c)});g.filter(Ra+la(w)).each(function(){r.push(h(this))});return h(r)}(this);var t=[];a.reversed&&(a.cw=
true);a.tooltip&&(a.hint=a.tooltip);a.hotspot&&(a.area=a.hotspot);j.each(function(){var g=h(this),r=g.data(),c=function(f,b){r[f]=b;g.trigger("store",[f,b]);return b},d=function(f){var b=r[f];g.trigger("recall",[f,b]);return b},v={teardown:function(f){g.unbind(q).unbind(v);var b=g.data("events"),e=g.clone().attr(g.data(Sa)).css({background:"transparent"}).removeClass(w).addClass(d(Ta));for(var i in b)h.each(b[i],function(k,l){e.bind(i+"."+l.namespace,l.handler,l.data)});h("img:"+pa,g.parent()).remove();
mb(g);h(d(Y)).before(e).detach();Z();B.unbind(E,v.tick).unbind(E,v.opening_tick);$.unbind(qa).unbind(ra);m.call(f)},setup:function(){var f=d(C),b=d(Ua),e=N(b,d(sa));e=c(o,1/e*((a.step||a.frame)-1));c(x,e*b+1);g.attr("id");b=g.parent();e=h(O,{"class":rb,css:{position:aa,left:0,top:0,width:f.x,height:f.y,background:ta,opacity:0}}).appendTo(b);e=c(Va,h(a.area||e));if(h.reel.touchy){g.css({WebkitUserSelect:"none",WebkitBackgroundSize:a.images.length?"auto":d(ua)&&d(ua)+"px "+f.y+"px"||f.x*a.footage+"px "+
f.y*d(va)*(a.rows||1)*(a.directional?2:1)+"px"});e.bind(sb,function(i){g.trigger("down",[W(i).clientX,W(i).clientY,true])}).bind(tb,function(i){g.trigger("slide",[W(i).clientX,W(i).clientY,true]);return!(a.rows>1||a.orbital||d(P))}).bind(ub,function(){g.trigger("up",[true]);return false}).bind(vb,function(){g.trigger("up",[true]);return false})}else e.css({cursor:"url("+Wa+"), "+wa}).bind(wb,function(i,k){g.trigger("wheel",[k]);return false}).bind(xb,function(){g.trigger("play")}).bind(a.clickfree?
yb:zb,function(i){g.trigger("down",[i.clientX,i.clientY]);return false}).bind(a.clickfree?Ab:"",function(){g.trigger("up");return false}).disableTextSelect();a.hint&&e.attr(Bb,a.hint);a.monitor&&b.append(xa=h(O,{"class":Cb,css:{position:aa,left:0,top:0}}))||(xa=h());a.indicator&&b.append(Xa("x"));a.rows>1&&a.indicator&&b.append(Xa("y"));g.trigger("preload")},preload:function(f){var b=d(C),e=g.parent(),i=d(Ya),k=a.images,l=!k.length?[i]:[].concat(k),n=g[0];n.frames=l.length;n.preloaded=0;g.trigger("stop");
for(e.append(ya=h(O,{"class":Db,css:{position:aa,left:0,top:b.y-a.preloader,height:a.preloader,overflow:pa,backgroundColor:ta}}));l.length;){var s=a.path+l.shift(),y=h(new Image).hide().bind("load"+q,function(){n.preloaded++;h(this).unbind(q);ya.css({width:1/n.frames*n.preloaded*b.x});if(n.frames==n.preloaded){ya.remove();k.length||g.css({backgroundImage:na(a.path+i)});g.attr({src:Eb}).trigger(a.rows>1&&!a.stitched?"rowChange":"frameChange").trigger("loaded").trigger("opening");m.call(f)}});e.append(y);
setTimeout(function(za,Q){return function(){za.attr({src:Q})}}(y,s),0)}},tick:function(f){var b=d(I);if(R){var e=H(b-d(Za)/A(D)*R);b=!(b*e<=0||b<u(e))&&c(I,b>u(d(Aa))?e:(R=F=0))}xa.text(d(a.monitor));b&&R++;F&&F++;$a(0);Ba=true;if(F&&!b)return m.call(f);if(d(ba))return m.call(f,J());e=d(ca)*oa(1,d(G));var i=(d(Ca)?b:u(d(Aa))+b)/A(D);b=d(o);e=c(o,b-i*e);m.call(f);e!=b&&g.trigger("fractionChange")},opening:function(){var f=a.entry||a.speed,b=d(o),e=a.opening;c(o,b-f*a.opening);c(da,e*A(D));B.bind(E,
v.opening_tick)},opening_tick:function(f){var b=(a.entry||a.speed)/A(D)*(a.cw?-1:1),e=d(o);c(o,H(e+b));b=c(da,d(da)-1);g.trigger("fractionChange");m.call(f);if(!(b>1)){B.unbind(E,v.opening_tick);Fb()}},play:function(f){var b=c(Da,true);c(Ca,!b);ab();m.call(f)},pause:function(f){c(Da,false);J();m.call(f)},stop:function(f){var b=c(Ca,true);c(Da,!b);m.call(f)},down:function(f,b,e,i){if(a.draggable){c(ba,d(x));c(I,0);ea=fa(b,e,d(o),d(ga),d(z));J();Z();if(!i){$.css({cursor:na(Gb)+", "+wa}).bind(ra,function(k){g.trigger("slide",
[k.clientX,k.clientY]);m.call(k);return false});a.clickfree||$.bind(qa,function(k){g.trigger("up");m.call(k)})}}m.call(f)},up:function(f,b){if(!a.draggable)return m.call(f);c(ba,false);c(P,false);var e=c(I,!a.throwable?0:u(S[0]+S[1])/60);R=e?1:0;e?ab():J();Z();!b&&$.unbind(qa).unbind(ra)&&d(Va).css({cursor:na(Wa)+", "+wa});m.call(f)},slide:function(f,b,e){if(a.draggable&&Ba){Ba=false;J();var i={x:b-ea.x,y:e-ea.y};if(u(i.x)>0||u(i.y)>0){ea={x:b,y:e};var k=d(ga),l=d(bb),n=d(K),s=c(o,cb(n?e-l.y:b-l.x,
d(Ea),k,d(Fa),d(Ga),d(ca)));c(P,d(P)||d(x)!=d(ba));(i=$a(n?i.y:i.x||0))&&c(G,i<0);if(a.orbital&&d(Ha)){c(K,u(e-l.y)>u(b-l.x));l=fa(b,e,s,k,d(z))}if(a.rows>1){i=d(C).y;n=d(db);var y=-n*i;c(z,H(h.reel.math.envelope(e-l.y,n,i,y,y+i,-1)))}!(s%1)&&!a.loops&&fa(b,e,s,k,d(z));g.trigger("fractionChange")}}m.call(f)},wheel:function(f,b){if(!a.wheelable||!b)return m.call(f);var e=eb(Hb(u(b))/2);e=oa(e,b>0);b=0.2*d(ga);fa(p,p,d(o),b,d(z));c(o,cb(e,d(Ea),b,d(Fa),d(Ga),d(ca)));e&&c(G,e<0);c(I,0);J();m.call(f);
g.trigger("fractionChange");return false},fractionChange:function(f,b){b=!b?d(o):c(o,b);b=a.loops?b-T(b):V(0,1,b);b=c(o,H(b));var e=d(x),i=c(x,1+T(b/d(ha))),k=a.orbital;c(Ha,!!k&&(i<=k||i>=a.footage-k+2));if(!a.loops&&a.rebound){!F&&!(b%1)?Ia++:(Ia=0);Ia>=a.rebound*1E3/A(D)&&c(G,!d(G))}k=d(C);var l=(d(K)?k.y:k.x)-a.indicator;b=V(0,l,U(h.reel.math.interpolate(b,-1,l+2)));b=!a.cw||a.stitched?b:l-b;h(la(Ja+".x"),d(Y)).css(d(K)?{left:0,top:b}:{left:b,top:k.y-a.indicator});if(a.rows>1){b=d(C).y-a.indicator;
b=V(0,b,U(h.reel.math.interpolate(d(z),-1,b+2)));h(la(Ja+".y"),d(Y)).css({top:b})}if(i==e&&i!=1)return m.call(f);g.trigger(a.rows>1?"rowChange":"frameChange");m.call(f)},rowChange:function(f,b){var e=T(d(o)/d(ha))+1;b=c(z,V(0,1,H(b!=p?(b-1)/(a.rows-1):d(z))));c(x,e+(a.rows<=1?0:U(b*(a.rows-1))*a.frames));m.call(f);g.trigger("frameChange")},frameChange:function(f,b){var e=!b?d(o):c(o,H(d(ha)*(b-1)));b=c(x,U(b?b:d(x)));var i=a.images,k=a.footage,l=d(C),n=a.horizontal;if(d(K)){b=a.inversed?k+1-b:b;b+=
k}if(i.length)g.attr({src:a.path+i[b-1]});else{if(a.stitched)i=[-U(e*d(fb))+L,0+L];else{e=b%k-1;e=e<0?k-1:e;k=T((b-0.1)/k);k+=a.rows>1?0:d(G)?0:d(va);b=d(gb);k=k*((n?l.y:l.x)+b);l=e*((n?l.x:l.y)+b);i=i.length?[0,0]:n?[-l+L,-k+L]:[-k+L,-l+L]}g.css({backgroundPosition:i.join(Ka)})}m.call(f)}},m=function(f){hb||delete this;return f},F,R=0,ab=function(){return F=0},J=function(){clearTimeout(ib);B.unbind(E,v.opening_tick);g.trigger("play");return F=-a.timeout*A(D)},ib,Fb=function(){ib=setTimeout(function(){g.trigger("play")},
a.delay*1E3||0)},xa,ya,Xa=function(f){return h(O,{"class":[Ja,f].join(Ka),css:{width:a.indicator,height:a.indicator,overflow:pa,top:d(C).y-a.indicator,left:0,position:aa,backgroundColor:ta}})},Ia=0,ea={x:0,y:0},$a=function(f){return S.push(f)&&S.shift()&&f},Z=function(){return S=[0,0]},S=Z(),cb=a.graph||h.reel.math[a.loops?"hatch":"envelope"],fa=function(f,b,e,i,k){c(Ea,e);c(db,k);c(Fa,a.loops?0:-e*i);c(Ga,a.loops?i:i-e*i);return f&&c(bb,{x:f,y:b})||p},Ba=true,$=h.browser.opera?B:h.unique(B.add(kb.top.document));
(function(f){if(g.hasClass(w))return m.call(f);var b=g.attr(Na),e=c(M,g.attr(M)||g.attr(M,w+"-"+ +new Date).attr(M)),i=g.attr("style"),k=a.images,l=a.stitched,n=a.loops,s={x:X(g.css(Oa)),y:X(g.css(Pa))},y=c(Ua,a.orbital&&a.footage||a.rows<=1&&k.length||a.frames),za=l?1:eb(y/a.footage),Q={display:"block",width:s.x,height:s.y};e="#"+e+a.suffix;var jb=g.attr("class"),La={position:"relative",width:s.x,height:s.y};La=h(O,{id:e.substr(1),"class":jb+Ka+Ib,css:La});Q=g.wrap(La).attr({"class":w}).css(Q).bind(v);
t.push(lb(Q)[0]);c(Ya,k.length&&k.length||a.image||b.replace(/^(.*)\.(jpg|jpeg|png|gif)$/,"$1"+a.suffix+".$2"));c(Ta,jb);c(x,a.frame);c(gb,a.spacing);c(C,s);c(o,0);c(sa,a.steps||a.frames);c(ga,a.revolution||l/2||s.x*2);c(va,za);c(ha,1/(y-(n&&!l?0:1)));c(Jb,1/N(y,d(sa)));c(ua,l);c(fb,l-(n?0:s.x));c(Y,e);c(G,c(Aa,a.speed)<0);c(I,0);c(K,a.vertical);c(z,(a.row-1)/(a.rows-1));c(ca,oa(1,!a.cw&&!l));c(P,false);c(Za,a.brake);c(Ha,!!a.orbital);c(D,a.tempo/(h.reel.lazy?a.laziness:1));c(da,0);c(Sa,{src:b,style:i||
Qa});B.bind(E,v.tick);m.call(f);g.trigger("setup")})()});ia=ia||function g(){var r=+new Date,c=A(D);if(c){B.trigger(E);h.reel.cost=(+new Date+h.reel.cost-r)/2;return ia=setTimeout(g,N(4,1E3/c-h.reel.cost))}else return ia=p}();return h(t)};h.reel.math={envelope:function(j,a,t,g,r,c){return a+N(g,Ma(r,-j*c))/t},hatch:function(j,a,t,g,r,c){j=(j<g?r:0)+j%r;j=a+-j*c/t;return j-T(j)},interpolate:function(j,a,t){return a+j*(t-a)}};h.reel.touchy=/iphone|ipod|ipad|android/i.test(navigator.userAgent);h.reel.lazy=
/iphone|ipod|android/i.test(navigator.userAgent);h.reel.instances=h();h.reel.cost=0;h.reel.leader=A;pb("mousewheel disableTextSelect enableTextSelect".split(/ /));var B=h(ja);ja=+h.browser.version.split(".").slice(0,2).join(".");var hb=h.browser.msie,nb=!(hb&&ja<8),wa="ew-resize",ia,w="jquery-reel",Ib=w+"-overlay",Ja=w+"-indicator",Db=w+"-preloader",Cb=w+"-monitor",rb=w+"-interface",Eb=ka("CAAIAIAAAAAAAAAAACH5BAEAAAAALAAAAAAIAAgAAAIHhI+py+1dAAA7")||ma("blank.gif"),Wa=ka("EAAQAJECAAAAAP///////wAAACH5BAEAAAIALAAAAAAQABAAQAI3lC8AeBDvgosQxQtne7yvLWGStVBelXBKqDJpNzLKq3xWBlU2nUs4C/O8cCvU0EfZGUwt19FYAAA7")||
ma("jquery.reel.cursor-drag.gif"),Gb=ka("EAAQAJECAAAAAP///////wAAACH5BAEAAAIALAAAAAAQABAAQAIslI95EB3MHECxNjBVdE/5b2zcRV1QBabqhwltq41St4hj5konmVioZ6OtEgUAOw==")||ma("jquery.reel.cursor-drag-down.gif"),U=Math.round,T=Math.floor,eb=Math.ceil,Ma=Math.min,N=Math.max,u=Math.abs,Hb=Math.sqrt,X=parseInt,Va="area",Sa="backup",G="backwards",ha="bit",Za="brake",Ha="center",Ta="classes",ba="clicked",bb="clicked_location",Ea="clicked_on",db="clicked_row",ca="cwish",C="dimensions",o="fraction",x="frame",Ua="frames",
Ga="hi",pa="hidden",Ya="image",da="opening_ticks",Fa="lo",Da="playing",P="reeling",ga="revolution",z="row",va="rows",gb="spacing",Aa="speed",Y="stage",sa="steps",ua="stitched",fb="stitched_travel",Ca="stopped",D="tempo",I="velocity",K="vertical",Jb="wheel_step",q=".reel",xb="dblclick"+q,zb="mousedown"+q,yb="mouseenter"+q,Ab="mouseleave"+q,ra="mousemove"+q,qa="mouseup"+q,wb="mousewheel"+q,E="tick"+q,vb="touchcancel"+q,ub="touchend"+q,sb="touchstart"+q,tb="touchmove"+q,Qa="",Ka=" ",aa="absolute",Ra=
"div",O=ob(Ra),Pa="height",ta="#000",M="id",qb="img",L="px",Na="src",Bb="title",Oa="width"}(jQuery,window,document);