-
Notifications
You must be signed in to change notification settings - Fork 0
/
compassrose-0.3.1.min.js
24 lines (24 loc) · 4.62 KB
/
compassrose-0.3.1.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
(function(b){var a=(function(){var c={};return function(f,d,e){if(!e){e="defaultId";}if(c[e]){clearTimeout(c[e]);}c[e]=setTimeout(f,d);};})();b.compassRose=function(c,d){this.element=b(d);
this._init(c);};b.compassRose.settings={radius:"90%",arc:360,center:true,point:{x:600,y:600},radialOffset:0,centerElementId:"compassRoseContent",centerElementLeftOffset:0,centerElementTopOffset:0,rotationEasing:undefined,easingSpeed:2000,sliceWidth:4,hoverFx:function(){jQuery.noop();
},blurFx:function(){jQuery.noop();},clickFx:function(){jQuery.noop();},onRotateFx:function(){jQuery.noop();}};b.compassRose.prototype={_center:function(){var c=b("#"+this.settings.centerElementId);
b(c).css("position","fixed");b(c).css("left",this.settings.point.x-(b(c).width()/2)+this.settings.centerElementLeftOffset);b(c).css("top",this.settings.point.y-(b(c).height()/2)+this.settings.centerElementTopOffset);
},center:function(c){if(c){this.settings.center=false;this.settings.point=c;}else{this.settings.center=true;this.settings.point.y=b(window).height()/2;
this.settings.point.x=b(window).width()/2;}this._center();},_init:function(c){this.settings=b.extend(true,{},b.compassRose.settings,c);if(this.settings.center){if(this.settings.centerElementId!==undefined){this.center();
}}else{this._center();}this._calibrate();this._orient();},_calibrate:function(){this.settings.directions$=this.element.children("div");this.settings.arcSpan=this.settings.arc/this.settings.directions$.length;
if(typeof(this.settings.radius)==="string"){if(this.settings.radius.indexOf("%")!==-1){var c=this.settings.radius.replace("%",""),f=parseInt(c,10),e=b(window).width(),g=b(window).height();
this.settings.radius=e>g?((g*(f/100))/2):((e*(f/100))/2);}}var d=this;this.settings.directions$.each(function(k){var i=b(this),h=b(i).html(),j="<span>"+h+"</span>";
b(i).data("compassRoseDirectionAngle",(k*d.settings.arcSpan)+90+d.settings.radialOffset);b(i).empty().append(j);b(i).click(function(){d.settings.clickFx(this);
});b(i).hover(function(){d.settings.hoverFx(this);},function(){d.settings.blurFx(this);});});},orient:function(c,d){this._orient(c,d);},_orient:function(d,e){if(d===undefined){d=false;
}if(e===undefined){e=false;}var c=this;this.settings.directions$.each(function(j){var h=b(this),f=b(h).data("compassRoseDirectionAngle")*Math.PI/180,g=(Math.cos(f)*c.settings.radius)+c.settings.point.x-(b(h).find("span").width()/2),i=(Math.sin(f)*c.settings.radius*-1)+c.settings.point.y;
b(h).data("compassRoseX",g);b(h).data("compassRoseY",i);b(h).css("position","fixed");if(d){if(e){b(h).animate({left:g,top:i},c.settings.easingSpeed,c.settings.rotationEasing);
}else{b(h).animate({left:g,top:i},50);}}else{b(h).css("left",g);b(h).css("top",i);}});},rotate:function(c){if(this.settings.rotationEasing!==undefined&&c!==0){this._rotate(c);
this._orient(true,true);}else{if(c!==0){this._rotateBySlices(c);this._orient(true,false);}}this.settings.onRotateFx();},_rotate:function(c){this.settings.directions$.each(function(g){var e=b(this),d=parseInt(b(e).data("compassRoseDirectionAngle"),10),f=d+parseInt(c,10);
if(f>=360){f-=360;}if(f<=0){f=360+f;}b(e).data("compassRoseDirectionAngle",f);});},_rotateBySlices:function(d){if(d===0){return;}var c=Math.abs(d);if(c<=this.settings.sliceWidth){this._rotateSlice(d);
this.rotate(0);}else{if(d<0){this._rotateSlice(-this.settings.sliceWidth);this._rotateBySlices(d+this.settings.sliceWidth);}else{this._rotateSlice(this.settings.sliceWidth);
this._rotateBySlices(d-this.settings.sliceWidth);}}},_rotateSlice:function(c){this.settings.directions$.each(function(g){var e=b(this),d=parseInt(b(e).data("compassRoseDirectionAngle"),10),f=d+parseInt(c,10);
if(f>=360){f-=360;}if(f<=0){f=360+f;}b(e).data("compassRoseDirectionAngle",f);});this._orient(true,false);},rotateTo:function(h,f){var c=this._findIndex(h),e,d,g;
if(c===-1){return;}e=b(this.settings.directions$).get(c);d=b(e).data("compassRoseDirectionAngle");g=parseInt(f,10)-parseInt(d,10);if(g<-180){g=(360+g);
}this.rotate(g);},_findIndex:function(d){var c=-1;b.each(this.settings.directions$,function(f,e){if(b(e).attr("id")===d){c=f;}});return c;}};b.fn.compassRose=function(d){if(typeof d==="string"){var c=Array.prototype.slice.call(arguments,1);
this.each(function(){var e=b.data(this,"compassRose");if(!e){return b.error("cannot call methods on compassRose prior to initialization; attempted to call method '"+d+"'");
}if(!b.isFunction(e[d])||d.charAt(0)==="_"){return b.error("no such method '"+d+"' for compassRose instance");}e[d].apply(e,c);});}else{this.each(function(){var e=b.data(this,"compassRose");
if(e){e.option(d);e._init();}else{b.data(this,"compassRose",new b.compassRose(d,this));}});}return this;};})(jQuery);