Team:UNITN-Trento/JS/Protocols

From 2013.igem.org

(Difference between revisions)
Line 8: Line 8:
**/
**/
(function ($) {
(function ($) {
-
alert(1);
 
$.scrollTo = $.fn.scrollTo = function(x, y, options){
$.scrollTo = $.fn.scrollTo = function(x, y, options){
    if (!(this instanceof $)) return $.fn.scrollTo.apply($('html, body'), arguments);
    if (!(this instanceof $)) return $.fn.scrollTo.apply($('html, body'), arguments);
Line 33: Line 32:
    });
    });
};
};
-
alert(2);
 
})(jQuery);
})(jQuery);
Line 48: Line 46:
e.preventDefault();
e.preventDefault();
-
alert(3);
+
 
if(al.parent().hasClass("tn-spoiler-protocol-active")) {
if(al.parent().hasClass("tn-spoiler-protocol-active")) {
//Remove the 'active' status
//Remove the 'active' status
Line 55: Line 53:
$(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp();
$(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp();
} else {
} else {
-
alert(4);
 
//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 63: Line 60:
$(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp();
$(".tn-spoiler-protocol").not(".tn-spoiler-protocol-active").children("div").slideUp();
//Open active PS
//Open active PS
-
alert(5);
 
$(".tn-spoiler-protocol-active").children("div").slideDown(600, function() {
$(".tn-spoiler-protocol-active").children("div").slideDown(600, function() {
-
alert(6);
 
$("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"));
-
alert(7);
 
});
});
}
}

Revision as of 16:26, 8 July 2013

/*!

  • jquery.scrollto.js 0.0.1 - https://github.com/yckart/jquery.scrollto.js
  • Scroll smooth to any element in your DOM.
  • Copyright (c) 2012 Yannick Albert (http://yckart.com)
  • Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
  • 2013/02/17
    • /

(function ($) { $.scrollTo = $.fn.scrollTo = function(x, y, options){ if (!(this instanceof $)) return $.fn.scrollTo.apply($('html, body'), arguments);

options = $.extend({}, { gap: { x: 0, y: 0 }, animation: { easing: 'swing', duration: 600, complete: $.noop, step: $.noop } }, options);

return this.each(function(){ var elem = $(this); elem.stop().animate({ scrollLeft: !isNaN(Number(x)) ? x : $(x).offset().left + options.gap.x, scrollTop: !isNaN(Number(y)) ? y : $(y).offset().top + options.gap.y }, options.animation); }); }; })(jQuery);

$(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); }); } }); } */ });