Team:TUDelft/js/script

// store the hash (DON'T put this code inside the $() function, it has to be executed // right away before the browser can start scrolling! var target = window.location.hash,

   target = target.replace('#', );

// delete hash so the page won't scroll to it window.location.hash = "";

// now whenever you are ready do whatever you want // (in this case I use jQuery to scroll to the tag after the page has loaded) $(window).on('load', function() {

   if (target) {
       $('html, body').animate({
           scrollTop: $("#" + target).offset().top
       }, 700, 'swing', function () {});
   }

});

(function () {

   $(function ($) {
 
       //navbar
       $(".dropdown-button").dropdown({
           hover: false,
           constrainWidth: false,
           belowOrigin: true
       });
       $('#menu-btn').click(function () {
           $('nav').addClass('show-nav');
       });
       $('#cross').click(function () {
           $('nav').removeClass('show-nav');
       });
       var module_classes = ['cas13a', 'TDP', 'detection', 'sampleprep', 'vesicles'];
       var whosActive = function () {
           var active = new Array(module_classes.length);
           $('#notebook-buttons>a').each(function (index) {
               var $this = $(this);
               active[index] = hasClass($this, 'active');
           })
           return active;
       };
       var hasClass = function ($el, className) {
           return $el.attr('class').split(' ').some(
               el => el === className)
       };
       var display = function (active) {
           for (var i = 0; i < active.length; i++) {
               var $module = $("." + module_classes[i]);
               if (active[i]) {
                   $module.css("display", "block");
               } else {
                   $module.css("display", "none");
               }
           }
       };
       display(whosActive()) // initialization
       $('#notebook-buttons>a').each(function (index) {
           var $this = $(this);
           $this.on('click', function () {
               console.log("I clicked this");
               $this.toggleClass('active');
               display(whosActive());
           });
       });
       


       //toc
       //        $(".scrollspy").scrollSpy();
       //        setTimeout(function () {
       //            $("#toc").pushpin({
       //                offset: 150,
       //                top: 0,
       //                bottom: $('footer').offset().top - $('#toc').outerHeight(true)
       //            })
       //        }, 100);
       //timeline
       //        $(".scrollspy").scrollSpy(
       //            {
       //                getActiveElement: function (id) {
       //                    return "round" + (parseInt(id.replace(/\D/g, )) - 20);
       //                }
       //            }
       //        );
       $(".scrollspy").scrollSpy();


       //main
       //        function scaleIn() {
       //            $("scaleIn").each(function() {
       //                setTimeout(function () {
       //                    $(this).addClass('activated');
       //                }, 500)
       //            });
       //        }
       function scaleIn(el) {
           console.log("im called");
           $(".scaleIn").each(function (index) {
               var that = $(this);
               setTimeout(function () {
                   that.addClass('activated')
               }, 200 * index);
           })
       }
       $('select').material_select();


       var options = [{
           selector: '#thisList',
           offset: 500,
           callback: function (el) {
               Materialize.showStaggeredList($(el));
           }
           }, {
           selector: '#row1',
           offset: 0,
           callback: scaleIn
           }];
       Materialize.scrollFire(options);
       var white = " ",
           first = "\u00A0\u00A0tudelft",
           secon = "igem",
           third = "gmail",
           forth = "com",
           all = " " + " " + first + "." + secon + "@" + third + "." + forth,
           sall = " " + " " + all,
           ma = "ma" + "il",
           mm = ma + "to" + ":";
       // Dynamically add e-mail to distract spam bots
       $("#mail-button").attr("href", mm + all.trim());
       $("#email").text(white + sall);
       // Removing empty p tages
       $("p").filter(function () {
           return $.trim($(this).text()) === ;
       }).remove();
       $('top_menu_14, top_menu_inside ').on('touchstart', function (e) {
           var $this = $(this);
           if ($this.hasClass('hover')) {
               return true
           } else {
               $this.addClass('hover');
               e.preventDefault();
               return false; // Is this a hack? Unnecesary code anyways. preventDefault should do it already, be you never know you know. 
           }
       })

   });

}($));

function filter_notebook(select) {

   console.log(select);

} // function for copying text to clipboard (used for phone number) function copyToClipboard(element) {

   var $temp = $("<input>");
   $("body").append($temp);
   $temp.val(element).select();
   document.execCommand("copy");
   $temp.remove();
   alert("You copied: " + element + ".");

}