Team:UNITN-Trento/JS/Protocols
From 2013.igem.org
(One intermediate revision not shown) | |||
Line 11: | Line 11: | ||
al.click(function(e) { | al.click(function(e) { | ||
if(al.parent().hasClass("tn-spoiler-protocol-active")) { | if(al.parent().hasClass("tn-spoiler-protocol-active")) { | ||
+ | e.preventDefault(); | ||
//Remove the 'active' status | //Remove the 'active' status | ||
$(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); | $(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); | ||
Line 16: | Line 17: | ||
$(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); | $(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); | ||
} else { | } else { | ||
+ | |||
//Remove the 'active' status | //Remove the 'active' status | ||
$(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); | $(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); | ||
Line 36: | Line 38: | ||
$(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); | $(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); | ||
//Add the 'active' status to the current link parent | //Add the 'active' status to the current link parent | ||
- | + | $(this).parent().addClass("tn-spoiler-protocol-active"); | |
//Close all 'non-active' PS | //Close all 'non-active' PS | ||
$(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); | $(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); |
Latest revision as of 16:38, 8 July 2013
$(document).ready(function() {
/*Protocol Spoiler*/ $(".tn-spoiler-protocol div").not(".tn-spoiler").slideUp();
//Reset first spoiler link default $(".tn-spoiler-protocol > a").each(function() { var al = $(this); //Modify click event of each ProtocolSpoiler link al.click(function(e) { if(al.parent().hasClass("tn-spoiler-protocol-active")) { e.preventDefault(); //Remove the 'active' status $(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); //Slide up all 'non-active' PS $(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); } else {
//Remove the 'active' status $(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); //Add the 'active' status to the current link parent al.parent().addClass("tn-spoiler-protocol-active"); //Close all 'non-active' PS $(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); //Open active PS $(".tn-spoiler-protocol-active").children("div").slideDown(); } }); });
//Open spoiler based on Hash (at page request) if (document.location.hash != "") { $(".tn-spoiler-protocol > a").each(function() { //Select the PS based on the hash if ($(this).attr("href") == document.location.hash) { //Remove the 'active' status $(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); //Add the 'active' status to the current link parent $(this).parent().addClass("tn-spoiler-protocol-active"); //Close all 'non-active' PS $(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); //Open active PS $(".tn-spoiler-protocol-active").children("div").slideDown(); } }); } });