Advertisement
Guest User

mobilyblocks.js

a guest
Jul 29th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($){$.fn.mobilyblocks=function(options){
  2.     var defaults={
  3.         trigger:"click",
  4.         direction:"clockwise",
  5.         duration:750,
  6.         zIndex:10,
  7.         widthMultiplier:1.2
  8.     };
  9.  
  10.     var sets=$.extend({},defaults,options);
  11.     return this.each(function(){
  12.         var $t=$(this),
  13.         w=$t.width(),
  14.         h=$t.height(),
  15.         parent=$t.find("ul"),
  16.         list=parent.find("li"),
  17.         size=list.length,
  18.         hov=false,dir;
  19.  
  20.         if(sets.direction=="clockwise"){
  21.             dir=-1
  22.         }else{
  23.             if(sets.direction=="counter"){
  24.                 dir=1
  25.             }
  26.         }
  27.  
  28.         var socials={
  29.             init:function(){
  30.                 parent.hide().css({zIndex:sets.zIndex});
  31.                 $t.append($("<a />").addClass("trigger").css({
  32.                     display:"block",
  33.                     position:"absolute",
  34.                     zIndex:1,
  35.                     top:0,
  36.                     left:0,
  37.                     width:"100%",
  38.                     height:"100%"
  39.                 }));
  40.  
  41.                 switch(sets.trigger){
  42.                     case"click":socials.click();break;
  43.                     case"hover":socials.hover();break;
  44.                     default:socials.click()}
  45.             },
  46.  
  47.             click:function(){
  48.                 var trigger=$t.find("a.trigger");
  49.                 trigger.bind("click",function(){
  50.                     if($t.hasClass("close")){
  51.                         parent.fadeTo(sets.duration,0);
  52.                         socials.animation.close();
  53.                         $t.removeClass("close")
  54.                     }else{
  55.                         parent.fadeTo(sets.duration,1);
  56.                         socials.animation.open();
  57.                         $t.addClass("close")
  58.                     }
  59.                     return false
  60.                 })
  61.             },
  62.  
  63.             hover:function(){
  64.                 var trigger=$t.find("a.trigger");
  65.                 trigger.bind("mouseover",function(){
  66.                     if(hov==false){
  67.                         parent.fadeTo(sets.duration,1);
  68.                         socials.animation.open();
  69.                         $t.addClass("close")
  70.                     }
  71.                 });
  72.  
  73.                 parent.bind("mouseleave",function(){
  74.                     $t.removeClass("close");
  75.                     parent.fadeTo(sets.duration,0);
  76.                     socials.animation.close();
  77.                     hov=true;setTimeout(function(){hov=false},500)
  78.                 })
  79.             },
  80.  
  81.             animation:{
  82.                 open:function(){
  83.                     socials.ie.open();
  84.                     list.each(function(i){
  85.                         var li=$(this);
  86.                         li.animate({
  87.                             path:new $.path.arc({
  88.                                 center:[0,0],
  89.                                 radius:w*sets.widthMultiplier,
  90.                                 start:0,
  91.                                 end:360/size*i,dir:dir
  92.                             })
  93.                         },
  94.                         sets.duration)
  95.                     });
  96.                     list.hover(function(){
  97.                         var li=$(this);
  98.                         li.css({zIndex:sets.zIndex}).siblings("li").css({zIndex:sets.zIndex-1})
  99.                     })
  100.                 },
  101.  
  102.                 close:function(){
  103.                     list.each(function(i){
  104.                         var li=$(this);
  105.                         li.animate({top:0,left:0},sets.duration,function(){socials.ie.close()})
  106.                     })
  107.                 }
  108.             },
  109.  
  110.             ie:{
  111.                 open:function(){
  112.                     if($.browser.msie){list.show()}
  113.                 },
  114.  
  115.                 close:function(){
  116.                     if($.browser.msie){list.hide()}
  117.                 }
  118.             }
  119.         };socials.init()
  120.     })
  121. }}(jQuery));
  122.  
  123. (function($){$.path={};$.path.arc=function(params){
  124.     for(var i in params){
  125.         this[i]=params[i]
  126.     }
  127.  
  128.     this.dir=this.dir||1;
  129.     while(this.start>this.end&&this.dir>0){this.start-=360}
  130.     while(this.start<this.end&&this.dir<0){this.start+=360}
  131.     this.css=function(p){
  132.         var a=this.start*(p)+this.end*(1-(p));
  133.         a=a*3.1415927/180;
  134.         var x=Math.sin(a)*this.radius+this.center[0];
  135.         var y=Math.cos(a)*this.radius+this.center[1];
  136.         return{top:y+"px",left:x+"px"}
  137.     }
  138. };
  139.  
  140. $.fx.step.path=function(fx){
  141.     var css=fx.end.css(1-fx.pos);
  142.     for(var i in css){fx.elem.style[i]=css[i]}
  143. }})(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement