Template:MichiganFrontEndScripts

From 2014.igem.org

jQuery(document).ready(function($){

/* announcement -------------------------------*/ if($.cookie){ if($.cookie("ts-hide-banner") == "1"){ $("#announcement").hide(); }else{ $("#announcement").show(); } $("#announcement .close-announcement").click(function(){ $("#announcement").slideUp(500 , "easeInOutQuad"); $.cookie("ts-hide-banner" , "1", {path: '/'}); return false; }); }

/* responsive main nav menu -------------------------------*/ mainNavChildren($("#main-nav-menu > ul") , 0); function mainNavChildren(parent , level){ $(parent).children("li").each(function(i , obj){ var label = ""; for(var k = 0 ; k < level ; k++){ label += "      "; } label += $(obj).children("a").text(); $("#responsive-main-nav-menu").append("<option " + ($(obj).hasClass("current") ? "selected = 'selected' " : "") + "value = '" + $(obj).children("a").attr("href") + "'>" + label + "</option>");

if($(obj).children("ul").size() == 1){ mainNavChildren($(obj).children("ul") , level + 1); } }); }

/* main nav menu -------------------------------*/ $("#main-nav-menu").find("li:has(ul) > a").each(function(){ $(this).append("<span class = 'indicator'/>"); });

$("#main-nav-menu").find("li:has(ul)").hover( function(){ var ul = $(this).children("ul"); ul.hide(); ul.fadeIn(250); } , function(){ $(this).children("ul").hide(); } );

/* top links -------------------------------*/

$("body").append("");

$(".divider a, .page-top-link").click(function(){ $(window.opera ? "html" : "html, body").stop(true , true).animate({scrollTop: 0} , 1500 , "easeInOutQuad"); return false; });

/* text input prompt -------------------------------*/ $("input[type='text'],textarea").each(function(){ var prompt = $(this).data("prompt");

if(prompt == undefined) return;

$(this).val(prompt).data("original-value" , prompt); if($(this).val() == prompt) $(this).addClass("js-original");

$(this).focusin(function(){ if($(this).val() == $(this).data("original-value")) $(this).val(""); $(this).removeClass("js-original"); });

$(this).focusout(function(){ if($(this).val() == ""){ $(this).val($(this).data("original-value")); $(this).addClass("js-original"); } }); });

/* tabs -------------------------------*/ $(".tab").each(function(){ if(!$(this).hasClass("active")){ $(this).parent().next().find(".tab-body:nth-child(" + ($(this).index() + 1) + ")").hide(); }

$(this).click(function(){ if(!$(this).hasClass("active")){ $(this).parent().find(".tab").removeClass("active"); $(this).addClass("active"); $(this).parent().next().find(".tab-body").hide(); $(this).parent().next().find(".tab-body:nth-child(" + ($(this).index() + 1) + ")").fadeIn(); return false; } }); });

/* toggle -------------------------------*/ $(".toggle-title").each(function(){ if(!$(this).parent().hasClass("active")){ $(this).next().hide(); } $(this).click(function(){ $(this).next().slideToggle(Math.min(600 , Math.max(300 , $(this).next().height()))); $(this).parent().toggleClass("active"); return false; }); });

/* accordion -------------------------------*/ $(".accordion-panel-title").each(function(){ if(!$(this).parent().hasClass("active")){ $(this).next().hide(); }

$(this).click(function(){ if($(this).next().is(":hidden")){ $(this).parent().parent().find(".accordion-panel-title").next().slideUp(Math.min(600 , Math.max(300 , $(this).next().height()))).parent().removeClass("active"); $(this).next().slideDown(Math.min(600 , Math.max(300 , $(this).next().height()))).parent().toggleClass("active"); }

return false; }); });

/* flex slider -------------------------------*/ $(".flexslider").flexslider({ directionNav: false , controlNav: true , pauseOnAction: false , pauseOnHover: true , animation: "fade" , animationDuration: 150 , start: function(slider){

var controlsRight = $("
");

var nextNav = $("<a class = 'next'>Next</a>"); var prevNav = $("<a class = 'prev'>Prev</a>"); var controlNav = slider.find(".flex-control-nav");

controlsRight.append(prevNav).append(nextNav); slider.append(controlsRight);

nextNav.click(function(){ slider.flexAnimate(slider.getTarget("next")); });

prevNav.click(function(){ slider.flexAnimate(slider.getTarget("prev")); });

/* left nav */ var controlsLeft = controlsRight.clone(true).removeClass("right-nav").addClass("left-nav").appendTo(slider); var nextNavLeft = controlsLeft.find("a.next");

controlsRight.prepend(nextNav);

/* actions */ controlNav.appendTo(controlsRight).after(controlNav.prev()); prevNav.stop(true , true).css({"margin-right": -prevNav.outerWidth() - 40 , "opacity": 0}); nextNavLeft.stop(true , true).css({"margin-left": -prevNav.outerWidth() - 40 , "opacity": 0}); controlNav.stop(true , true).css({"margin-right": -controlNav.outerWidth() - 40 , "opacity": 0});

controlsRight.hover( function(){ prevNav.stop(true , true).animate({"margin-right": 0 , "opacity": 1} , 250);

var controlNav = $(this).find(".flex-control-nav"); if(controlNav.length == 0){ controlNav = $(this).next().find(".flex-control-nav"); controlNav.appendTo(this).after(controlNav.prev()); } controlNav.stop(true , true).css({"margin-right": -controlNav.outerWidth() - 40 , "opacity": 0 , "margin-left": "auto"}).animate({"margin-right": 0 , "opacity": 1} , 250); } , function(){ prevNav.stop(true , true).animate({"margin-right": -prevNav.outerWidth() - 40 , "opacity": 0} , 300 , "easeInOutQuad");

var controlNav = $(this).find(".flex-control-nav"); controlNav.stop(true , true).css("margin-left" , "auto").animate({"margin-right": -controlNav.outerWidth() - 40 , "opacity": 0} , 300 , "easeInOutQuad"); } );

controlsLeft.hover( function(){ nextNavLeft.stop(true , true).animate({"margin-left": 0 , "opacity": 1} , 250);

var controlNav = $(this).find(".flex-control-nav"); if(controlNav.length == 0){ controlNav = $(this).prev().find(".flex-control-nav"); controlNav.appendTo(this).after(controlNav.prev()); } controlNav.stop(true , true).css({"margin-left": -controlNav.outerWidth() - 40 , "opacity": 0 , "margin-right": "auto"}).animate({"margin-left": 0 , "opacity": 1} , 250); } , function(){ nextNavLeft.stop(true , true).animate({"margin-left": -nextNavLeft.outerWidth() - 40 , "opacity": 0} , 300 , "easeInOutQuad");

var controlNav = $(this).find(".flex-control-nav"); controlNav.stop(true , true).css("margin-right" , "auto").animate({"margin-left": -controlNav.outerWidth() - 40 , "opacity": 0} , 300 , "easeInOutQuad"); } ); } });

$(".flexslider.autohide .controls").hide(); $(".flexslider.autohide").hover( function(){ $(this).find(".controls").css("display" , "block").children("a").stop(true,true).fadeIn(150); } , function(){ $(this).find(".controls").css("display" , "block").children("a").stop(true,true).fadeOut(150); } );

/* colorbox -------------------------------*/ $(".colorbox").each(createColorbox);

function createColorbox(i , obj){ var $colorboxArgs = new Object(); $colorboxArgs.innerWidth = $(obj).data("width") || false; $colorboxArgs.innerHeight = $(obj).data("height") || false; $colorboxArgs.slideshow = String($(obj).data("slideshow")).toLowerCase() == "true"; $colorboxArgs.slideshowAuto = String($(obj).data("slideshowauto")).toLowerCase() == "true"; $colorboxArgs.iframe = String($(obj).data("iframe")).toLowerCase() == "true"; $colorboxArgs.inline = String($(obj).data("inline")).toLowerCase() == "true"; $colorboxArgs.photo = String($(obj).data("photo")).toLowerCase() == "true"; $colorboxArgs.rel = $(obj).data("group"); $colorboxArgs.fixed = true;

if(!$(obj).is("a")) $colorboxArgs.href = $(obj).data("href"); if(!$colorboxArgs.innerWidth) $colorboxArgs.innerWidth = $colorboxArgs.iframe ? 480 : false; if(!$colorboxArgs.innerHeight) $colorboxArgs.innerHeight = $colorboxArgs.iframe ? 360 : false;

$colorboxArgs.maxWidth = "100%"; $colorboxArgs.maxHeight = "100%"; $colorboxArgs.speed = 600; $colorboxArgs.opacity = 0.75; $colorboxArgs.current = "{current} / {total}";

$colorboxArgs.onComplete = function(){ if(!$("#colorbox").data("isInitiated")){ $("#colorbox").data("isSlideshow" , $("#cboxSlideshow").css("display") != "none"); $("#colorbox").data("isSingle" , $("#cboxNext").css("display") == "none"); }else{ if($("#colorbox").data("mouseOver") == false){ $("#cboxNext").hide(); $("#cboxPrevious").hide(); $("#cboxSlideshow").hide(); $("#cboxClose").hide(); } }

if($("#colorbox").data("isInitiated")){ return; }

$("#colorbox").hover( function(){ $("#colorbox").data("mouseOver" , true); $("#cboxClose").fadeIn(150);

if(!$("#colorbox").data("isSingle")){ $("#cboxNext").fadeIn(150); $("#cboxPrevious").fadeIn(150); }

if($("#colorbox").data("isSlideshow")){ $("#cboxSlideshow").fadeIn(150); } } , function(){ $("#colorbox").data("mouseOver" , false); $("#cboxClose").fadeOut(150);

if(!$("#colorbox").data("isSingle")){ $("#cboxNext").fadeOut(150); $("#cboxPrevious").fadeOut(150); }

if($("#colorbox").data("isSlideshow")){ $("#cboxSlideshow").fadeOut(150); } } );

$("#colorbox").data("isInitiated" , true); }//end onComplete

$colorboxArgs.onCleanup = function(){ $("#colorbox").data("isInitiated" , false); }//end onCleanup

$(obj).colorbox($colorboxArgs); }

/* audio/video -------------------------------*/ $("audio,video").mediaelementplayer();

/* twitter feed -------------------------------*/ $(".twitter-feed").each(function(){ var output = $(this).html().replace(/%7B/g , "{").replace(/%7D/g , "}"); $(this).html(""); $(this).social({ network : "twitter", loadingText : "Loading...", user : $(this).attr("data-user"), count: 3 , twitter : { output : String(output) } }); });

/* flickr feed -------------------------------*/ $(".flickr-feed").each(function(){ var output = $(this).html().replace(/%7B/g , "{").replace(/%7D/g , "}"); $(this).html(""); $(this).social({ network : "flickr", loadingText : "Loading...", user : $(this).attr("data-user"), count: 9 , flickr : { output : String(output) } }); });

/* contact form -------------------------------*/ $(".contact-form").each(function(){ var form = $(this);

form.find("*[type='submit']").click(function(){ var name = form.find("input[name='name']"); var email = form.find("input[name='email']"); var message = form.find("textarea[name='message']"); var website = form.find("textarea[name='website']"); var to = form.find("input[name='to']");

email.removeClass("invalid"); form.parent().find(".form-failure").hide();

if(name.val() == name.attr("data-prompt") || name.val() == ""){ name.focus(); return false; }

if(email.val() == email.attr("data-prompt") || email.val() == ""){ email.focus(); return false; }

if(email.val().indexOf("@",0) == -1 || email.val().indexOf(".",0) == -1){ email.focus(); email.addClass("invalid"); return false; }

if(message.val() == message.attr("data-prompt") || message.val() == ""){ message.focus(); return false; }

var dataString = "name=" + name.val() + "&email=" + email.val() + "&message=" + message.val() + "&to=" + to.val(); if(website != undefined) dataString += "&website=" + website.val();

$.ajax({ type: "POST" , url: form.attr("action") , data: dataString , success: function(r){ if(r == "missing_name"){ name.focus(); }else if(r == "missing_email"){ email.focus(); }else if(r == "missing_message"){ message.focus(); }else if(r == "invalid_email"){ email.focus(); email.addClass("invalid"); }else if(r == "success"){ form.hide(); form.parent().find(".form-success").fadeIn(500); }else if(r == "failure"){ form.parent().find(".form-failure").fadeIn(500); } } , error: function(r){ form.parent().find(".form-failure").fadeIn(500); } });

return false; }); });

/* quicksand -------------------------------*/ var itemsByTags = {}; var cols = 4;

jQuery("#portfolio.filterable .row").attr("style" , "height: auto !important;"); if(jQuery("#portfolio.filterable").hasClass("portfolio-3")) cols = 3; if(jQuery("#portfolio.filterable").hasClass("portfolio-2")) cols = 2;

var items = jQuery("#portfolio.filterable .span-" + (12/cols));

items.each(function(i){ var elem = jQuery(this), tags = elem.data("tags").split(",");

elem.attr("data-id" , i);

jQuery(elem).removeClass("first"); if((i)%cols == 0) jQuery(elem).addClass("first");

jQuery.each(tags,function(key,value){ value = jQuery.trim(value);

if(!(value in itemsByTags)){ itemsByTags[value] = []; }

itemsByTags[value].push(elem); }); });

createList("All" , items);

jQuery.each(itemsByTags,function(k,v){ createList(k,v); });

jQuery("#portfolio-filter li").on("click",function(e){ var link = jQuery(this);

jQuery("#portfolio.filterable .row").removeAttr("style"); link.addClass("active").siblings().removeClass("active");

jQuery("#portfolio.filterable > div").quicksand(link.data("list").find(".span-" + (12/cols)) , { adjustHeight: jQuery("#portfolio.filterable").data("s") ? "dynamic" : "auto" , easing: "easeInOutQuad" , duration: 750 , useScaling: true, enhancement: function(){ // re-colorbox jQuery("#portfolio.filterable .colorbox").each(createColorbox);

// ie-overlay if(window.ie_overlay) jQuery(".overlay").each(ie_overlay); } });

e.preventDefault(); });

jQuery("#portfolio-filter li:first").click(); jQuery("#portfolio.filterable").data("s" , true);

function createList(text,items){

var ul = jQuery("
");

jQuery.each(items,function(i){ var item = jQuery(this).clone(); jQuery(item).removeClass("first"); if((i)%cols == 0) jQuery(item).addClass("first"); item.appendTo(ul); });

var a = jQuery("
  • ",{ html: text, data: {list:ul} }); a.addClass("tab").appendTo("#portfolio-filter > ul"); } /* compact portfolio -------------------------------*/ $(".portfolio.compact .entry .more").click(function(){ var entry = $(this).closest(".entry"); $(".portfolio.compact .entry").not(entry).removeClass("active"); entry.toggleClass("active"); $(".portfolio.compact .entry").each(function(i , obj){ var entryWrap, entryFeature, dy, da, dh; entryWrap = $(obj).find(".entry-wrap"); entryFeature = entryWrap.find(".entry-feature"); if($(obj).hasClass("active") == true){ dy = entryFeature.outerHeight(); da = 0.2; dh = Math.max($(entryWrap).height() , $(entryWrap).height() - $(this).find(".entry-feature").outerHeight() + $(this).find(".entry-content").outerHeight() + 30); }else{ dy = 0; da = 1; dh = $(entryWrap).height(); } if($(obj).data("ts") == "1"){ entryFeature.stop(true , true).animate({opacity: da} , 600 , "easeInOutQuad"); entryWrap.find(".entry-content").stop(true , true).animate({opacity: da == 1 ? 0 : 1} , da == 1 ? 500 : 800 , "easeInOutQuad"); entryWrap.stop(true , true).animate({top: -dy} , 600 , "easeInOutQuad"); $(this).stop(true , true).animate({height: dh} , 200 , "easeInOutQuad"); } }); return false; }); top.updateCompactPortfolioEntry = function(target){ var entry = $(target).closest(".entry"); var entryWrap = entry.find(".entry-wrap"); var dy = entry.find(".entry-feature").outerHeight(); entryWrap.find(".entry-content").css("opacity" , 0); $(entryWrap).height(dy + entry.find("header").outerHeight() + 30); entry.height($(entryWrap).height()); entry.data("ts" , "1"); } $(".portfolio.compact .entry").each(function(){ var images = $(this).find(".entry-feature img"); if(images.size() > 0){ // image var image = images[0]; $(image).attr("onload" , "top.updateCompactPortfolioEntry(this);").attr("src" , $(image).data("tsrc")); }else{ // iframe var iframe = $(this).find(".entry-feature iframe"); iframe = iframe[0]; top.updateCompactPortfolioEntry(iframe); } }); /* window scroll -------------------------------*/ $(".sticky-nav").fadeIn(200); $(".sticky-nav .next, .sticky-nav .prev").click(function(){ var pos = stickyNavScroll($(this).parent() , $(this).hasClass("next") ? "next" : "prev"); if(pos !== false) $(window.opera ? "html" : "html, body").stop(true , true).animate({scrollTop: pos} , 1000 , "easeInOutQuad"); return false; }); $(".blog .leave-a-comment, .blog .leave-a-comment-text").click(function(){ $(window.opera ? "html" : "html, body").stop(true , true).animate({scrollTop: $(".blog #comment-form").offset().top - 20} , 1000 , "easeInOutQuad"); return false; }); $(window).scroll(function(){ if($(window).scrollTop() > 150){ $(".back-to-top").stop(true , true).fadeIn(200); }else{ $(".back-to-top").stop(true , true).fadeOut(200); } updateStickyNav(); }); $(window).scroll(); $(window).resize(updateStickyNav); function updateStickyNav(){ var nav = $(".sticky-nav").eq(0); if(!nav.parent().offset()) return; var a = nav.parent().offset().top - 20; var b = nav.parent().children(".entry").size() > 1 ? nav.parent().children(".entry").last().offset().top - 20 : nav.parent().height() - nav.height() + nav.parent().offset().top; var wst = $(window).scrollTop(); if(wst > a && wst < b){ nav.css({position: "fixed" , top: 20 , left: nav.parent().offset().left - 100}); }else if(wst >= b){ nav.css({position: "absolute" , top: b - a , left: - 100}); }else{ nav.css({position: "absolute" , top: 0 , left: - 100}); } } function stickyNavScroll(nav , dir){ var ret = false; var tmp = 9E10; var pos = $(nav).offset().top; if(dir == "prev") tmp *= -1; $(nav).parent().children(".entry").each(function(i){ if(dir == "next"){ if($(this).offset().top - pos > 10 && $(this).offset().top - pos < tmp){ tmp = $(this).offset().top - pos; ret = $(this).offset().top - 20; } }else{ if($(this).offset().top - pos < -10 && $(this).offset().top - pos > tmp){ tmp = $(this).offset().top - pos; ret = $(this).offset().top - 20; } } }); return ret; } }); /* --- END READY --- */