Team:UT Dallas/haccordion.js

From 2012.igem.org

var haccordion={ajaxloadingmsg:'
<img src="UTD_Img-loader.gif" style="vertical-align: middle" />
',ismobile:navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i)!=null,accordioninfo:{},expandli:function(a,b){var c=haccordion.accordioninfo[a];var d=typeof b=="number"?c.$targetlis.eq(b):typeof b=="string"?jQuery("#"+b):jQuery(b);if(typeof c.$lastexpanded!="undefined")c.$lastexpanded.stop().animate({width:c.paneldimensions.peekw},c.speed,"easeInOutCirc");d.stop().animate({width:d.data("hpaneloffsetw")},c.speed,"easeInOutCirc");c.$lastexpanded=d},urlparamselect:function(a){var b=window.location.search.match(new RegExp(a+"=(\\d+)","i"));if(b!=null)b=parseInt(RegExp.$1)+"";return b},getCookie:function(a){var b=new RegExp(a+"=[^;]+","i");if(document.cookie.match(b))return document.cookie.match(b)[0].split("=")[1];return null},setCookie:function(a,b){document.cookie=a+"="+b+"; path=/"},loadexternal:function(a,b){var c=a("#"+b.ajaxsource.container).html(this.ajaxloadingmsg);a.ajax({url:b.ajaxsource.path,async:true,error:function(a){c.html("Error fetching content.
Server Response: "+a.responseText)},success:function(d){c.html(d);haccordion.init(a,b)}})},init:function(a,b){haccordion.accordioninfo[b.accordionid]=b;var c=a("#"+b.accordionid).find("ul:eq(0) > li");b.$targetlis=c;b.selectedli=b.selectedli||[];b.speed=b.speed||"normal";c.each(function(c){var d=a(this).data("pos",c);d.data("hpaneloffsetw",d.find(".hpanel:eq(0)").outerWidth());d[haccordion.ismobile?"click":"mouseenter"](function(){haccordion.expandli(b.accordionid,this);b.$lastexpanded=a(this)});if(b.collapsecurrent){d.mouseleave(function(){a(this).stop().animate({width:b.paneldimensions.peekw},b.speed)})}});var d=haccordion.urlparamselect(b.accordionid)||(b.selectedli[1]&&haccordion.getCookie(b.accordionid)?parseInt(haccordion.getCookie(b.accordionid)):b.selectedli[0]);d=parseInt(d);if(d>=0&&d<b.$targetlis.length){b.$lastexpanded=c.eq(d);b.$lastexpanded.css("width",b.$lastexpanded.data("hpaneloffsetw"))}a(window).bind("unload",function(){haccordion.uninit(a,b)})},uninit:function(a,b){var c=b.$targetlis;var d=-1;c.each(function(){var b=a(this);b.unbind();if(b.width()==b.data("hpaneloffsetw"))d=b.data("pos")});if(b.selectedli[1]==true)haccordion.setCookie(b.accordionid,d)},setup:function(a){document.write('<style type="text/css">\n');document.write("#"+a.accordionid+" li{width: "+a.paneldimensions.peekw+";\nheight: "+a.paneldimensions.h+";\n}\n");document.write("#"+a.accordionid+" li .hpanel{width: "+a.paneldimensions.fullw+";\nheight: "+a.paneldimensions.h+";\n}\n");document.write("</style>");jQuery(document).ready(function(b){if(a.ajaxsource)haccordion.loadexternal(b,a);else haccordion.init(b,a)})}}