Team:UNITN-Trento/JS/Protocols
From 2013.igem.org
(Created page with "$(document).ready(function() { - →Protocol Spoiler: $(".tn-spoiler-protocol div").not(".tn-spoiler").slideUp(); //Reset first spoiler link default $(".tn-spoiler-protocol > a...") |
|||
Line 1: | Line 1: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
+ | |||
/*Protocol Spoiler*/ | /*Protocol Spoiler*/ | ||
$(".tn-spoiler-protocol div").not(".tn-spoiler").slideUp(); | $(".tn-spoiler-protocol div").not(".tn-spoiler").slideUp(); | ||
+ | |||
//Reset first spoiler link default | //Reset first spoiler link default | ||
$(".tn-spoiler-protocol > a").each(function() { | $(".tn-spoiler-protocol > a").each(function() { | ||
var al = $(this); | var al = $(this); | ||
+ | //Modify click event of each ProtocolSpoiler link | ||
al.click(function(e) { | al.click(function(e) { | ||
+ | |||
e.preventDefault(); | e.preventDefault(); | ||
+ | |||
if(al.parent().hasClass("tn-spoiler-protocol-active")) { | if(al.parent().hasClass("tn-spoiler-protocol-active")) { | ||
+ | //Remove the 'active' status | ||
$(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); | $(".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(); | $(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); | ||
} else { | } else { | ||
+ | //Remove the 'active' status | ||
$(".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 | ||
al.parent().addClass("tn-spoiler-protocol-active"); | al.parent().addClass("tn-spoiler-protocol-active"); | ||
+ | //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(); | ||
- | $(".tn-spoiler-protocol-active").children("div"). | + | //Open active PS |
+ | $(".tn-spoiler-protocol-active").children("div").slideDown(600, function() { | ||
$("html,body").scrollTo($(".tn-spoiler-protocol-active > a").attr("href"),$(".tn-spoiler-protocol-active > a").attr("href")); | $("html,body").scrollTo($(".tn-spoiler-protocol-active > a").attr("href"),$(".tn-spoiler-protocol-active > a").attr("href")); | ||
}); | }); | ||
Line 21: | Line 32: | ||
}); | }); | ||
+ | /* | ||
//Open spoiler based on Hash (at page request) | //Open spoiler based on Hash (at page request) | ||
if (document.location.hash != "") { | if (document.location.hash != "") { | ||
Line 34: | Line 46: | ||
}); | }); | ||
} | } | ||
+ | */ | ||
}); | }); |
Revision as of 15:58, 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) {
e.preventDefault();
if(al.parent().hasClass("tn-spoiler-protocol-active")) { //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(600, function() { $("html,body").scrollTo($(".tn-spoiler-protocol-active > a").attr("href"),$(".tn-spoiler-protocol-active > a").attr("href")); }); } }); });
/* //Open spoiler based on Hash (at page request) if (document.location.hash != "") { $(".tn-spoiler-protocol > a").each(function() { if ($(this).attr("href") == document.location.hash) { $(".tn-spoiler-protocol-active").removeClass("tn-spoiler-protocol-active"); $(this).parent().addClass("tn-spoiler-protocol-active"); $(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp(); $(".tn-spoiler-protocol-active").children("div").slideToggle(600, function() { $("html,body").scrollTo(document.location.hash,document.location.hash); }); } }); } */ });