Team:SDU-Denmark/core/scripts

From 2013.igem.org

Revision as of 15:31, 8 September 2013 by Heidi.Wille (Talk | contribs)

function isInt(n) {

   return (n+"").match(/^\d+$/);

} function handleStickyTopBar() {

   var viewportHeight = $(window).height();
   var totalPageHeight = $(document).height();
   if (totalPageHeight > viewportHeight) {
       $(".MainLayout").css("margin-bottom", "100px");
   }
   else {
       $(".MainLayout").css("margin-bottom", "0");
   }
   var window_top = $(window).scrollTop();
   var div_top = $('#sticky-anchor').offset().top;
   if (window_top > div_top) {
       $('.top').addClass('stick');
       $('.tourBoundingBox').addClass('stick2');
       $('.tourBoundingBoxInner').css('margin-left', 13);
       $(".topMargin").css("margin-top", "113px");
   } else {
       $('.top').removeClass('stick');
       $('.tourBoundingBox').removeClass('stick2');
       $('.tourBoundingBoxInner').css('margin-left', 0);
       $(".topMargin").css("margin-top", "25px");
   }

} function enableMenuDropdown() {

   $('#btnMenu, .menuPopup, #btnMenu2').hover(
       function () {
           $('.menuPopup').show();
       },
       function () {
           $('.menuPopup').hide();
       }
   );

} function styleIGEMTopMenu() {

   $('.left-menu').children().first().children().last().css('color', );
   $('.left-menu').children().first().children().last().css('font-size', '10px');
   $('#menubar').bind("mouseover", function () {
       $(this).css("background", "transparent");
       $('#menubar').css("background", "transparent");
   });

}

function hideTestElementsOnLiveSite() {

 var pathname = window.location.pathname;
 if (pathname.toLowerCase().indexOf('test') < 0) {
    $('.testing').hide();
 }

}

       function HandleSelectedTourItems(allItems, selectedIndex, isClosed) {
           for (var i = 0; i < allItems.length; i++) {
               var currentSelected = allItems.eq(i);
               if (i < selectedIndex) {
                   if (i == selectedIndex - 1 && isClosed) {
                       currentSelected.addClass('itemLastSelected');
                       currentSelected.children('.tourItemLabel').first().addClass('tourItemLabelSelected');
                   }
                   else {
                       currentSelected.addClass('itemSelected');
                       currentSelected.removeClass('tourItemLabelSelected');
                   }
               }
               else {
                   currentSelected.removeClass('itemLastSelected');
                   currentSelected.removeClass('itemSelected');
                   currentSelected.removeClass('tourItemLabelSelected');
               }
           }
       }
       function ToggleTourMenu() {
           var parentIndex = 2;
           var childIndex = 1;



           // Not a tour-site
           if (parentIndex == 0) {
               $('.tourBoundingBox').hide();
               $('.tourBoundingBox').css('position', 'fixed');
               return;
           }
           // Handle parent items
           var parents = $('.tourBoundingBox').children('.parentTourItem');
           HandleSelectedTourItems(parents, parentIndex, childIndex == 0);
           // Show/Hide expand boxes
           var expandBoxes = $('.tourBoundingBox').children('.expandedTour');
           for (var i = 0; i < expandBoxes.length; i++) {
               if (i == parentIndex -1) {
                   expandBoxes.eq(i).show();
               }
               else {
                   expandBoxes.eq(i).hide();
               }
           }
           var selectedExpandBox = expandBoxes.eq(parentIndex - 1);
           var selectedInnerExpandBox = selectedExpandBox.children('.expandedTourInner').first();
           // Handle bend color
           if (childIndex > 0) {
               selectedExpandBox.children().first().addClass('tourBendLeftSelected');
               HandleSelectedTourItems(selectedInnerExpandBox.children('.parentTourItem'), childIndex, true);
           }
           else {
               selectedExpandBox.children().first().removeClass('tourBendLeftSelected');
           }
           // Calculate width of children
           var childrens = selectedInnerExpandBox.children('.parentTourItem');
           var childrensTotalWidth = 0;
           for (var i = 0; i < childrens.length; i++) {
               childrensTotalWidth = childrensTotalWidth + childrens.eq(i).outerWidth();
           }
           var remainingSpaceToFill = selectedInnerExpandBox.innerWidth() - childrensTotalWidth -1;  // -1 fixes IE
           var childrenHMargin = remainingSpaceToFill / childrens.length / 2;
           // Ensures enough room for all paddings. If not enough room, all items will try to be centered.
           if (childrenHMargin > childrens.length * 2) {
               childrens.each(function () {
                   $(this).css('padding-left', childrenHMargin);
                   $(this).css('padding-right', childrenHMargin);
               });
           }
           else if (remainingSpaceToFill > 2) {
               childrens.first().css('padding-left', remainingSpaceToFill / 2);
               childrens.last().css('padding-right', remainingSpaceToFill / 2);
           }


           // Add links for all items
           $('.tourBoundingBox').children('.parentTourItem').each(function (index) {
               $(this).children().first().attr('href', "Tour" + (index+1) + "0" + ".html");
           });
           $('.tourBoundingBox').children('.expandedTour').each(function (indexP) {
               $(this).children('.expandedTourInner').first().children('.parentTourItem').each(function (indexC) {
                   $(this).children().first().attr('href', "https://2013.igem.org/Team:SDU-Denmark/Tour" + (indexP + 1) + (indexC +1) + ".html");
               });
           });
       }

$(document).ready(function () {

   styleIGEMTopMenu();
   $(window).scroll(handleStickyTopBar);
   enableMenuDropdown();
   

ToggleTourMenu();

   hideTestElementsOnLiveSite();
   

});