diff --git a/jquery.roundabout.js b/jquery.roundabout.js index df83da2..f5b0751 100644 --- a/jquery.roundabout.js +++ b/jquery.roundabout.js @@ -43,6 +43,44 @@ var defaults, internalData, methods; + + // compareVersions + // compares a given version string with another + var compareVersions = function(baseVersion, compareVersion) { + var i, + base = baseVersion.split(/\./i), + compare = compareVersion.split(/\./i), + maxVersionSegmentLength = (base.length > compare.length) ? base.length : compare.length; + + for (i = 0; i <= maxVersionSegmentLength; i++) { + if (base[i] && !compare[i] && parseInt(base[i], 10) !== 0) { + // base is higher + return 1; + } else if (compare[i] && !base[i] && parseInt(compare[i], 10) !== 0) { + // compare is higher + return -1; + } else if (base[i] === compare[i]) { + // these are the same, next + continue; + } + + if (base[i] && compare[i]) { + if (parseInt(base[i], 10) > parseInt(compare[i], 10)) { + // base is higher + return 1; + } else { + // compare is higher + return -1; + } + } + } + + // nothing was triggered, versions are the same + return 0; + }; + + var useUpdatedBearingCalculation = compareVersions.apply(null, [$.fn.jquery, "1.7.2"]) >= 0 && (compareVersions.apply(null, [$.ui.version, "1.9.1"]) >= 0 || !$.easing['easeOutBack']); + // add default shape $.extend({ roundaboutShapes: { @@ -688,9 +726,7 @@ newBearing = $.easing[thisEasingType]((timer / passedData.totalTime), timer, passedData.start, bearing - passedData.start, passedData.totalTime); } - // fixes issue #24, animation changed as of jQuery 1.7.2 - // also addresses issue #29, using easing breaks "linear" - if (methods.compareVersions.apply(null, [$().jquery, "1.7.2"]) >= 0 && !($.easing["easeOutBack"])) { + if (useUpdatedBearingCalculation) { newBearing = passedData.start + ((bearing - passedData.start) * newBearing); } @@ -1144,42 +1180,6 @@ return (data.childInFocus > -1) ? data.childInFocus : false; }, - - - // compareVersions - // compares a given version string with another - compareVersions: function(baseVersion, compareVersion) { - var i, - base = baseVersion.split(/\./i), - compare = compareVersion.split(/\./i), - maxVersionSegmentLength = (base.length > compare.length) ? base.length : compare.length; - - for (i = 0; i <= maxVersionSegmentLength; i++) { - if (base[i] && !compare[i] && parseInt(base[i], 10) !== 0) { - // base is higher - return 1; - } else if (compare[i] && !base[i] && parseInt(compare[i], 10) !== 0) { - // compare is higher - return -1; - } else if (base[i] === compare[i]) { - // these are the same, next - continue; - } - - if (base[i] && compare[i]) { - if (parseInt(base[i], 10) > parseInt(compare[i], 10)) { - // base is higher - return 1; - } else { - // compare is higher - return -1; - } - } - } - - // nothing was triggered, versions are the same - return 0; - } }; @@ -1193,4 +1193,4 @@ $.error("Method " + method + " does not exist for jQuery.roundabout."); } }; -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/jquery.roundabout.min.js b/jquery.roundabout.min.js index b6f4935..feee8fa 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(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('
');k.push('Child '+g+"
");k.push("left: "+h.css("left")+"
");k.push("top: "+h.css("top")+"
");k.push("width: "+h.css("width")+"
");k.push("opacity: "+h.css("opacity")+"
");k.push("height: "+h.css("height")+"
");k.push("z-index: "+h.css("z-index")+"
");k.push("font-size: "+h.css("font-size")+"
");k.push("scale: "+h.data("roundabout").currentScale);k.push("
");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=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)=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)&&n180)?-(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)}},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);