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("