forked from fredleblanc/roundabout
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.roundabout.min.js
41 lines (41 loc) · 17.7 KB
/
jquery.roundabout.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
36
37
38
39
40
41
/**
* jQuery Roundabout - v2.4.2
* http://fredhq.com/projects/roundabout
*
* Moves list-items of enabled ordered and unordered lists long
* a chosen path. Includes the default "lazySusan" path, that
* moves items long a spinning turntable.
*
* Terms of Use // jQuery Roundabout
*
* Open source under the BSD license
*
* Copyright (c) 2011-2012, Fred LeBlanc
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* - Neither the name of the author nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
(function(c){var d,f,b;var a=function(g,m){var j,l=g.split(/\./i),k=m.split(/\./i),h=(l.length>k.length)?l.length:k.length;for(j=0;j<=h;j++){if(l[j]&&!k[j]&&parseInt(l[j],10)!==0){return 1}else{if(k[j]&&!l[j]&&parseInt(k[j],10)!==0){return -1}else{if(l[j]===k[j]){continue}}}if(l[j]&&k[j]){if(parseInt(l[j],10)>parseInt(k[j],10)){return 1}else{return -1}}}return 0};var e=a.apply(null,[c.fn.jquery,"1.7.2"])>=0&&(a.apply(null,[c.ui.version,"1.9.1"])>=0||!c.easing.easeOutBack);c.extend({roundaboutShapes:{def:"lazySusan",lazySusan:function(i,g,h){return{x:Math.sin(i+g),y:(Math.sin(i+3*Math.PI/2+g)/8)*h,z:(Math.cos(i+g)+1)/2,scale:(Math.sin(i+Math.PI/2+g)/2)+0.5}}}});d={bearing:0,tilt:0,minZ:100,maxZ:280,minOpacity:0.4,maxOpacity:1,minScale:0.4,maxScale:1,duration:600,btnNext:null,btnNextCallback:function(){},btnPrev:null,btnPrevCallback:function(){},btnToggleAutoplay:null,btnStartAutoplay:null,btnStopAutoplay:null,easing:"swing",clickToFocus:true,clickToFocusCallback:function(){},focusBearing:0,shape:"lazySusan",debug:false,childSelector:"li",startingChild:null,reflect:false,floatComparisonThreshold:0.001,autoplay:false,autoplayDuration:1000,autoplayPauseOnHover:false,autoplayCallback:function(){},autoplayInitialDelay:0,enableDrag:false,dropDuration:600,dropEasing:"swing",dropAnimateTo:"nearest",dropCallback:function(){},dragAxis:"x",dragFactor:4,triggerFocusEvents:true,triggerBlurEvents:true,responsive:false};f={autoplayInterval:null,autoplayIsRunning:false,autoplayStartTimeout:null,animating:false,childInFocus:-1,touchMoveStartPosition:null,stopAnimation:false,lastAnimationStep:false};b={init:function(h,k,j){var i,g=(new Date()).getTime();h=(typeof h==="object")?h:{};k=(c.isFunction(k))?k:function(){};k=(c.isFunction(h))?h:k;i=c.extend({},d,h,f);return this.each(function(){var m=c(this),l=m.children(i.childSelector).length,p=360/l,o=(i.startingChild&&i.startingChild>(l-1))?(l-1):i.startingChild,n=(i.startingChild===null)?i.bearing:360-(o*p),q=(m.css("position")!=="static")?m.css("position"):"relative";m.css({padding:0,position:q}).addClass("roundabout-holder").data("roundabout",c.extend({},i,{startingChild:o,bearing:n,oppositeOfFocusBearing:b.normalize.apply(null,[i.focusBearing-180]),dragBearing:n,period:p}));if(j){m.unbind(".roundabout").children(i.childSelector).unbind(".roundabout")}else{if(i.responsive){c(window).bind("resize",function(){b.stopAutoplay.apply(m);b.relayoutChildren.apply(m)})}}if(i.clickToFocus){m.children(i.childSelector).each(function(r){c(this).bind("click.roundabout",function(){var s=b.getPlacement.apply(m,[r]);if(!b.isInFocus.apply(m,[s])){b.stopAnimation.apply(c(this));if(!m.data("roundabout").animating){b.animateBearingToFocus.apply(m,[s,m.data("roundabout").clickToFocusCallback])}return false}})})}if(i.btnNext){c(i.btnNext).bind("click.roundabout",function(){if(!m.data("roundabout").animating){b.animateToNextChild.apply(m,[m.data("roundabout").btnNextCallback])}return false})}if(i.btnPrev){c(i.btnPrev).bind("click.roundabout",function(){b.animateToPreviousChild.apply(m,[m.data("roundabout").btnPrevCallback]);return false})}if(i.btnToggleAutoplay){c(i.btnToggleAutoplay).bind("click.roundabout",function(){b.toggleAutoplay.apply(m);return false})}if(i.btnStartAutoplay){c(i.btnStartAutoplay).bind("click.roundabout",function(){b.startAutoplay.apply(m);return false})}if(i.btnStopAutoplay){c(i.btnStopAutoplay).bind("click.roundabout",function(){b.stopAutoplay.apply(m);return false})}if(i.autoplayPauseOnHover){m.bind("mouseenter.roundabout.autoplay",function(){b.stopAutoplay.apply(m,[true])}).bind("mouseleave.roundabout.autoplay",function(){b.startAutoplay.apply(m)})}if(i.enableDrag){if(!c.isFunction(m.drag)){if(i.debug){alert("You do not have the drag plugin loaded.")}}else{if(!c.isFunction(m.drop)){if(i.debug){alert("You do not have the drop plugin loaded.")}}else{m.drag(function(t,r){var s=m.data("roundabout"),u=(s.dragAxis.toLowerCase()==="x")?"deltaX":"deltaY";b.stopAnimation.apply(m);b.setBearing.apply(m,[s.dragBearing+r[u]/s.dragFactor])}).drop(function(s){var r=m.data("roundabout"),t=b.getAnimateToMethod(r.dropAnimateTo);b.allowAnimation.apply(m);b[t].apply(m,[r.dropDuration,r.dropEasing,r.dropCallback]);r.dragBearing=r.period*b.getNearestChild.apply(m)})}}m.each(function(){var r=c(this).get(0),t=c(this).data("roundabout"),s=(t.dragAxis.toLowerCase()==="x")?"pageX":"pageY",u=b.getAnimateToMethod(t.dropAnimateTo);if(r.addEventListener){r.addEventListener("touchstart",function(v){t.touchMoveStartPosition=v.touches[0][s]},false);r.addEventListener("touchmove",function(v){var w=(v.touches[0][s]-t.touchMoveStartPosition)/t.dragFactor;v.preventDefault();b.stopAnimation.apply(c(this));b.setBearing.apply(c(this),[t.dragBearing+w])},false);r.addEventListener("touchend",function(v){v.preventDefault();b.allowAnimation.apply(c(this));u=b.getAnimateToMethod(t.dropAnimateTo);b[u].apply(c(this),[t.dropDuration,t.dropEasing,t.dropCallback]);t.dragBearing=t.period*b.getNearestChild.apply(c(this))},false)}})}b.initChildren.apply(m,[k,j])})},initChildren:function(j,h){var g=c(this),i=g.data("roundabout");j=j||function(){};g.children(i.childSelector).each(function(n){var l,k,m,o=b.getPlacement.apply(g,[n]);if(h&&c(this).data("roundabout")){l=c(this).data("roundabout").startWidth;k=c(this).data("roundabout").startHeight;m=c(this).data("roundabout").startFontSize}c(this).addClass("roundabout-moveable-item").css("position","absolute");c(this).data("roundabout",{startWidth:l||c(this).width(),startHeight:k||c(this).height(),startFontSize:m||parseInt(c(this).css("font-size"),10),degrees:o,backDegrees:b.normalize.apply(null,[o-180]),childNumber:n,currentScale:1,parent:g})});b.updateChildren.apply(g);if(i.autoplay){i.autoplayStartTimeout=setTimeout(function(){b.startAutoplay.apply(g)},i.autoplayInitialDelay)}g.trigger("ready");j.apply(g);return g},updateChildren:function(){return this.each(function(){var g=c(this),h=g.data("roundabout"),j=-1,i={bearing:h.bearing,tilt:h.tilt,stage:{width:Math.floor(c(this).width()*0.9),height:Math.floor(c(this).height()*0.9)},animating:h.animating,inFocus:h.childInFocus,focusBearingRadian:b.degToRad.apply(null,[h.focusBearing]),shape:c.roundaboutShapes[h.shape]||c.roundaboutShapes[c.roundaboutShapes.def]};i.midStage={width:i.stage.width/2,height:i.stage.height/2};i.nudge={width:i.midStage.width+(i.stage.width*0.05),height:i.midStage.height+(i.stage.height*0.05)};i.zValues={min:h.minZ,max:h.maxZ,diff:h.maxZ-h.minZ};i.opacity={min:h.minOpacity,max:h.maxOpacity,diff:h.maxOpacity-h.minOpacity};i.scale={min:h.minScale,max:h.maxScale,diff:h.maxScale-h.minScale};g.children(h.childSelector).each(function(k){if(b.updateChild.apply(g,[c(this),i,k,function(){c(this).trigger("ready")}])&&(!i.animating||h.lastAnimationStep)){j=k;c(this).addClass("roundabout-in-focus")}else{c(this).removeClass("roundabout-in-focus")}});if(j!==i.inFocus){if(h.triggerBlurEvents){g.children(h.childSelector).eq(i.inFocus).trigger("blur")}h.childInFocus=j;if(h.triggerFocusEvents&&j!==-1){g.children(h.childSelector).eq(j).trigger("focus")}}g.trigger("childrenUpdated")})},updateChild:function(j,i,g,o){var n,p=this,h=c(j),l=h.data("roundabout"),k=[],m=b.degToRad.apply(null,[(360-l.degrees)+i.bearing]);o=o||function(){};m=b.normalizeRad.apply(null,[m]);n=i.shape(m,i.focusBearingRadian,i.tilt);n.scale=(n.scale>1)?1:n.scale;n.adjustedScale=(i.scale.min+(i.scale.diff*n.scale)).toFixed(4);n.width=(n.adjustedScale*l.startWidth).toFixed(4);n.height=(n.adjustedScale*l.startHeight).toFixed(4);h.css({left:((n.x*i.midStage.width+i.nudge.width)-n.width/2).toFixed(0)+"px",top:((n.y*i.midStage.height+i.nudge.height)-n.height/2).toFixed(0)+"px",width:n.width+"px",height:n.height+"px",opacity:(i.opacity.min+(i.opacity.diff*n.scale)).toFixed(2),zIndex:Math.round(i.zValues.min+(i.zValues.diff*n.z)),fontSize:(n.adjustedScale*l.startFontSize).toFixed(1)+"px"});l.currentScale=n.adjustedScale;if(p.data("roundabout").debug){k.push('<div style="font-weight: normal; font-size: 10px; padding: 2px; width: '+h.css("width")+'; background-color: #ffc;">');k.push('<strong style="font-size: 12px; white-space: nowrap;">Child '+g+"</strong><br />");k.push("<strong>left:</strong> "+h.css("left")+"<br />");k.push("<strong>top:</strong> "+h.css("top")+"<br />");k.push("<strong>width:</strong> "+h.css("width")+"<br />");k.push("<strong>opacity:</strong> "+h.css("opacity")+"<br />");k.push("<strong>height:</strong> "+h.css("height")+"<br />");k.push("<strong>z-index:</strong> "+h.css("z-index")+"<br />");k.push("<strong>font-size:</strong> "+h.css("font-size")+"<br />");k.push("<strong>scale:</strong> "+h.data("roundabout").currentScale);k.push("</div>");h.html(k.join(""))}h.trigger("reposition");o.apply(p);return b.isInFocus.apply(p,[l.degrees])},setBearing:function(g,h){h=h||function(){};g=b.normalize.apply(null,[g]);this.each(function(){var n,i,l,k=c(this),m=k.data("roundabout"),j=m.bearing;m.bearing=g;k.trigger("bearingSet");b.updateChildren.apply(k);n=Math.abs(j-g);if(!m.animating||n>180){return}n=Math.abs(j-g);k.children(m.childSelector).each(function(p){var o;if(b.isChildBackDegreesBetween.apply(c(this),[g,j])){o=(j>g)?"Clockwise":"Counterclockwise";c(this).trigger("move"+o+"ThroughBack")}})});h.apply(this);return this},adjustBearing:function(h,g){g=g||function(){};if(h===0){return this}this.each(function(){b.setBearing.apply(c(this),[c(this).data("roundabout").bearing+h])});g.apply(this);return this},setTilt:function(g,h){h=h||function(){};this.each(function(){c(this).data("roundabout").tilt=g;b.updateChildren.apply(c(this))});h.apply(this);return this},adjustTilt:function(h,g){g=g||function(){};this.each(function(){b.setTilt.apply(c(this),[c(this).data("roundabout").tilt+h])});g.apply(this);return this},animateToBearing:function(h,i,l,j,k){var g=(new Date()).getTime();k=k||function(){};if(c.isFunction(j)){k=j;j=null}else{if(c.isFunction(l)){k=l;l=null}else{if(c.isFunction(i)){k=i;i=null}}}this.each(function(){var s,r,m,n=c(this),q=n.data("roundabout"),o=(!i)?q.duration:i,p=(l)?l:q.easing||"swing";if(!j){j={timerStart:g,start:q.bearing,totalTime:o}}s=g-j.timerStart;if(q.stopAnimation){b.allowAnimation.apply(n);q.animating=false;return}if(s<o){if(!q.animating){n.trigger("animationStart")}q.animating=true;if(typeof c.easing.def==="string"){r=c.easing[p]||c.easing[c.easing.def];m=r(null,s,j.start,h-j.start,j.totalTime)}else{m=c.easing[p]((s/j.totalTime),s,j.start,h-j.start,j.totalTime)}if(e){m=j.start+((h-j.start)*m)}m=b.normalize.apply(null,[m]);q.dragBearing=m;b.setBearing.apply(n,[m,function(){setTimeout(function(){b.animateToBearing.apply(n,[h,o,p,j,k])},0)}])}else{q.lastAnimationStep=true;h=b.normalize.apply(null,[h]);b.setBearing.apply(n,[h,function(){n.trigger("animationEnd")}]);q.animating=false;q.lastAnimationStep=false;q.dragBearing=h;k.apply(n)}});return this},animateToNearbyChild:function(g,i){var h=g[0],k=g[1],j=g[2]||function(){};if(c.isFunction(k)){j=k;k=null}else{if(c.isFunction(h)){j=h;h=null}}return this.each(function(){var o,m,l=c(this),q=l.data("roundabout"),n=(!q.reflect)?q.bearing%360:q.bearing,p=l.children(q.childSelector).length;if(!q.animating){if((q.reflect&&i==="previous")||(!q.reflect&&i==="next")){n=(Math.abs(n)<q.floatComparisonThreshold)?360:n;for(o=0;o<p;o+=1){m={lower:(q.period*o),upper:(q.period*(o+1))};m.upper=(o===p-1)?360:m.upper;if(n<=Math.ceil(m.upper)&&n>=Math.floor(m.lower)){if(p===2&&n===360){b.animateToDelta.apply(l,[-180,h,k,j])}else{b.animateBearingToFocus.apply(l,[m.lower,h,k,j])}break}}}else{n=(Math.abs(n)<q.floatComparisonThreshold||360-Math.abs(n)<q.floatComparisonThreshold)?0:n;for(o=p-1;o>=0;o-=1){m={lower:q.period*o,upper:q.period*(o+1)};m.upper=(o===p-1)?360:m.upper;if(n>=Math.floor(m.lower)&&n<Math.ceil(m.upper)){if(p===2&&n===360){b.animateToDelta.apply(l,[180,h,k,j])}else{b.animateBearingToFocus.apply(l,[m.upper,h,k,j])}break}}}}})},animateToNearestChild:function(g,i,h){h=h||function(){};if(c.isFunction(i)){h=i;i=null}else{if(c.isFunction(g)){h=g;g=null}}return this.each(function(){var j=b.getNearestChild.apply(c(this));b.animateToChild.apply(c(this),[j,g,i,h])})},animateToChild:function(g,h,j,i){i=i||function(){};if(c.isFunction(j)){i=j;j=null}else{if(c.isFunction(h)){i=h;h=null}}return this.each(function(){var m,k=c(this),l=k.data("roundabout");if(l.childInFocus!==g&&!l.animating){m=k.children(l.childSelector).eq(g);b.animateBearingToFocus.apply(k,[m.data("roundabout").degrees,h,j,i])}})},animateToNextChild:function(g,i,h){return b.animateToNearbyChild.apply(this,[arguments,"next"])},animateToPreviousChild:function(g,i,h){return b.animateToNearbyChild.apply(this,[arguments,"previous"])},animateToDelta:function(h,g,j,i){i=i||function(){};if(c.isFunction(j)){i=j;j=null}else{if(c.isFunction(g)){i=g;g=null}}return this.each(function(){var k=c(this).data("roundabout").bearing+h;b.animateToBearing.apply(c(this),[k,g,j,i])})},animateBearingToFocus:function(h,g,j,i){i=i||function(){};if(c.isFunction(j)){i=j;j=null}else{if(c.isFunction(g)){i=g;g=null}}return this.each(function(){var k=c(this).data("roundabout").bearing-h;k=(Math.abs(360-k)<Math.abs(k))?360-k:-k;k=(k>180)?-(360-k):k;if(k!==0){b.animateToDelta.apply(c(this),[k,g,j,i])}})},stopAnimation:function(){return this.each(function(){c(this).data("roundabout").stopAnimation=true})},allowAnimation:function(){return this.each(function(){c(this).data("roundabout").stopAnimation=false})},startAutoplay:function(g){return this.each(function(){var h=c(this),i=h.data("roundabout");g=g||i.autoplayCallback||function(){};clearInterval(i.autoplayInterval);i.autoplayInterval=setInterval(function(){b.animateToNextChild.apply(h,[g])},i.autoplayDuration);i.autoplayIsRunning=true;h.trigger("autoplayStart")})},stopAutoplay:function(g){return this.each(function(){clearInterval(c(this).data("roundabout").autoplayInterval);c(this).data("roundabout").autoplayInterval=null;c(this).data("roundabout").autoplayIsRunning=false;if(!g){c(this).unbind(".autoplay")}c(this).trigger("autoplayStop")})},toggleAutoplay:function(g){return this.each(function(){var h=c(this),i=h.data("roundabout");g=g||i.autoplayCallback||function(){};if(!b.isAutoplaying.apply(c(this))){b.startAutoplay.apply(c(this),[g])}else{b.stopAutoplay.apply(c(this),[g])}})},isAutoplaying:function(){return(this.data("roundabout").autoplayIsRunning)},changeAutoplayDuration:function(g){return this.each(function(){var h=c(this),i=h.data("roundabout");i.autoplayDuration=g;if(b.isAutoplaying.apply(h)){b.stopAutoplay.apply(h);setTimeout(function(){b.startAutoplay.apply(h)},10)}})},normalize:function(h){var g=h%360;return(g<0)?360+g:g},normalizeRad:function(g){while(g<0){g+=(Math.PI*2)}while(g>(Math.PI*2)){g-=(Math.PI*2)}return g},isChildBackDegreesBetween:function(h,g){var i=c(this).data("roundabout").backDegrees;if(h>g){return(i>=g&&i<h)}else{return(i<g&&i>=h)}},getAnimateToMethod:function(g){g=g.toLowerCase();if(g==="next"){return"animateToNextChild"}else{if(g==="previous"){return"animateToPreviousChild"}}return"animateToNearestChild"},relayoutChildren:function(){return this.each(function(){var g=c(this),h=c.extend({},g.data("roundabout"));h.startingChild=g.data("roundabout").childInFocus;b.init.apply(g,[h,null,true])})},getNearestChild:function(){var g=c(this),i=g.data("roundabout"),h=g.children(i.childSelector).length;if(!i.reflect){return((h)-(Math.round(i.bearing/i.period)%h))%h}else{return(Math.round(i.bearing/i.period)%h)}},degToRad:function(g){return b.normalize.apply(null,[g])*Math.PI/180},getPlacement:function(h){var g=this.data("roundabout");return(!g.reflect)?360-(g.period*h):g.period*h},isInFocus:function(k){var j,g=this,i=g.data("roundabout"),h=b.normalize.apply(null,[i.bearing]);k=b.normalize.apply(null,[k]);j=Math.abs(h-k);return(j<=i.floatComparisonThreshold||j>=360-i.floatComparisonThreshold)},getChildInFocus:function(){var g=c(this).data("roundabout");return(g.childInFocus>-1)?g.childInFocus:false}};c.fn.roundabout=function(g){if(b[g]){return b[g].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof g==="object"||c.isFunction(g)||!g){return b.init.apply(this,arguments)}else{c.error("Method "+g+" does not exist for jQuery.roundabout.")}}}})(jQuery);