diff --git a/jquery.roundabout.js b/jquery.roundabout.js index df83da2..f112c61 100644 --- a/jquery.roundabout.js +++ b/jquery.roundabout.js @@ -169,7 +169,7 @@ } else { // bind responsive action if (settings.responsive) { - $(window).bind("resize", function() { + $(window).bind("resize.roundabout", function() { methods.stopAutoplay.apply(self); methods.relayoutChildren.apply(self); }); @@ -1179,6 +1179,65 @@ // nothing was triggered, versions are the same return 0; + }, + + + + // destroy + // ----------------------------------------------------------------------- + + // destroy + // destroys roundabout instance, returning all code to its original state + destroy: function() { + var self = $(this), + data = self.data("roundabout"); + + // Unbind window listeners + $(window).unbind(".roundabout"); + + // Unset classes and css on self + self + .removeClass("roundabout-holder") + .removeAttr("style"); + + // Unset classes and css on children + self + .children(data.childSelector) + .removeClass("roundabout-moveable-item") + .removeClass("roundabout-in-focus") + .removeData("roundabout") + .removeAttr("style"); + + // Universal unbind + self + .children(data.childSelector) + .andSelf() + .unbind(".roundabout") + .unbind(".roundabout.autoplay"); + + // un-bind buttons + if (data.btnNext) { + $(data.btnNext).unbind(".roundabout"); + } + if (data.btnPrev) { + $(data.btnPrev).bind(".roundabout"); + } + if (data.btnToggleAutoplay) { + $(data.btnToggleAutoplay).bind(".roundabout"); + } + if (data.btnStartAutoplay) { + $(data.btnStartAutoplay).bind(".roundabout"); + } + if (data.btnStopAutoplay) { + $(data.btnStopAutoplay).bind(".roundabout"); + } + + + // @todo: Can we namespace the element.addEventListeners set in the "// on mobile" section? + + // Remove all assigned Data + self + .removeData("roundabout"); } }; diff --git a/jquery.roundabout.min.js b/jquery.roundabout.min.js index b6f4935..782d4f0 100644 --- a/jquery.roundabout.min.js +++ b/jquery.roundabout.min.js @@ -38,4 +38,4 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -(function(a){"use strict";var b,c,d;a.extend({roundaboutShapes:{def:"lazySusan",lazySusan:function(a,b,c){return{x:Math.sin(a+b),y:Math.sin(a+3*Math.PI/2+b)/8*c,z:(Math.cos(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+.5}}}});b={bearing:0,tilt:0,minZ:100,maxZ:280,minOpacity:.4,maxOpacity:1,minScale:.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:.001,autoplay:false,autoplayDuration:1e3,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};c={autoplayInterval:null,autoplayIsRunning:false,autoplayStartTimeout:null,animating:false,childInFocus:-1,touchMoveStartPosition:null,stopAnimation:false,lastAnimationStep:false};d={init:function(e,f,g){var h,i=(new Date).getTime();e=typeof e==="object"?e:{};f=a.isFunction(f)?f:function(){};f=a.isFunction(e)?e:f;h=a.extend({},b,e,c);return this.each(function(){var b=a(this),c=b.children(h.childSelector).length,e=360/c,i=h.startingChild&&h.startingChild>c-1?c-1:h.startingChild,j=h.startingChild===null?h.bearing:360-i*e,k=b.css("position")!=="static"?b.css("position"):"relative";b.css({padding:0,position:k}).addClass("roundabout-holder").data("roundabout",a.extend({},h,{startingChild:i,bearing:j,oppositeOfFocusBearing:d.normalize.apply(null,[h.focusBearing-180]),dragBearing:j,period:e}));if(g){b.unbind(".roundabout").children(h.childSelector).unbind(".roundabout")}else{if(h.responsive){a(window).bind("resize",function(){d.stopAutoplay.apply(b);d.relayoutChildren.apply(b)})}}if(h.clickToFocus){b.children(h.childSelector).each(function(c){a(this).bind("click.roundabout",function(){var e=d.getPlacement.apply(b,[c]);if(!d.isInFocus.apply(b,[e])){d.stopAnimation.apply(a(this));if(!b.data("roundabout").animating){d.animateBearingToFocus.apply(b,[e,b.data("roundabout").clickToFocusCallback])}return false}})})}if(h.btnNext){a(h.btnNext).bind("click.roundabout",function(){if(!b.data("roundabout").animating){d.animateToNextChild.apply(b,[b.data("roundabout").btnNextCallback])}return false})}if(h.btnPrev){a(h.btnPrev).bind("click.roundabout",function(){d.animateToPreviousChild.apply(b,[b.data("roundabout").btnPrevCallback]);return false})}if(h.btnToggleAutoplay){a(h.btnToggleAutoplay).bind("click.roundabout",function(){d.toggleAutoplay.apply(b);return false})}if(h.btnStartAutoplay){a(h.btnStartAutoplay).bind("click.roundabout",function(){d.startAutoplay.apply(b);return false})}if(h.btnStopAutoplay){a(h.btnStopAutoplay).bind("click.roundabout",function(){d.stopAutoplay.apply(b);return false})}if(h.autoplayPauseOnHover){b.bind("mouseenter.roundabout.autoplay",function(){d.stopAutoplay.apply(b,[true])}).bind("mouseleave.roundabout.autoplay",function(){d.startAutoplay.apply(b)})}if(h.enableDrag){if(!a.isFunction(b.drag)){if(h.debug){alert("You do not have the drag plugin loaded.")}}else if(!a.isFunction(b.drop)){if(h.debug){alert("You do not have the drop plugin loaded.")}}else{b.drag(function(a,c){var e=b.data("roundabout"),f=e.dragAxis.toLowerCase()==="x"?"deltaX":"deltaY";d.stopAnimation.apply(b);d.setBearing.apply(b,[e.dragBearing+c[f]/e.dragFactor])}).drop(function(a){var c=b.data("roundabout"),e=d.getAnimateToMethod(c.dropAnimateTo);d.allowAnimation.apply(b);d[e].apply(b,[c.dropDuration,c.dropEasing,c.dropCallback]);c.dragBearing=c.period*d.getNearestChild.apply(b)})}b.each(function(){var b=a(this).get(0),c=a(this).data("roundabout"),e=c.dragAxis.toLowerCase()==="x"?"pageX":"pageY",f=d.getAnimateToMethod(c.dropAnimateTo);if(b.addEventListener){b.addEventListener("touchstart",function(a){c.touchMoveStartPosition=a.touches[0][e]},false);b.addEventListener("touchmove",function(b){var f=(b.touches[0][e]-c.touchMoveStartPosition)/c.dragFactor;b.preventDefault();d.stopAnimation.apply(a(this));d.setBearing.apply(a(this),[c.dragBearing+f])},false);b.addEventListener("touchend",function(b){b.preventDefault();d.allowAnimation.apply(a(this));f=d.getAnimateToMethod(c.dropAnimateTo);d[f].apply(a(this),[c.dropDuration,c.dropEasing,c.dropCallback]);c.dragBearing=c.period*d.getNearestChild.apply(a(this))},false)}})}d.initChildren.apply(b,[f,g])})},initChildren:function(b,c){var e=a(this),f=e.data("roundabout");b=b||function(){};e.children(f.childSelector).each(function(b){var f,g,h,i=d.getPlacement.apply(e,[b]);if(c&&a(this).data("roundabout")){f=a(this).data("roundabout").startWidth;g=a(this).data("roundabout").startHeight;h=a(this).data("roundabout").startFontSize}a(this).addClass("roundabout-moveable-item").css("position","absolute");a(this).data("roundabout",{startWidth:f||a(this).width(),startHeight:g||a(this).height(),startFontSize:h||parseInt(a(this).css("font-size"),10),degrees:i,backDegrees:d.normalize.apply(null,[i-180]),childNumber:b,currentScale:1,parent:e})});d.updateChildren.apply(e);if(f.autoplay){f.autoplayStartTimeout=setTimeout(function(){d.startAutoplay.apply(e)},f.autoplayInitialDelay)}e.trigger("ready");b.apply(e);return e},updateChildren:function(){return this.each(function(){var b=a(this),c=b.data("roundabout"),e=-1,f={bearing:c.bearing,tilt:c.tilt,stage:{width:Math.floor(a(this).width()*.9),height:Math.floor(a(this).height()*.9)},animating:c.animating,inFocus:c.childInFocus,focusBearingRadian:d.degToRad.apply(null,[c.focusBearing]),shape:a.roundaboutShapes[c.shape]||a.roundaboutShapes[a.roundaboutShapes.def]};f.midStage={width:f.stage.width/2,height:f.stage.height/2};f.nudge={width:f.midStage.width+f.stage.width*.05,height:f.midStage.height+f.stage.height*.05};f.zValues={min:c.minZ,max:c.maxZ,diff:c.maxZ-c.minZ};f.opacity={min:c.minOpacity,max:c.maxOpacity,diff:c.maxOpacity-c.minOpacity};f.scale={min:c.minScale,max:c.maxScale,diff:c.maxScale-c.minScale};b.children(c.childSelector).each(function(g){if(d.updateChild.apply(b,[a(this),f,g,function(){a(this).trigger("ready")}])&&(!f.animating||c.lastAnimationStep)){e=g;a(this).addClass("roundabout-in-focus")}else{a(this).removeClass("roundabout-in-focus")}});if(e!==f.inFocus){if(c.triggerBlurEvents){b.children(c.childSelector).eq(f.inFocus).trigger("blur")}c.childInFocus=e;if(c.triggerFocusEvents&&e!==-1){b.children(c.childSelector).eq(e).trigger("focus")}}b.trigger("childrenUpdated")})},updateChild:function(b,c,e,f){var g,h=this,i=a(b),j=i.data("roundabout"),k=[],l=d.degToRad.apply(null,[360-j.degrees+c.bearing]);f=f||function(){};l=d.normalizeRad.apply(null,[l]);g=c.shape(l,c.focusBearingRadian,c.tilt);g.scale=g.scale>1?1:g.scale;g.adjustedScale=(c.scale.min+c.scale.diff*g.scale).toFixed(4);g.width=(g.adjustedScale*j.startWidth).toFixed(4);g.height=(g.adjustedScale*j.startHeight).toFixed(4);i.css({left:(g.x*c.midStage.width+c.nudge.width-g.width/2).toFixed(0)+"px",top:(g.y*c.midStage.height+c.nudge.height-g.height/2).toFixed(0)+"px",width:g.width+"px",height:g.height+"px",opacity:(c.opacity.min+c.opacity.diff*g.scale).toFixed(2),zIndex:Math.round(c.zValues.min+c.zValues.diff*g.z),fontSize:(g.adjustedScale*j.startFontSize).toFixed(1)+"px"});j.currentScale=g.adjustedScale;if(h.data("roundabout").debug){k.push('
');k.push('Child '+e+"
");k.push("left: "+i.css("left")+"
");k.push("top: "+i.css("top")+"
");k.push("width: "+i.css("width")+"
");k.push("opacity: "+i.css("opacity")+"
");k.push("height: "+i.css("height")+"
");k.push("z-index: "+i.css("z-index")+"
");k.push("font-size: "+i.css("font-size")+"
");k.push("scale: "+i.data("roundabout").currentScale);k.push("
");i.html(k.join(""))}i.trigger("reposition");f.apply(h);return d.isInFocus.apply(h,[j.degrees])},setBearing:function(b,c){c=c||function(){};b=d.normalize.apply(null,[b]);this.each(function(){var c,e,f,g=a(this),h=g.data("roundabout"),i=h.bearing;h.bearing=b;g.trigger("bearingSet");d.updateChildren.apply(g);c=Math.abs(i-b);if(!h.animating||c>180){return}c=Math.abs(i-b);g.children(h.childSelector).each(function(c){var e;if(d.isChildBackDegreesBetween.apply(a(this),[b,i])){e=i>b?"Clockwise":"Counterclockwise";a(this).trigger("move"+e+"ThroughBack")}})});c.apply(this);return this},adjustBearing:function(b,c){c=c||function(){};if(b===0){return this}this.each(function(){d.setBearing.apply(a(this),[a(this).data("roundabout").bearing+b])});c.apply(this);return this},setTilt:function(b,c){c=c||function(){};this.each(function(){a(this).data("roundabout").tilt=b;d.updateChildren.apply(a(this))});c.apply(this);return this},adjustTilt:function(b,c){c=c||function(){};this.each(function(){d.setTilt.apply(a(this),[a(this).data("roundabout").tilt+b])});c.apply(this);return this},animateToBearing:function(b,c,e,f,g){var h=(new Date).getTime();g=g||function(){};if(a.isFunction(f)){g=f;f=null}else if(a.isFunction(e)){g=e;e=null}else if(a.isFunction(c)){g=c;c=null}this.each(function(){var i,j,k,l=a(this),m=l.data("roundabout"),n=!c?m.duration:c,o=e?e:m.easing||"swing";if(!f){f={timerStart:h,start:m.bearing,totalTime:n}}i=h-f.timerStart;if(m.stopAnimation){d.allowAnimation.apply(l);m.animating=false;return}if(i=0&&!a.easing["easeOutBack"]){k=f.start+(b-f.start)*k}k=d.normalize.apply(null,[k]);m.dragBearing=k;d.setBearing.apply(l,[k,function(){setTimeout(function(){d.animateToBearing.apply(l,[b,n,o,f,g])},0)}])}else{m.lastAnimationStep=true;b=d.normalize.apply(null,[b]);d.setBearing.apply(l,[b,function(){l.trigger("animationEnd")}]);m.animating=false;m.lastAnimationStep=false;m.dragBearing=b;g.apply(l)}});return this},animateToNearbyChild:function(b,c){var e=b[0],f=b[1],g=b[2]||function(){};if(a.isFunction(f)){g=f;f=null}else if(a.isFunction(e)){g=e;e=null}return this.each(function(){var b,h,i=a(this),j=i.data("roundabout"),k=!j.reflect?j.bearing%360:j.bearing,l=i.children(j.childSelector).length;if(!j.animating){if(j.reflect&&c==="previous"||!j.reflect&&c==="next"){k=Math.abs(k)=Math.floor(h.lower)){if(l===2&&k===360){d.animateToDelta.apply(i,[-180,e,f,g])}else{d.animateBearingToFocus.apply(i,[h.lower,e,f,g])}break}}}else{k=Math.abs(k)=0;b-=1){h={lower:j.period*b,upper:j.period*(b+1)};h.upper=b===l-1?360:h.upper;if(k>=Math.floor(h.lower)&&k180?-(360-g):g;if(g!==0){d.animateToDelta.apply(a(this),[g,c,e,f])}})},stopAnimation:function(){return this.each(function(){a(this).data("roundabout").stopAnimation=true})},allowAnimation:function(){return this.each(function(){a(this).data("roundabout").stopAnimation=false})},startAutoplay:function(b){return this.each(function(){var c=a(this),e=c.data("roundabout");b=b||e.autoplayCallback||function(){};clearInterval(e.autoplayInterval);e.autoplayInterval=setInterval(function(){d.animateToNextChild.apply(c,[b])},e.autoplayDuration);e.autoplayIsRunning=true;c.trigger("autoplayStart")})},stopAutoplay:function(b){return this.each(function(){clearInterval(a(this).data("roundabout").autoplayInterval);a(this).data("roundabout").autoplayInterval=null;a(this).data("roundabout").autoplayIsRunning=false;if(!b){a(this).unbind(".autoplay")}a(this).trigger("autoplayStop")})},toggleAutoplay:function(b){return this.each(function(){var c=a(this),e=c.data("roundabout");b=b||e.autoplayCallback||function(){};if(!d.isAutoplaying.apply(a(this))){d.startAutoplay.apply(a(this),[b])}else{d.stopAutoplay.apply(a(this),[b])}})},isAutoplaying:function(){return this.data("roundabout").autoplayIsRunning},changeAutoplayDuration:function(b){return this.each(function(){var c=a(this),e=c.data("roundabout");e.autoplayDuration=b;if(d.isAutoplaying.apply(c)){d.stopAutoplay.apply(c);setTimeout(function(){d.startAutoplay.apply(c)},10)}})},normalize:function(a){var b=a%360;return b<0?360+b:b},normalizeRad:function(a){while(a<0){a+=Math.PI*2}while(a>Math.PI*2){a-=Math.PI*2}return a},isChildBackDegreesBetween:function(b,c){var d=a(this).data("roundabout").backDegrees;if(b>c){return d>=c&&d=b}},getAnimateToMethod:function(a){a=a.toLowerCase();if(a==="next"){return"animateToNextChild"}else if(a==="previous"){return"animateToPreviousChild"}return"animateToNearestChild"},relayoutChildren:function(){return this.each(function(){var b=a(this),c=a.extend({},b.data("roundabout"));c.startingChild=b.data("roundabout").childInFocus;d.init.apply(b,[c,null,true])})},getNearestChild:function(){var b=a(this),c=b.data("roundabout"),d=b.children(c.childSelector).length;if(!c.reflect){return(d-Math.round(c.bearing/c.period)%d)%d}else{return Math.round(c.bearing/c.period)%d}},degToRad:function(a){return d.normalize.apply(null,[a])*Math.PI/180},getPlacement:function(a){var b=this.data("roundabout");return!b.reflect?360-b.period*a:b.period*a},isInFocus:function(a){var b,c=this,e=c.data("roundabout"),f=d.normalize.apply(null,[e.bearing]);a=d.normalize.apply(null,[a]);b=Math.abs(f-a);return b<=e.floatComparisonThreshold||b>=360-e.floatComparisonThreshold},getChildInFocus:function(){var b=a(this).data("roundabout");return b.childInFocus>-1?b.childInFocus:false},compareVersions:function(a,b){var c,d=a.split(/\./i),e=b.split(/\./i),f=d.length>e.length?d.length:e.length;for(c=0;c<=f;c++){if(d[c]&&!e[c]&&parseInt(d[c],10)!==0){return 1}else if(e[c]&&!d[c]&&parseInt(e[c],10)!==0){return-1}else if(d[c]===e[c]){continue}if(d[c]&&e[c]){if(parseInt(d[c],10)>parseInt(e[c],10)){return 1}else{return-1}}}return 0}};a.fn.roundabout=function(b){if(d[b]){return d[b].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof b==="object"||a.isFunction(b)||!b){return d.init.apply(this,arguments)}else{a.error("Method "+b+" does not exist for jQuery.roundabout.")}}})(jQuery) \ No newline at end of file +(function(b){var c,d,a;b.extend({roundaboutShapes:{def:"lazySusan",lazySusan:function(g,e,f){return{x:Math.sin(g+e),y:(Math.sin(g+3*Math.PI/2+e)/8)*f,z:(Math.cos(g+e)+1)/2,scale:(Math.sin(g+Math.PI/2+e)/2)+0.5}}}});c={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};d={autoplayInterval:null,autoplayIsRunning:false,autoplayStartTimeout:null,animating:false,childInFocus:-1,touchMoveStartPosition:null,stopAnimation:false,lastAnimationStep:false};a={init:function(f,i,h){var g,e=(new Date()).getTime();f=(typeof f==="object")?f:{};i=(b.isFunction(i))?i:function(){};i=(b.isFunction(f))?f:i;g=b.extend({},c,f,d);return this.each(function(){var k=b(this),j=k.children(g.childSelector).length,n=360/j,m=(g.startingChild&&g.startingChild>(j-1))?(j-1):g.startingChild,l=(g.startingChild===null)?g.bearing:360-(m*n),o=(k.css("position")!=="static")?k.css("position"):"relative";k.css({padding:0,position:o}).addClass("roundabout-holder").data("roundabout",b.extend({},g,{startingChild:m,bearing:l,oppositeOfFocusBearing:a.normalize.apply(null,[g.focusBearing-180]),dragBearing:l,period:n}));if(h){k.unbind(".roundabout").children(g.childSelector).unbind(".roundabout")}else{if(g.responsive){b(window).bind("resize.roundabout",function(){a.stopAutoplay.apply(k);a.relayoutChildren.apply(k)})}}if(g.clickToFocus){k.children(g.childSelector).each(function(p){b(this).bind("click.roundabout",function(){var q=a.getPlacement.apply(k,[p]);if(!a.isInFocus.apply(k,[q])){a.stopAnimation.apply(b(this));if(!k.data("roundabout").animating){a.animateBearingToFocus.apply(k,[q,k.data("roundabout").clickToFocusCallback])}return false}})})}if(g.btnNext){b(g.btnNext).bind("click.roundabout",function(){if(!k.data("roundabout").animating){a.animateToNextChild.apply(k,[k.data("roundabout").btnNextCallback])}return false})}if(g.btnPrev){b(g.btnPrev).bind("click.roundabout",function(){a.animateToPreviousChild.apply(k,[k.data("roundabout").btnPrevCallback]);return false})}if(g.btnToggleAutoplay){b(g.btnToggleAutoplay).bind("click.roundabout",function(){a.toggleAutoplay.apply(k);return false})}if(g.btnStartAutoplay){b(g.btnStartAutoplay).bind("click.roundabout",function(){a.startAutoplay.apply(k);return false})}if(g.btnStopAutoplay){b(g.btnStopAutoplay).bind("click.roundabout",function(){a.stopAutoplay.apply(k);return false})}if(g.autoplayPauseOnHover){k.bind("mouseenter.roundabout.autoplay",function(){a.stopAutoplay.apply(k,[true])}).bind("mouseleave.roundabout.autoplay",function(){a.startAutoplay.apply(k)})}if(g.enableDrag){if(!b.isFunction(k.drag)){if(g.debug){alert("You do not have the drag plugin loaded.")}}else{if(!b.isFunction(k.drop)){if(g.debug){alert("You do not have the drop plugin loaded.")}}else{k.drag(function(r,p){var q=k.data("roundabout"),s=(q.dragAxis.toLowerCase()==="x")?"deltaX":"deltaY";a.stopAnimation.apply(k);a.setBearing.apply(k,[q.dragBearing+p[s]/q.dragFactor])}).drop(function(q){var p=k.data("roundabout"),r=a.getAnimateToMethod(p.dropAnimateTo);a.allowAnimation.apply(k);a[r].apply(k,[p.dropDuration,p.dropEasing,p.dropCallback]);p.dragBearing=p.period*a.getNearestChild.apply(k)})}}k.each(function(){var p=b(this).get(0),r=b(this).data("roundabout"),q=(r.dragAxis.toLowerCase()==="x")?"pageX":"pageY",s=a.getAnimateToMethod(r.dropAnimateTo);if(p.addEventListener){p.addEventListener("touchstart",function(t){r.touchMoveStartPosition=t.touches[0][q]},false);p.addEventListener("touchmove",function(t){var u=(t.touches[0][q]-r.touchMoveStartPosition)/r.dragFactor;t.preventDefault();a.stopAnimation.apply(b(this));a.setBearing.apply(b(this),[r.dragBearing+u])},false);p.addEventListener("touchend",function(t){t.preventDefault();a.allowAnimation.apply(b(this));s=a.getAnimateToMethod(r.dropAnimateTo);a[s].apply(b(this),[r.dropDuration,r.dropEasing,r.dropCallback]);r.dragBearing=r.period*a.getNearestChild.apply(b(this))},false)}})}a.initChildren.apply(k,[i,h])})},initChildren:function(h,f){var e=b(this),g=e.data("roundabout");h=h||function(){};e.children(g.childSelector).each(function(m){var k,j,l,n=a.getPlacement.apply(e,[m]);if(f&&b(this).data("roundabout")){k=b(this).data("roundabout").startWidth;j=b(this).data("roundabout").startHeight;l=b(this).data("roundabout").startFontSize}b(this).addClass("roundabout-moveable-item").css("position","absolute");b(this).data("roundabout",{startWidth:k||b(this).width(),startHeight:j||b(this).height(),startFontSize:l||parseInt(b(this).css("font-size"),10),degrees:n,backDegrees:a.normalize.apply(null,[n-180]),childNumber:m,currentScale:1,parent:e})});a.updateChildren.apply(e);if(g.autoplay){g.autoplayStartTimeout=setTimeout(function(){a.startAutoplay.apply(e)},g.autoplayInitialDelay)}e.trigger("ready");h.apply(e);return e},updateChildren:function(){return this.each(function(){var e=b(this),f=e.data("roundabout"),h=-1,g={bearing:f.bearing,tilt:f.tilt,stage:{width:Math.floor(b(this).width()*0.9),height:Math.floor(b(this).height()*0.9)},animating:f.animating,inFocus:f.childInFocus,focusBearingRadian:a.degToRad.apply(null,[f.focusBearing]),shape:b.roundaboutShapes[f.shape]||b.roundaboutShapes[b.roundaboutShapes.def]};g.midStage={width:g.stage.width/2,height:g.stage.height/2};g.nudge={width:g.midStage.width+(g.stage.width*0.05),height:g.midStage.height+(g.stage.height*0.05)};g.zValues={min:f.minZ,max:f.maxZ,diff:f.maxZ-f.minZ};g.opacity={min:f.minOpacity,max:f.maxOpacity,diff:f.maxOpacity-f.minOpacity};g.scale={min:f.minScale,max:f.maxScale,diff:f.maxScale-f.minScale};e.children(f.childSelector).each(function(j){if(a.updateChild.apply(e,[b(this),g,j,function(){b(this).trigger("ready")}])&&(!g.animating||f.lastAnimationStep)){h=j;b(this).addClass("roundabout-in-focus")}else{b(this).removeClass("roundabout-in-focus")}});if(h!==g.inFocus){if(f.triggerBlurEvents){e.children(f.childSelector).eq(g.inFocus).trigger("blur")}f.childInFocus=h;if(f.triggerFocusEvents&&h!==-1){e.children(f.childSelector).eq(h).trigger("focus")}}e.trigger("childrenUpdated")})},updateChild:function(h,g,e,m){var l,n=this,f=b(h),j=f.data("roundabout"),i=[],k=a.degToRad.apply(null,[(360-j.degrees)+g.bearing]);m=m||function(){};k=a.normalizeRad.apply(null,[k]);l=g.shape(k,g.focusBearingRadian,g.tilt);l.scale=(l.scale>1)?1:l.scale;l.adjustedScale=(g.scale.min+(g.scale.diff*l.scale)).toFixed(4);l.width=(l.adjustedScale*j.startWidth).toFixed(4);l.height=(l.adjustedScale*j.startHeight).toFixed(4);f.css({left:((l.x*g.midStage.width+g.nudge.width)-l.width/2).toFixed(0)+"px",top:((l.y*g.midStage.height+g.nudge.height)-l.height/2).toFixed(0)+"px",width:l.width+"px",height:l.height+"px",opacity:(g.opacity.min+(g.opacity.diff*l.scale)).toFixed(2),zIndex:Math.round(g.zValues.min+(g.zValues.diff*l.z)),fontSize:(l.adjustedScale*j.startFontSize).toFixed(1)+"px"});j.currentScale=l.adjustedScale;if(n.data("roundabout").debug){i.push('
');i.push('Child '+e+"
");i.push("left: "+f.css("left")+"
");i.push("top: "+f.css("top")+"
");i.push("width: "+f.css("width")+"
");i.push("opacity: "+f.css("opacity")+"
");i.push("height: "+f.css("height")+"
");i.push("z-index: "+f.css("z-index")+"
");i.push("font-size: "+f.css("font-size")+"
");i.push("scale: "+f.data("roundabout").currentScale);i.push("
");f.html(i.join(""))}f.trigger("reposition");m.apply(n);return a.isInFocus.apply(n,[j.degrees])},setBearing:function(e,f){f=f||function(){};e=a.normalize.apply(null,[e]);this.each(function(){var l,g,j,i=b(this),k=i.data("roundabout"),h=k.bearing;k.bearing=e;i.trigger("bearingSet");a.updateChildren.apply(i);l=Math.abs(h-e);if(!k.animating||l>180){return}l=Math.abs(h-e);i.children(k.childSelector).each(function(n){var m;if(a.isChildBackDegreesBetween.apply(b(this),[e,h])){m=(h>e)?"Clockwise":"Counterclockwise";b(this).trigger("move"+m+"ThroughBack")}})});f.apply(this);return this},adjustBearing:function(f,e){e=e||function(){};if(f===0){return this}this.each(function(){a.setBearing.apply(b(this),[b(this).data("roundabout").bearing+f])});e.apply(this);return this},setTilt:function(e,f){f=f||function(){};this.each(function(){b(this).data("roundabout").tilt=e;a.updateChildren.apply(b(this))});f.apply(this);return this},adjustTilt:function(f,e){e=e||function(){};this.each(function(){a.setTilt.apply(b(this),[b(this).data("roundabout").tilt+f])});e.apply(this);return this},animateToBearing:function(f,g,j,h,i){var e=(new Date()).getTime();i=i||function(){};if(b.isFunction(h)){i=h;h=null}else{if(b.isFunction(j)){i=j;j=null}else{if(b.isFunction(g)){i=g;g=null}}}this.each(function(){var q,p,k,l=b(this),o=l.data("roundabout"),m=(!g)?o.duration:g,n=(j)?j:o.easing||"swing";if(!h){h={timerStart:e,start:o.bearing,totalTime:m}}q=e-h.timerStart;if(o.stopAnimation){a.allowAnimation.apply(l);o.animating=false;return}if(q=0&&!(b.easing.easeOutBack)){k=h.start+((f-h.start)*k)}k=a.normalize.apply(null,[k]);o.dragBearing=k;a.setBearing.apply(l,[k,function(){setTimeout(function(){a.animateToBearing.apply(l,[f,m,n,h,i])},0)}])}else{o.lastAnimationStep=true;f=a.normalize.apply(null,[f]);a.setBearing.apply(l,[f,function(){l.trigger("animationEnd")}]);o.animating=false;o.lastAnimationStep=false;o.dragBearing=f;i.apply(l)}});return this},animateToNearbyChild:function(e,g){var f=e[0],i=e[1],h=e[2]||function(){};if(b.isFunction(i)){h=i;i=null}else{if(b.isFunction(f)){h=f;f=null}}return this.each(function(){var n,l,k=b(this),p=k.data("roundabout"),m=(!p.reflect)?p.bearing%360:p.bearing,o=k.children(p.childSelector).length;if(!p.animating){if((p.reflect&&g==="previous")||(!p.reflect&&g==="next")){m=(Math.abs(m)=Math.floor(l.lower)){if(o===2&&m===360){a.animateToDelta.apply(k,[-180,f,i,h])}else{a.animateBearingToFocus.apply(k,[l.lower,f,i,h])}break}}}else{m=(Math.abs(m)=0;n-=1){l={lower:p.period*n,upper:p.period*(n+1)};l.upper=(n===o-1)?360:l.upper;if(m>=Math.floor(l.lower)&&m180)?-(360-i):i;if(i!==0){a.animateToDelta.apply(b(this),[i,e,h,g])}})},stopAnimation:function(){return this.each(function(){b(this).data("roundabout").stopAnimation=true})},allowAnimation:function(){return this.each(function(){b(this).data("roundabout").stopAnimation=false})},startAutoplay:function(e){return this.each(function(){var f=b(this),g=f.data("roundabout");e=e||g.autoplayCallback||function(){};clearInterval(g.autoplayInterval);g.autoplayInterval=setInterval(function(){a.animateToNextChild.apply(f,[e])},g.autoplayDuration);g.autoplayIsRunning=true;f.trigger("autoplayStart")})},stopAutoplay:function(e){return this.each(function(){clearInterval(b(this).data("roundabout").autoplayInterval);b(this).data("roundabout").autoplayInterval=null;b(this).data("roundabout").autoplayIsRunning=false;if(!e){b(this).unbind(".autoplay")}b(this).trigger("autoplayStop")})},toggleAutoplay:function(e){return this.each(function(){var f=b(this),g=f.data("roundabout");e=e||g.autoplayCallback||function(){};if(!a.isAutoplaying.apply(b(this))){a.startAutoplay.apply(b(this),[e])}else{a.stopAutoplay.apply(b(this),[e])}})},isAutoplaying:function(){return(this.data("roundabout").autoplayIsRunning)},changeAutoplayDuration:function(e){return this.each(function(){var f=b(this),g=f.data("roundabout");g.autoplayDuration=e;if(a.isAutoplaying.apply(f)){a.stopAutoplay.apply(f);setTimeout(function(){a.startAutoplay.apply(f)},10)}})},normalize:function(f){var e=f%360;return(e<0)?360+e:e},normalizeRad:function(e){while(e<0){e+=(Math.PI*2)}while(e>(Math.PI*2)){e-=(Math.PI*2)}return e},isChildBackDegreesBetween:function(f,e){var g=b(this).data("roundabout").backDegrees;if(f>e){return(g>=e&&g=f)}},getAnimateToMethod:function(e){e=e.toLowerCase();if(e==="next"){return"animateToNextChild"}else{if(e==="previous"){return"animateToPreviousChild"}}return"animateToNearestChild"},relayoutChildren:function(){return this.each(function(){var e=b(this),f=b.extend({},e.data("roundabout"));f.startingChild=e.data("roundabout").childInFocus;a.init.apply(e,[f,null,true])})},getNearestChild:function(){var e=b(this),g=e.data("roundabout"),f=e.children(g.childSelector).length;if(!g.reflect){return((f)-(Math.round(g.bearing/g.period)%f))%f}else{return(Math.round(g.bearing/g.period)%f)}},degToRad:function(e){return a.normalize.apply(null,[e])*Math.PI/180},getPlacement:function(f){var e=this.data("roundabout");return(!e.reflect)?360-(e.period*f):e.period*f},isInFocus:function(i){var h,e=this,g=e.data("roundabout"),f=a.normalize.apply(null,[g.bearing]);i=a.normalize.apply(null,[i]);h=Math.abs(f-i);return(h<=g.floatComparisonThreshold||h>=360-g.floatComparisonThreshold)},getChildInFocus:function(){var e=b(this).data("roundabout");return(e.childInFocus>-1)?e.childInFocus:false},compareVersions:function(e,k){var g,j=e.split(/\./i),h=k.split(/\./i),f=(j.length>h.length)?j.length:h.length;for(g=0;g<=f;g++){if(j[g]&&!h[g]&&parseInt(j[g],10)!==0){return 1}else{if(h[g]&&!j[g]&&parseInt(h[g],10)!==0){return -1}else{if(j[g]===h[g]){continue}}}if(j[g]&&h[g]){if(parseInt(j[g],10)>parseInt(h[g],10)){return 1}else{return -1}}}return 0},destroy:function(){var e=b(this),f=e.data("roundabout");b(window).unbind(".roundabout");e.removeClass("roundabout-holder").removeAttr("style");e.children(f.childSelector).removeClass("roundabout-moveable-item").removeClass("roundabout-in-focus").removeData("roundabout").removeAttr("style");e.children(f.childSelector).andSelf().unbind(".roundabout").unbind(".roundabout.autoplay");if(f.btnNext){b(f.btnNext).unbind(".roundabout")}if(f.btnPrev){b(f.btnPrev).bind(".roundabout")}if(f.btnToggleAutoplay){b(f.btnToggleAutoplay).bind(".roundabout")}if(f.btnStartAutoplay){b(f.btnStartAutoplay).bind(".roundabout")}if(f.btnStopAutoplay){b(f.btnStopAutoplay).bind(".roundabout")}e.removeData("roundabout")}};b.fn.roundabout=function(e){if(a[e]){return a[e].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof e==="object"||b.isFunction(e)||!e){return a.init.apply(this,arguments)}else{b.error("Method "+e+" does not exist for jQuery.roundabout.")}}}})(jQuery); \ No newline at end of file