Team:Heidelberg/js/wikipage

From 2014.igem.org

(Difference between revisions)
Line 1: Line 1:
 +
var collapsed = false;
 +
 +
function centerDropdowns(){
 +
$("ul.dropdown-menu").each(function(){
 +
    var parentWidth = $(this).parent().innerWidth();
 +
    var menuWidth = $(this).innerWidth();
 +
    var margin = (parentWidth / 2 ) - (menuWidth / 2);
 +
    margin = margin + "px";
 +
    $(this).css("margin-left", margin);
 +
});
 +
}
 +
document.onreadystatechange = function() {
document.onreadystatechange = function() {
-
     if (document.readyState === 'complete') {
+
     if (document.readyState === 'complete'){
-
         $("ul.dropdown-menu").each(function(){
+
         if($(window).width() >= 768) {
-
             var parentWidth = $(this).parent().innerWidth();
+
             centerDropdowns();
-
            var menuWidth = $(this).innerWidth();
+
        }
-
            var margin = (parentWidth / 2 ) - (menuWidth / 2);
+
        else
-
            margin = margin + "px";
+
            collapsed = true;
-
            $(this).css("margin-left", margin);
+
    }
-
         });
+
}
-
        alert("Changed!");
+
 
 +
 
 +
/* Center Dropdown menu if not collapsed */
 +
$(window).resize(function(){
 +
if($(window).width() >= 768){
 +
    if(collapsed == true){
 +
        centerDropdowns();
 +
        collapsed = false;
 +
    }
 +
}
 +
else{
 +
    if(collapsed == false){
 +
        $("ul.dropdown-menu").css("margin-left", "");
 +
         collapsed = true;
     }
     }
}
}
 +
 +
   
 +
 +
});

Revision as of 13:19, 3 October 2014

var collapsed = false;

function centerDropdowns(){ $("ul.dropdown-menu").each(function(){

   var parentWidth = $(this).parent().innerWidth();
   var menuWidth = $(this).innerWidth();
   var margin = (parentWidth / 2 ) - (menuWidth / 2);
   margin = margin + "px";
   $(this).css("margin-left", margin);

}); }

document.onreadystatechange = function() {

   if (document.readyState === 'complete'){
       if($(window).width() >= 768) {
           centerDropdowns();
       }
       else
           collapsed = true;
   }

}


/* Center Dropdown menu if not collapsed */ $(window).resize(function(){ if($(window).width() >= 768){

   if(collapsed == true){
       centerDropdowns();
       collapsed = false;
   }

} else{

   if(collapsed == false){
       $("ul.dropdown-menu").css("margin-left", "");
       collapsed = true;
   }

}


});