Team:UT Dallas/jquery.lavalamp-1.3.4b.js

From 2011.igem.org

(function(jQuery){jQuery.fn.lavaLamp=function(o){o=jQuery.extend({target:'li',fx:'swing',speed:500,click:function(){return true},startItem:,autoReturn:true,returnDelay:0,setOnClick:true,homeTop:0,homeLeft:0,homeWidth:0,homeHeight:0,returnHome:false},o||{});return this.each(function(){if(jQuery(this).css('position')=='static')jQuery(this).css('position','relative');if(o.homeTop||o.homeLeft){var $home=jQuery('<'+o.target+' class="homeLava"></'+o.target+'>').css({left:o.homeLeft,top:o.homeTop,width:o.homeWidth,height:o.homeHeight,position:'absolute'});jQuery(this).prepend($home)}var path=location.pathname+location.search+location.hash,$selected,$back,$lt=jQuery(o.target+'[class!=noLava]',this),delayTimer,bx=by=0;$selected=jQuery(o.target+'.selectedLava',this);if(o.startItem!=)$selected=$lt.eq(o.startItem);if((o.homeTop||o.homeLeft)&&$selected.length<1)$selected=$home;if($selected.length<1){var pathmatch_len=0,$pathel;$lt.each(function(){var thishref=$('a:first',this).attr('href');if(path.indexOf(thishref)>-1&&thishref.length>pathmatch_len){$pathel=$(this);pathmatch_len=thishref.length}});if(pathmatch_len>0){$selected=$pathel}}if($selected.length<1)$selected=$lt.eq(0);$selected=jQuery($selected.eq(0).addClass('selectedLava'));$lt.bind('mouseenter',function(){if(delayTimer){clearTimeout(delayTimer);delayTimer=null}move(jQuery(this))}).click(function(e){if(o.setOnClick){$selected.removeClass('selectedLava');$selected=jQuery(this).addClass('selectedLava')}return o.click.apply(this,[e,this])});$back=jQuery('
  • </li>').css('position','absolute').prependTo(this);bx=parseInt($back.css('borderLeftWidth').match(/\d+/))+parseInt($back.css('borderRightWidth').match(/\d+/))+parseInt($back.css('paddingLeft').match(/\d+/))+parseInt($back.css('paddingRight').match(/\d+/));by=parseInt($back.css('borderTopWidth').match(/\d+/))+parseInt($back.css('borderBottomWidth').match(/\d+/))+parseInt($back.css('paddingTop').match(/\d+/))+parseInt($back.css('paddingBottom').match(/\d+/));if(o.homeTop||o.homeLeft)$back.css({left:o.homeLeft,top:o.homeTop,width:o.homeWidth,height:o.homeHeight});else{$back.css({left:$selected.position().left,top:$selected.position().top,width:$selected.outerWidth()-bx,height:$selected.outerHeight()-by})}jQuery(this).bind('mouseleave',function(){var $returnEl=null;if(o.returnHome)$returnEl=$home;else if(!o.autoReturn)return true;if(o.returnDelay){if(delayTimer)clearTimeout(delayTimer);delayTimer=setTimeout(function(){move($returnEl)},o.returnDelay)}else{move($returnEl)}return true});function move($el){if(!$el)$el=$selected;$back.stop().animate({left:$el.position().left,top:$el.position().top,width:$el.outerWidth()-bx,height:$el.outerHeight()-by},o.speed,o.fx)}})}})(jQuery);