Team:EPF-Lausanne/Template/script.js

From 2012.igem.org

(Difference between revisions)
 
(21 intermediate revisions not shown)
Line 1: Line 1:
//Generate private namespace
//Generate private namespace
window.EPFL = (function(){
window.EPFL = (function(){
-
//Little hack to stop MediaWiki from replacing ampersands...
+
  //Little hack to stop MediaWiki from replacing ampersands...
-
var amp = unescape("%26");
+
  var amp = unescape("%26");
-
return {
+
  return {
-
namingRegex: /^(\/|([A-Z][a-z]*))*[0-9]*$/,
+
    namingRegex: /^(\/|([A-Z][a-z]*))*[0-9]*$/,
-
registerNewPageButton: function(titleID, buttonID, base, preload, check){
+
    dateRegex: /^([0-9]+) ([A-Z][a-z]+) ([0-9]+)$/,
-
$(buttonID).click(function(){
+
    registerNewPageButton: function(titleID, buttonID, base, preload, check){
-
if(check != undefined){
+
      $(buttonID).click(function(){
-
if(!check(base, $(titleID).val())){
+
        if(check != undefined){
-
if(!confirm("The title doesn't seem to follow the naming conventions.\nAre you sure you want to create this page?")){
+
          if(!check(base, $(titleID).val())){
-
return;
+
            if(!confirm("The title doesn't seem to follow the naming conventions.\nAre you sure you want to create this page?")){
-
}
+
              return;
-
}
+
            }
-
}
+
          }
-
window.location.href = "/wiki/index.php?title="+base+"/"+$(titleID).val()+amp+"action=edit"+amp+"preload="+preload;
+
        }
-
});
+
        window.location.href = "/wiki/index.php?title="+base+"/"+$(titleID).val()+amp+"action=edit"+amp+"preload="+preload;
-
},
+
      });
-
checkNamingConventions: function(base, title){
+
    },
-
return EPFL.namingRegex.test(title);
+
    checkNamingConventions: function(base, title){
-
},
+
      return EPFL.namingRegex.test(title);
-
setup: function(){
+
    },
-
EPFL.setupProtocols();
+
    getPage: function(){
-
EPFL.setupCalendar();
+
      var title = $(".firstHeading").text();
-
EPFL.setupPlanning();
+
      var prefix = "Team:EPF-Lausanne/";
-
EPFL.setupTitle();
+
      title = title.substr(prefix.length);
-
EPFL.setupTOC();
+
      titleParts = title.split("/");
-
$('p')
+
     
-
.filter(function(){
+
      if(titleParts.length > 0 && titleParts[0] == "Template"){
-
return $.trim($(this).text()) === '' && $.trim($(this).html()).length < 10;
+
        titleParts.shift();
-
})
+
      }
-
.remove();
+
      return titleParts;
-
},
+
    },
-
setupTOC: function(){
+
    setup: function(){
-
var toc = $("#toc");
+
      EPFL.setupProtocols();
-
toc.remove();
+
      EPFL.setupCalendar();
-
$(".paper").prepend(toc);
+
      EPFL.setupPlanning();
-
},
+
      EPFL.setupTitle();
-
setupPlanning: function(){
+
      EPFL.setupTOC();
-
if(location.href.match(/Team:EPF-Lausanne\/Planning/ig)){
+
      EPFL.setupNotebookNavButtons();
-
$(".toctext, .mw-headline").each(function(){
+
      $('p')
-
var text = $(this).text().trim();
+
        .filter(function(){
-
+
          return $.trim($(this).text()) === '' && $.trim($(this).html()).length < 10;
-
if(text.substr(0, 1) == "\u2713"){
+
        })
-
$(this).addClass("planning-finished");
+
        .remove();
-
}else{
+
    },
-
var parts = text.split(" - ");
+
    setupTOC: function(){
-
if(parts.length == 1){
+
      var toc = $("#toc");
-
$(this).addClass("planning-todo");
+
      toc.remove();
-
}else{
+
      $(".paper").prepend(toc);
-
$(this).addClass("planning-taken");
+
    },
-
}
+
    setupNotebookNavButtons: function(){
-
}
+
      var months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
-
});
+
      //Note: Valid for 2012, if you're reusing this script, update this:
-
}
+
      var days = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
-
},
+
     
-
setupProtocols: function(){
+
      var exists = function(day, month, year){
-
var hide = false;
+
        if(year != 2012) return false;
-
$(".protocol-title").each(function(){
+
        if(month <= 6){
-
if($.trim($(this).parent().parent().attr("class")) != "protocol-remove-style"){
+
          if(month == 3 && day == 19) return true;
-
hide = true;
+
          if(month == 4 && day == 4) return true;
-
var link = $("<a>")
+
          if(month == 5 && (day >= 30 || day == 25)) return true;
-
.attr("href", "#")
+
          if(month == 6 && (day <= 1 || day == 13 || day == 28 || day == 29)) return true;
-
.click(
+
          return false;
-
function(){
+
        }
-
$(this).parent().parent().children().last().toggle()
+
        if(month >= 10) return false;
-
return false;
+
        if(month == 7){
-
});
+
          if(day >= 4 && day <= 7) return true;
-
+
          if(day >= 10 && day <= 13) return true;
-
var children = $(this).children().children();
+
          if(day >= 16) return true;
-
$(this).empty();
+
          return false;
-
link.append(children);
+
        }
-
$(this).append(link);
+
        if(month == 8) return true;
-
}else{
+
        if(month == 9 && day <= 26) return true;
-
var txt = $(this).text();
+
        return false;
-
$(this).empty();
+
      };
-
$(this).text(txt);
+
     
-
}
+
      var getCorrectDate = function(day, month, year){
-
});
+
          if(day < 1){
-
if(hide)
+
            month--;
-
$(".protocol-inner-box").hide();
+
            day = days[month];
-
},
+
          }
-
setupCalendar: function(){
+
          if(day > days[month]){
-
var toAdd = amp+"preload=Team:EPF-Lausanne/Notebook/Template/NewEntry";
+
            month++;
-
$(".month tr td a")
+
            day = 1;
-
.filter(
+
          }
-
function(){  
+
          if(month < 1){
-
return $(this).attr("href").length > 80;
+
            year--;
-
})
+
            month = 12;
-
.each(
+
          }
-
function(){
+
          if(month > 12){
-
$(this).attr("href", $(this).attr("href")+toAdd);
+
            year++;
-
}
+
            month = 1;
-
);
+
          }
-
},
+
         
-
setupTitle: function(){
+
          return [day, month, year];
-
var title = "";
+
      }
-
if(window.titleOverride !== undefined && window.titleOverride !== "" && window.titleOverride !== " " && window.titleOverride !== "{{{1}}}"){
+
     
-
title = window.titleOverride;
+
      var buildString = function(d){
-
}else{
+
        if(exists(d[0], d[1], d[2])){
-
var title = $($(".firstHeading")[0]).text();
+
          return d[0]+" "+months[d[1]]+" "+d[2];
-
var prefix = "Team:EPF-Lausanne/";
+
        }else{
-
title = title.substr(prefix.length);
+
          return "";
-
titleParts = title.split("/");
+
        }
-
+
      }
-
switch(titleParts[0]){
+
     
-
case "Template":
+
      if(EPFL.getPage().length == 2 && EPFL.getPage()[0] == "Notebook"){
-
titleParts.shift();
+
        var date = EPFL.getPage()[1];
-
break;
+
       
-
}
+
        var parts = EPFL.dateRegex.exec(date);
-
+
        if(parts != null){
-
var result = titleParts.join(" ");
+
          var day = parseInt(parts[1], 10);
 +
          var month = 6;
 +
          for(var i = 1; i < 12; i++){
 +
            if(months[i] == parts[2]){
 +
              month = i;
 +
            }
 +
          }
 +
          var year = parseInt(parts[3], 10);
 +
         
 +
          var prevDate = getCorrectDate(day-1, month, year);
 +
          while(prevDate[2] == 2012 && !exists(prevDate[0], prevDate[1], prevDate[2])){
 +
            prevDate = getCorrectDate(prevDate[0]-1, prevDate[1], prevDate[2]);
 +
          }
 +
         
 +
          var nextDate = getCorrectDate(day+1, month, year);
 +
          while(nextDate[2] == 2012 && !exists(nextDate[0], nextDate[1], nextDate[2])){
 +
            nextDate = getCorrectDate(nextDate[0]+1, nextDate[1], nextDate[2]);
 +
          }
 +
          var prev = buildString(prevDate);
 +
          var next = buildString(nextDate);
 +
         
 +
          $(".page-content").prepend(
 +
            $("<div>")
 +
              .css({"clear": "both"}));
 +
         
 +
          if(prev.length > 0){
 +
            $(".page-content").prepend(
 +
              $("<a>")
 +
                .css({"float": "left"})
 +
                .attr("href", "/Team:EPF-Lausanne/Notebook/"+prev)
 +
                .html("\u2190 "+prev));
 +
          }
 +
         
 +
          if(next.length > 0){
 +
            $(".page-content").prepend(
 +
              $("<a>")
 +
                .css({"float": "right"})
 +
                .attr("href", "/Team:EPF-Lausanne/Notebook/"+next)
 +
                .html(next+" \u2192"));
 +
          }
 +
        }
 +
      }
 +
    },
 +
    setupPlanning: function(){
 +
      if(EPFL.getPage()[0] == "Planning"){
 +
        $(".toctext, .mw-headline").each(function(){
 +
          var text = $(this).text().trim();
 +
         
 +
          if(text.substr(0, 1) == "\u2713"){
 +
            $(this).addClass("planning-finished");
 +
          }else{
 +
            var parts = text.split(" - ");
 +
            if(parts.length == 1){
 +
              $(this).addClass("planning-todo");
 +
            }else{
 +
              $(this).addClass("planning-taken");
 +
            }
 +
          }
 +
        });
 +
      }
 +
    },
 +
    setupProtocols: function(){
 +
      var hide = false;
 +
      $(".protocol-title").each(function(){
 +
        if($.trim($(this).parent().parent().attr("class")) != "protocol-remove-style"){
 +
          hide = true;
 +
          var link = $("<a>")
 +
            .attr("href", "#")
 +
            .click(
 +
              function(){
 +
                $(this).parent().parent().children().last().toggle()
 +
                return false;
 +
            });
 +
         
 +
          var children = $(this).children().children();
 +
          $(this).empty();
 +
          link.append(children);
 +
          $(this).append(link);
 +
        }else{
 +
          var txt = $(this).text();
 +
          $(this).empty();
 +
          $(this).text(txt);
 +
        }
 +
      });
 +
      if(hide)
 +
        $(".protocol-inner-box").hide();
 +
    },
 +
    setupCalendar: function(){
 +
      if(EPFL.getPage().length == 1 && EPFL.getPage()[0] == "Notebook"){
 +
        var toAdd = amp+"preload=Team:EPF-Lausanne/Notebook/Template/NewEntry";
 +
          $(".month tr td a")
 +
            .filter(
 +
              function(){  
 +
                return $(this).attr("href").length > 80;
 +
              })
 +
            .each(
 +
              function(){
 +
                $(this).attr("href", $(this).attr("href")+toAdd);
 +
              }
 +
            );
 +
      }
 +
    },
 +
    setupTitle: function(){
 +
      var title = "";
 +
      if(window.titleOverride !== undefined && window.titleOverride !== "" && window.titleOverride !== " " && window.titleOverride !== "{{{1}}}"){
 +
        title = window.titleOverride;
 +
      }else{
 +
        var title = $($(".firstHeading")[0]).text();
 +
        var prefix = "Team:EPF-Lausanne/";
 +
        title = title.substr(prefix.length);
 +
        titleParts = title.split("/");
 +
       
 +
        switch(titleParts[0]){
 +
          case "Template":
 +
            titleParts.shift();
 +
            break;
 +
        }
 +
       
 +
        var result = titleParts.join(" ");
          
          
         if(titleParts.length > 1){
         if(titleParts.length > 1){
           result = titleParts.shift()+": "+titleParts.join(" ");
           result = titleParts.shift()+": "+titleParts.join(" ");
         }
         }
-
+
       
-
if(result == ""){
+
        if(result == ""){
-
result = "Home";
+
          result = "Home";
-
}
+
        }
-
title = result;
+
        title = result;
-
}
+
      }
-
+
     
-
$("#pageTitle").text(title);
+
      $("#pageTitle").text(title);
-
}
+
    }
-
};
+
  };
}());
}());
if(!window.console){
if(!window.console){
-
//Dummy console...
+
  //Dummy console...
-
window.console = {
+
  window.console = {
-
log: function(){ }
+
    log: function(){ }
-
};
+
  };
}
}
window.Doodles = (function(){
window.Doodles = (function(){
-
var SPACE_MIN = 80;
+
  var SPACE_MIN = 80;
-
var SPACE_MAX = 400;
+
  var SPACE_MAX = 400;
-
var WIDTH = 120;
+
  var WIDTH = 120;
-
var MAX_DOODLES_PER_BAR = 100;
+
  var MAX_DOODLES_PER_BAR = 100;
-
var MAX_RETRIES = 100;
+
  var MAX_RETRIES = 100;
-
+
 
-
var all = [
+
  var all = [
-
//{ height: 114, src: "https://static.igem.org/mediawiki/2012/6/61/Team-EPF-Lausanne_Template_Doodle_Placeholder.png" },
+
    //{ height: 114, src: "https://static.igem.org/mediawiki/2012/6/61/Team-EPF-Lausanne_Template_Doodle_Placeholder.png" },
-
{ height: 27, src: "https://static.igem.org/mediawiki/2012/9/9b/Team-EPF-Lausanne_Doodle_Switch.png" },
+
    { height: 27, src: "https://static.igem.org/mediawiki/2012/9/9b/Team-EPF-Lausanne_Doodle_Switch.png" },
-
{ height: 131, src: "https://static.igem.org/mediawiki/2012/3/3b/Team-EPF-Lausanne_Doodle_Graph.png" },
+
    { height: 131, src: "https://static.igem.org/mediawiki/2012/3/3b/Team-EPF-Lausanne_Doodle_Graph.png" },
-
{ height: 87, src: "https://static.igem.org/mediawiki/2012/f/f6/Team-EPF-Lausanne_Doodle_Circuit.png" },
+
    { height: 87, src: "https://static.igem.org/mediawiki/2012/f/f6/Team-EPF-Lausanne_Doodle_Circuit.png" },
-
{ height: 138, src: "https://static.igem.org/mediawiki/2012/f/f4/Team-EPF-Lausanne_Doodle_Centrifuge.png" },
+
    { height: 138, src: "https://static.igem.org/mediawiki/2012/f/f4/Team-EPF-Lausanne_Doodle_Centrifuge.png" },
-
{ height: 76, src: "https://static.igem.org/mediawiki/2012/4/49/Team-EPF-Lausanne_Doodle_Agarose.png" },
+
    { height: 76, src: "https://static.igem.org/mediawiki/2012/4/49/Team-EPF-Lausanne_Doodle_Agarose.png" },
-
+
 
-
+
 
-
{ height: 156, src: "https://static.igem.org/mediawiki/2012/7/7f/LED.png" },
+
    { height: 156, src: "https://static.igem.org/mediawiki/2012/7/7f/LED.png" },
-
{ height: 175, src: "https://static.igem.org/mediawiki/2012/a/a2/Pipette.png" },
+
    { height: 175, src: "https://static.igem.org/mediawiki/2012/a/a2/Pipette.png" },
-
{ height: 141, src: "https://static.igem.org/mediawiki/2012/d/d2/Team_epf_Resistance.png" },
+
    { height: 141, src: "https://static.igem.org/mediawiki/2012/d/d2/Team_epf_Resistance.png" },
-
{ height: 71, src: "https://static.igem.org/mediawiki/2012/6/6f/Team_epf_Restrictionenzyme.png" },
+
    { height: 71, src: "https://static.igem.org/mediawiki/2012/6/6f/Team_epf_Restrictionenzyme.png" },
-
{ height: 128, src: "https://static.igem.org/mediawiki/2012/8/86/Team_epf_Wellplate.png" },
+
    { height: 128, src: "https://static.igem.org/mediawiki/2012/8/86/Team_epf_Wellplate.png" },
-
{ height: 98, src: "https://static.igem.org/mediawiki/2012/8/8a/Team_epf_Plasmid.png" }
+
    { height: 98, src: "https://static.igem.org/mediawiki/2012/8/8a/Team_epf_Plasmid.png" }
-
+
 
-
];
+
  ];
-
+
 
-
var isHomePage = function(){
+
  var isHomePage = function(){
-
var title = $($(".firstHeading")[0]).text();
+
    var title = $($(".firstHeading")[0]).text();
-
var prefix = "Team:EPF-Lausanne/";
+
    var prefix = "Team:EPF-Lausanne/";
-
title = title.substr(prefix.length);
+
    title = title.substr(prefix.length);
-
titleParts = title.split("/");
+
    titleParts = title.split("/");
-
+
   
-
switch(titleParts[0]){
+
    switch(titleParts[0]){
-
case "Template":
+
      case "Template":
-
titleParts.shift();
+
        titleParts.shift();
-
break;
+
        break;
-
}
+
    }
-
+
   
-
var result = titleParts.join(" ");
+
    var result = titleParts.join(" ");
-
+
   
-
if(result == ""){
+
    if(result == ""){
-
return true;
+
      return true;
-
}
+
    }
-
return false;
+
    return false;
-
}
+
  }
-
+
 
-
var contentHeight = 0;
+
  var contentHeight = 0;
-
var doodleBars = [];
+
  var doodleBars = [];
-
var barUsage = [{max: 0, images: []}, {max: 0, images: []}];
+
  var barUsage = [{max: 0, images: []}, {max: 0, images: []}];
-
var previous = undefined;
+
  var previous = undefined;
-
var firstLoad = true;
+
  var firstLoad = true;
-
+
 
-
return {
+
  return {
-
onLoad: function(){
+
    onLoad: function(){
-
if(firstLoad){
+
      if(firstLoad){
-
var that = this;
+
        var that = this;
-
setTimeout(function(){ that.onLoad(); }, 1000);
+
        setTimeout(function(){ that.onLoad(); }, 1000);
-
firstLoad = false;
+
        firstLoad = false;
-
}
+
      }
-
+
     
-
//console.log("Doodle onload");
+
      //console.log("Doodle onload");
-
contentHeight = $(".page-content").height() - 50;
+
      contentHeight = $(".page-content").height() - 50;
-
doodleBars = $(".doodle-bar");
+
      doodleBars = $(".doodle-bar");
-
//doodleBars.height(contentHeight);
+
      //doodleBars.height(contentHeight);
-
+
     
-
this.addDoodles();
+
      this.addDoodles();
-
},
+
    },
-
addDoodles: function(){
+
    addDoodles: function(){
-
//console.log("Adding doodles to left");
+
      //console.log("Adding doodles to left");
-
+
     
-
if(isHomePage()){
+
      if(isHomePage()){
-
this.addDoodle(1, 400);
+
        this.addDoodle(1, 400);
-
}
+
      }
-
+
     
-
//Add a doodle at one of the sides (random) at y = 0
+
      //Add a doodle at one of the sides (random) at y = 0
-
this.addDoodle(Math.round(Math.random()), 0);
+
      this.addDoodle(Math.round(Math.random()), 0);
-
+
     
-
for(var i = 0; i < MAX_DOODLES_PER_BAR; i++){
+
      for(var i = 0; i < MAX_DOODLES_PER_BAR; i++){
-
if(!this.addDoodle(0)) break;
+
        if(!this.addDoodle(0)) break;
-
}
+
      }
-
+
     
-
//console.log("Adding doodles to right");
+
      //console.log("Adding doodles to right");
-
for(var i = 0; i < MAX_DOODLES_PER_BAR; i++){
+
      for(var i = 0; i < MAX_DOODLES_PER_BAR; i++){
-
if(!this.addDoodle(1)) break;
+
        if(!this.addDoodle(1)) break;
-
}
+
      }
-
},
+
    },
-
addDoodle: function(barNumber, nextDistance){
+
    addDoodle: function(barNumber, nextDistance){
-
//console.log("Trying to add doodle to", barNumber);
+
      //console.log("Trying to add doodle to", barNumber);
-
var bar = $(doodleBars[barNumber]);
+
      var bar = $(doodleBars[barNumber]);
-
var usage = barUsage[barNumber];
+
      var usage = barUsage[barNumber];
-
+
     
-
//console.log("Current usage vs contentHeight: ", usage.max, contentHeight);
+
      //console.log("Current usage vs contentHeight: ", usage.max, contentHeight);
-
if(usage.max > contentHeight) return false;
+
      if(usage.max > contentHeight) return false;
-
+
     
-
if(nextDistance === undefined)
+
      if(nextDistance === undefined)
-
nextDistance = SPACE_MIN + Math.floor(Math.random()*(SPACE_MAX-SPACE_MIN+1));
+
        nextDistance = SPACE_MIN + Math.floor(Math.random()*(SPACE_MAX-SPACE_MIN+1));
-
+
     
-
var nextImage = all[Math.floor(Math.random()*all.length)];
+
      var nextImage = all[Math.floor(Math.random()*all.length)];
-
for(var i = 0; i < MAX_RETRIES; i++){
+
      for(var i = 0; i < MAX_RETRIES; i++){
-
if(previous == nextImage){
+
        if(previous == nextImage){
-
nextImage = all[Math.floor(Math.random()*all.length)];
+
          nextImage = all[Math.floor(Math.random()*all.length)];
-
}else{
+
        }else{
-
break;
+
          break;
-
}
+
        }
-
}
+
      }
-
+
     
-
if(previous == nextImage) return false;
+
      if(previous == nextImage) return false;
-
+
     
-
previous = nextImage;
+
      previous = nextImage;
-
+
     
-
if(usage.max + nextDistance + nextImage.height > contentHeight) return false;
+
      if(usage.max + nextDistance + nextImage.height > contentHeight) return false;
-
+
     
-
var container = $("<div>")
+
      var container = $("<div>")
-
.css({
+
          .css({
-
"background": "url('"+nextImage.src+"')",
+
            "background": "url('"+nextImage.src+"')",
-
"width": WIDTH+"px",
+
            "width": WIDTH+"px",
-
"height": nextImage.height+"px",
+
            "height": nextImage.height+"px",
-
"margin-top": nextDistance+"px"
+
            "margin-top": nextDistance+"px"
-
});
+
          });
-
bar.append(container);
+
      bar.append(container);
-
/*
+
      /*
-
var img =  
+
      var img =  
-
$("<img>")
+
        $("<img>")
-
.load(function(){ container.append(img); })
+
          .load(function(){ container.append(img); })
-
.attr("width", WIDTH)
+
          .attr("width", WIDTH)
-
.attr("height", nextImage.height)
+
          .attr("height", nextImage.height)
-
.attr("src", nextImage.src);*/
+
          .attr("src", nextImage.src);*/
-
+
     
-
usage.max += nextDistance + nextImage.height;
+
      usage.max += nextDistance + nextImage.height;
-
+
     
-
return true;
+
      return true;
-
}
+
    }
-
};
+
  };
})();
})();
window.Menu = (function(){
window.Menu = (function(){
-
var items = ["introduction", "project", "notebook", "human", "acknowledgments"];
+
  var items = ["introduction", "project", "notebook", "human", "acknowledgments"];
-
var positions = {"introduction": -300, "project": -170, "notebook": -60, "human": 75, "acknowledgments": 240};
+
  var positions = {"introduction": -300, "project": -170, "notebook": -60, "human": 75, "acknowledgments": 240};
-
+
 
-
var subMenus = {
+
  var subMenus = {
-
introduction: [
+
    introduction: [
-
["Home", "/Team:EPF-Lausanne"],
+
      ["Home", "/Team:EPF-Lausanne"],
-
["Team", "/Team:EPF-Lausanne/Team"],
+
      ["Team", "/Team:EPF-Lausanne/Team"],
-
["Photos", "/Team:EPF-Lausanne/Photos"]
+
      ["Photos", "/Team:EPF-Lausanne/Photos"]
-
],
+
    ],
-
project: [
+
    project: [
-
["Project Contents", "/Team:EPF-Lausanne/Project"],
+
      ["Project Contents", "/Team:EPF-Lausanne/Project"],
-
["Results", "/Team:EPF-Lausanne/Results"],
+
      ["Modeling", "/Team:EPF-Lausanne/Modeling"],
-
["Parts Submitted to the Registry", "https://2012.igem.org/Team:EPF-Lausanne/Parts"],
+
      ["Results", "/Team:EPF-Lausanne/Results"],
-
["Modeling", "/Team:EPF-Lausanne/Modeling"]
+
      ["Parts Submitted to the Registry", "https://2012.igem.org/Team:EPF-Lausanne/Parts"]
-
],
+
    ],
-
notebook: [
+
    notebook: [
-
["Notebook", "/Team:EPF-Lausanne/Notebook"],
+
      ["Notebook", "/Team:EPF-Lausanne/Notebook"],
-
["Protocols", "/Team:EPF-Lausanne/Protocol"]
+
      ["Protocols", "/Team:EPF-Lausanne/Protocol"]
-
],
+
    ],
-
human: [
+
    human: [
-
["Talks", "/Team:EPF-Lausanne/Human/Talks"],
+
      ["Human Practices", "/Team:EPF-Lausanne/HumanPractices"],
-
["Survey", "/Team:EPF-Lausanne/Human/Survey"],
+
      ["Talks", "/Team:EPF-Lausanne/Human/Talks"],
-
["Primer Design", "/Team:EPF-Lausanne/PrimerDesignHelper"],
+
      ["Survey", "/Team:EPF-Lausanne/Human/Survey"],
-
["Cell Creator", "/Team:EPF-Lausanne/CellCreator"],
+
      ["Primer Design", "/Team:EPF-Lausanne/PrimerDesignHelper"],
-
["Safety", "/Team:EPF-Lausanne/Safety"],
+
      ["Cell Creator", "/Team:EPF-Lausanne/CellCreator"],
-
],
+
      ["Safety", "/Team:EPF-Lausanne/Safety"],
-
acknowledgments: [
+
    ],
-
["Attributions", "/Team:EPF-Lausanne/Acknowledgments"],
+
    acknowledgments: [
-
["Sponsors", "/Team:EPF-Lausanne/Sponsors"]
+
      ["Attributions", "/Team:EPF-Lausanne/Acknowledgments"],
-
]
+
      ["References", "/Team:EPF-Lausanne/References"],
-
};
+
      ["Sponsors", "/Team:EPF-Lausanne/Sponsors"]
-
+
    ]
-
// Default to notebook
+
  };
-
var current = "notebook";
+
 
-
var leaveTimer = undefined;
+
  // Default to notebook
-
var leaveMenu = function(){
+
  var current = "notebook";
-
current = window.menu != "" ? window.menu.toLowerCase() : "notebook";
+
  var leaveTimer = undefined;
-
window.Menu.update();
+
  var leaveMenu = function(){
-
};
+
    current = window.menu != "" ? window.menu.toLowerCase() : "notebook";
-
var attachEvents = function(name){
+
    window.Menu.update();
-
$(".menu-"+name).mouseover(function(){
+
  };
-
if(leaveTimer !== undefined){
+
  var attachEvents = function(name){
-
clearTimeout(leaveTimer);
+
    $(".menu-"+name).mouseover(function(){
-
leaveTimer = undefined;
+
      if(leaveTimer !== undefined){
-
}
+
        clearTimeout(leaveTimer);
-
current = name;
+
        leaveTimer = undefined;
-
window.Menu.update();
+
      }
-
});
+
      current = name;
-
$(".menu-"+name).mouseout(function(){
+
      window.Menu.update();
-
if(leaveTimer === undefined){
+
    });
-
leaveTimer = setTimeout(leaveMenu, 1000);
+
    $(".menu-"+name).mouseout(function(){
-
}
+
      if(leaveTimer === undefined){
-
});
+
        leaveTimer = setTimeout(leaveMenu, 1000);
-
};
+
      }
-
return {
+
    });
-
onLoad: function(){
+
  };
-
// Default to notebook
+
  return {
-
if(window.menu === undefined || window.menu === "" || window.menu === " " || window.menu === "{{{1}}}"){
+
    onLoad: function(){
-
window.menu = "notebook";
+
      // Default to notebook
-
}
+
      if(window.menu === undefined || window.menu === "" || window.menu === " " || window.menu === "{{{1}}}"){
-
current = window.menu != "" ? window.menu.toLowerCase() : "notebook";
+
        window.menu = "notebook";
-
+
      }
-
for(var i = 0; i < items.length; i++){
+
      current = window.menu != "" ? window.menu.toLowerCase() : "notebook";
-
attachEvents(items[i]);
+
     
-
}
+
      for(var i = 0; i < items.length; i++){
-
+
        attachEvents(items[i]);
-
$(".sub-menu").mouseover(function(){
+
      }
-
if(leaveTimer !== undefined){
+
     
-
clearTimeout(leaveTimer);
+
      $(".sub-menu").mouseover(function(){
-
leaveTimer = undefined;
+
        if(leaveTimer !== undefined){
-
}
+
          clearTimeout(leaveTimer);
-
});
+
          leaveTimer = undefined;
-
+
        }
-
$(".sub-menu").mouseout(function(){
+
      });
-
if(leaveTimer === undefined){
+
     
-
leaveTimer = setTimeout(leaveMenu, 1000);
+
      $(".sub-menu").mouseout(function(){
-
}
+
        if(leaveTimer === undefined){
-
});
+
          leaveTimer = setTimeout(leaveMenu, 1000);
-
+
        }
-
$(".paper-arrow").show();
+
      });
-
window.Menu.update();
+
     
-
},
+
      $(".paper-arrow").show();
-
update: function(){
+
      window.Menu.update();
-
if(current === undefined || current === "" || current === " "|| current === "{{{1}}}" || !positions[current]){
+
    },
-
$(".paper-arrow").hide();
+
    update: function(){
-
}else{
+
      if(current === undefined || current === "" || current === " "|| current === "{{{1}}}" || !positions[current]){
-
$(".paper-arrow").show();
+
        $(".paper-arrow").hide();
-
var newPos = positions[current]+"px";
+
      }else{
-
$(".paper-arrow").css({left: newPos});
+
        $(".paper-arrow").show();
-
}
+
        var newPos = positions[current]+"px";
-
this.updateSubMenu();
+
        $(".paper-arrow").css({left: newPos});
-
},
+
      }
-
updateSubMenu: function(){
+
      this.updateSubMenu();
-
var subMenu = subMenus[current];
+
    },
-
+
    updateSubMenu: function(){
-
var sub = $(".sub-menu .simple-navi ul");
+
      var subMenu = subMenus[current];
-
sub.empty();
+
     
-
+
      var sub = $(".sub-menu .simple-navi ul");
-
if(subMenu !== undefined && subMenu.length > 0){
+
      sub.empty();
-
sub.append($("<li>").attr("class", "left").append($("<span>")));
+
     
-
+
      if(subMenu !== undefined && subMenu.length > 0){
-
for(var i = 0; i < subMenu.length; i++){
+
        sub.append($("<li>").attr("class", "left").append($("<span>")));
-
sub.append($("<li>")
+
       
-
.append($("<a>")
+
        for(var i = 0; i < subMenu.length; i++){
-
.attr("href", subMenu[i][1])
+
          sub.append($("<li>")
-
.append($("<span>").text(subMenu[i][0]))));
+
            .append($("<a>")
-
}
+
              .attr("href", subMenu[i][1])
-
+
              .append($("<span>").text(subMenu[i][0]))));
-
sub.append($("<li>").attr("class", "right").append($("<span>")));
+
        }
-
+
       
-
var center = positions[current];
+
        sub.append($("<li>").attr("class", "right").append($("<span>")));
-
width = sub.width();
+
       
-
+
        var center = positions[current];
-
var x = 330 + center - width/2;
+
        width = sub.width();
-
var dx = 0;
+
       
-
+
        var x = 330 + center - width/2;
-
if(width > 660){
+
        var dx = 0;
-
dx = -center;
+
       
-
}else if(x < -40){
+
        if(width > 660){
-
dx = -x - 40;
+
          dx = -center;
-
}else if(x + width > 660){
+
        }else if(x < -40){
-
dx = 660 - width - x;
+
          dx = -x - 40;
-
}
+
        }else if(x + width > 660){
-
+
          dx = 660 - width - x;
-
sub.css({"position": "relative", "left": (center+dx)+"px"});
+
        }
-
}
+
       
-
}
+
        sub.css({"position": "relative", "left": (center+dx)+"px"});
-
};
+
      }
 +
    }
 +
  };
})();
})();
$(function(){
$(function(){
-
Menu.onLoad();
+
  Menu.onLoad();
-
Doodles.onLoad();
+
  Doodles.onLoad();
});
});
runOnloadHook = function(){
runOnloadHook = function(){
-
EPFL.setup();
+
  EPFL.setup();
};
};

Latest revision as of 01:19, 27 September 2012

//Generate private namespace window.EPFL = (function(){

 //Little hack to stop MediaWiki from replacing ampersands...
 var amp = unescape("%26");
 return {
   namingRegex: /^(\/|([A-Z][a-z]*))*[0-9]*$/,
   dateRegex: /^([0-9]+) ([A-Z][a-z]+) ([0-9]+)$/,
   registerNewPageButton: function(titleID, buttonID, base, preload, check){
     $(buttonID).click(function(){
       if(check != undefined){
         if(!check(base, $(titleID).val())){
           if(!confirm("The title doesn't seem to follow the naming conventions.\nAre you sure you want to create this page?")){
             return;
           }
         }
       }
       window.location.href = "/wiki/index.php?title="+base+"/"+$(titleID).val()+amp+"action=edit"+amp+"preload="+preload;
     });
   },
   checkNamingConventions: function(base, title){
     return EPFL.namingRegex.test(title);
   },
   getPage: function(){
     var title = $(".firstHeading").text();
     var prefix = "Team:EPF-Lausanne/";
     title = title.substr(prefix.length);
     titleParts = title.split("/");
     
     if(titleParts.length > 0 && titleParts[0] == "Template"){
       titleParts.shift();
     }
     return titleParts;
   },
   setup: function(){
     EPFL.setupProtocols();
     EPFL.setupCalendar();
     EPFL.setupPlanning();
     EPFL.setupTitle();
     EPFL.setupTOC();
     EPFL.setupNotebookNavButtons();
     $('p')
       .filter(function(){
         return $.trim($(this).text()) ===  && $.trim($(this).html()).length < 10;
       })
       .remove();
   },
   setupTOC: function(){
     var toc = $("#toc");
     toc.remove();
     $(".paper").prepend(toc);
   },
   setupNotebookNavButtons: function(){
     var months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
     //Note: Valid for 2012, if you're reusing this script, update this:
     var days = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
     
     var exists = function(day, month, year){
       if(year != 2012) return false;
       if(month <= 6){
         if(month == 3 && day == 19) return true;
         if(month == 4 && day == 4) return true;
         if(month == 5 && (day >= 30 || day == 25)) return true;
         if(month == 6 && (day <= 1 || day == 13 || day == 28 || day == 29)) return true;
         return false;
       }
       if(month >= 10) return false;
       if(month == 7){
         if(day >= 4 && day <= 7) return true;
         if(day >= 10 && day <= 13) return true;
         if(day >= 16) return true;
         return false;
       }
       if(month == 8) return true;
       if(month == 9 && day <= 26) return true;
       return false;
     };
     
     var getCorrectDate = function(day, month, year){
         if(day < 1){
           month--;
           day = days[month];
         }
         if(day > days[month]){
           month++;
           day = 1;
         }
         if(month < 1){
           year--;
           month = 12;
         }
         if(month > 12){
           year++;
           month = 1;
         }
         
         return [day, month, year];
     }
     
     var buildString = function(d){
       if(exists(d[0], d[1], d[2])){
         return d[0]+" "+months[d[1]]+" "+d[2];
       }else{
         return "";
       }
     }
     
     if(EPFL.getPage().length == 2 && EPFL.getPage()[0] == "Notebook"){
       var date = EPFL.getPage()[1];
       
       var parts = EPFL.dateRegex.exec(date);
       if(parts != null){
         var day = parseInt(parts[1], 10);
         var month = 6;
         for(var i = 1; i < 12; i++){
           if(months[i] == parts[2]){
             month = i;
           }
         }
         var year = parseInt(parts[3], 10);
         
         var prevDate = getCorrectDate(day-1, month, year);
         while(prevDate[2] == 2012 && !exists(prevDate[0], prevDate[1], prevDate[2])){
           prevDate = getCorrectDate(prevDate[0]-1, prevDate[1], prevDate[2]);
         }
         
         var nextDate = getCorrectDate(day+1, month, year);
         while(nextDate[2] == 2012 && !exists(nextDate[0], nextDate[1], nextDate[2])){
           nextDate = getCorrectDate(nextDate[0]+1, nextDate[1], nextDate[2]);
         }
         var prev = buildString(prevDate);
         var next = buildString(nextDate);
         
         $(".page-content").prepend(
$("
")
             .css({"clear": "both"}));
         
         if(prev.length > 0){
           $(".page-content").prepend(
             $("<a>")
               .css({"float": "left"})
               .attr("href", "/Team:EPF-Lausanne/Notebook/"+prev)
               .html("\u2190 "+prev));
         }
         
         if(next.length > 0){
           $(".page-content").prepend(
             $("<a>")
               .css({"float": "right"})
               .attr("href", "/Team:EPF-Lausanne/Notebook/"+next)
               .html(next+" \u2192"));
         }
       }
     }
   },
   setupPlanning: function(){
     if(EPFL.getPage()[0] == "Planning"){
       $(".toctext, .mw-headline").each(function(){
         var text = $(this).text().trim();
         
         if(text.substr(0, 1) == "\u2713"){
           $(this).addClass("planning-finished");
         }else{
           var parts = text.split(" - ");
           if(parts.length == 1){
             $(this).addClass("planning-todo");
           }else{
             $(this).addClass("planning-taken");
           }
         }
       });
     }
   },
   setupProtocols: function(){
     var hide = false;
     $(".protocol-title").each(function(){
       if($.trim($(this).parent().parent().attr("class")) != "protocol-remove-style"){
         hide = true;
         var link = $("<a>")
           .attr("href", "#")
           .click(
             function(){
               $(this).parent().parent().children().last().toggle()
               return false;
           });
         
         var children = $(this).children().children();
         $(this).empty();
         link.append(children);
         $(this).append(link);
       }else{
         var txt = $(this).text();
         $(this).empty();
         $(this).text(txt);
       }
     });
     if(hide)
       $(".protocol-inner-box").hide();
   },
   setupCalendar: function(){
     if(EPFL.getPage().length == 1 && EPFL.getPage()[0] == "Notebook"){
       var toAdd = amp+"preload=Team:EPF-Lausanne/Notebook/Template/NewEntry";
         $(".month tr td a")
           .filter(
             function(){ 
               return $(this).attr("href").length > 80;
             })
           .each(
             function(){
               $(this).attr("href", $(this).attr("href")+toAdd);
             }
           );
     }
   },
   setupTitle: function(){
     var title = "";
     if(window.titleOverride !== undefined && window.titleOverride !== "" && window.titleOverride !== " " && window.titleOverride !== "{{{1}}}"){
       title = window.titleOverride;
     }else{
       var title = $($(".firstHeading")[0]).text();
       var prefix = "Team:EPF-Lausanne/";
       title = title.substr(prefix.length);
       titleParts = title.split("/");
       
       switch(titleParts[0]){
         case "Template":
           titleParts.shift();
           break;
       }
       
       var result = titleParts.join(" ");
       
       if(titleParts.length > 1){
         result = titleParts.shift()+": "+titleParts.join(" ");
       }
       
       if(result == ""){
         result = "Home";
       }
       title = result;
     }
     
     $("#pageTitle").text(title);
   }
 };

}());

if(!window.console){

 //Dummy console...
 window.console = {
   log: function(){ }
 };

}

window.Doodles = (function(){

 var SPACE_MIN = 80;
 var SPACE_MAX = 400;
 var WIDTH = 120;
 var MAX_DOODLES_PER_BAR = 100;
 var MAX_RETRIES = 100;
 
 var all = [
   //{ height: 114, src: "Team-EPF-Lausanne_Template_Doodle_Placeholder.png" },
   { height: 27, src: "Team-EPF-Lausanne_Doodle_Switch.png" },
   { height: 131, src: "Team-EPF-Lausanne_Doodle_Graph.png" },
   { height: 87, src: "Team-EPF-Lausanne_Doodle_Circuit.png" },
   { height: 138, src: "Team-EPF-Lausanne_Doodle_Centrifuge.png" },
   { height: 76, src: "Team-EPF-Lausanne_Doodle_Agarose.png" },
 
 
   { height: 156, src: "LED.png" },
   { height: 175, src: "Pipette.png" },
   { height: 141, src: "Team_epf_Resistance.png" },
   { height: 71, src: "Team_epf_Restrictionenzyme.png" },
   { height: 128, src: "Team_epf_Wellplate.png" },
   { height: 98, src: "Team_epf_Plasmid.png" }
 
 ];
 
 var isHomePage = function(){
   var title = $($(".firstHeading")[0]).text();
   var prefix = "Team:EPF-Lausanne/";
   title = title.substr(prefix.length);
   titleParts = title.split("/");
   
   switch(titleParts[0]){
     case "Template":
       titleParts.shift();
       break;
   }
   
   var result = titleParts.join(" ");
   
   if(result == ""){
     return true;
   }
   return false;
 }
 
 var contentHeight = 0;
 var doodleBars = [];
 var barUsage = [{max: 0, images: []}, {max: 0, images: []}];
 var previous = undefined;
 var firstLoad = true;
 
 return {
   onLoad: function(){
     if(firstLoad){
       var that = this;
       setTimeout(function(){ that.onLoad(); }, 1000);
       firstLoad = false;
     }
     
     //console.log("Doodle onload");
     contentHeight = $(".page-content").height() - 50;
     doodleBars = $(".doodle-bar");
     //doodleBars.height(contentHeight);
     
     this.addDoodles();
   },
   addDoodles: function(){
     //console.log("Adding doodles to left");
     
     if(isHomePage()){
       this.addDoodle(1, 400);
     }
     
     //Add a doodle at one of the sides (random) at y = 0
     this.addDoodle(Math.round(Math.random()), 0);
     
     for(var i = 0; i < MAX_DOODLES_PER_BAR; i++){
       if(!this.addDoodle(0)) break;
     }
     
     //console.log("Adding doodles to right");
     for(var i = 0; i < MAX_DOODLES_PER_BAR; i++){
       if(!this.addDoodle(1)) break;
     }
   },
   addDoodle: function(barNumber, nextDistance){
     //console.log("Trying to add doodle to", barNumber);
     var bar = $(doodleBars[barNumber]);
     var usage = barUsage[barNumber];
     
     //console.log("Current usage vs contentHeight: ", usage.max, contentHeight);
     if(usage.max > contentHeight) return false;
     
     if(nextDistance === undefined)
       nextDistance = SPACE_MIN + Math.floor(Math.random()*(SPACE_MAX-SPACE_MIN+1));
     
     var nextImage = all[Math.floor(Math.random()*all.length)];
     for(var i = 0; i < MAX_RETRIES; i++){
       if(previous == nextImage){
         nextImage = all[Math.floor(Math.random()*all.length)];
       }else{
         break;
       }
     }
     
     if(previous == nextImage) return false;
     
     previous = nextImage;
     
     if(usage.max + nextDistance + nextImage.height > contentHeight) return false;
     
var container = $("
")
         .css({
           "background": "url('"+nextImage.src+"')",
           "width": WIDTH+"px",
           "height": nextImage.height+"px",
           "margin-top": nextDistance+"px"
         });
     bar.append(container);
     /*
     var img = 
       $("<img>")
         .load(function(){ container.append(img); })
         .attr("width", WIDTH)
         .attr("height", nextImage.height)
         .attr("src", nextImage.src);*/
     
     usage.max += nextDistance + nextImage.height;
     
     return true;
   }
 };

})();

window.Menu = (function(){

 var items = ["introduction", "project", "notebook", "human", "acknowledgments"];
 var positions = {"introduction": -300, "project": -170, "notebook": -60, "human": 75, "acknowledgments": 240};
 
 var subMenus = {
   introduction: [
     ["Home", "/Team:EPF-Lausanne"],
     ["Team", "/Team:EPF-Lausanne/Team"],
     ["Photos", "/Team:EPF-Lausanne/Photos"]
   ],
   project: [
     ["Project Contents", "/Team:EPF-Lausanne/Project"],
     ["Modeling", "/Team:EPF-Lausanne/Modeling"],
     ["Results", "/Team:EPF-Lausanne/Results"],
     ["Parts Submitted to the Registry", "https://2012.igem.org/Team:EPF-Lausanne/Parts"]
   ],
   notebook: [
     ["Notebook", "/Team:EPF-Lausanne/Notebook"],
     ["Protocols", "/Team:EPF-Lausanne/Protocol"]
   ],
   human: [
     ["Human Practices", "/Team:EPF-Lausanne/HumanPractices"],
     ["Talks", "/Team:EPF-Lausanne/Human/Talks"],
     ["Survey", "/Team:EPF-Lausanne/Human/Survey"],
     ["Primer Design", "/Team:EPF-Lausanne/PrimerDesignHelper"],
     ["Cell Creator", "/Team:EPF-Lausanne/CellCreator"],
     ["Safety", "/Team:EPF-Lausanne/Safety"],
   ],
   acknowledgments: [
     ["Attributions", "/Team:EPF-Lausanne/Acknowledgments"],
     ["References", "/Team:EPF-Lausanne/References"],
     ["Sponsors", "/Team:EPF-Lausanne/Sponsors"]
   ]
 };
 
 // Default to notebook
 var current = "notebook";
 var leaveTimer = undefined;
 var leaveMenu = function(){
   current = window.menu != "" ? window.menu.toLowerCase() : "notebook";
   window.Menu.update();
 };
 var attachEvents = function(name){
   $(".menu-"+name).mouseover(function(){
     if(leaveTimer !== undefined){
       clearTimeout(leaveTimer);
       leaveTimer = undefined;
     }
     current = name;
     window.Menu.update();
   });
   $(".menu-"+name).mouseout(function(){
     if(leaveTimer === undefined){
       leaveTimer = setTimeout(leaveMenu, 1000);
     }
   });
 };
 return {
   onLoad: function(){
     // Default to notebook
     if(window.menu === undefined || window.menu === "" || window.menu === " " || window.menu === "{{{1}}}"){
       window.menu = "notebook";
     }
     current = window.menu != "" ? window.menu.toLowerCase() : "notebook";
     
     for(var i = 0; i < items.length; i++){
       attachEvents(items[i]);
     }
     
     $(".sub-menu").mouseover(function(){
       if(leaveTimer !== undefined){
         clearTimeout(leaveTimer);
         leaveTimer = undefined;
       }
     });
     
     $(".sub-menu").mouseout(function(){
       if(leaveTimer === undefined){
         leaveTimer = setTimeout(leaveMenu, 1000);
       }
     });
     
     $(".paper-arrow").show();
     window.Menu.update();
   },
   update: function(){
     if(current === undefined || current === "" || current === " "|| current === "{{{1}}}" || !positions[current]){
       $(".paper-arrow").hide();
     }else{
       $(".paper-arrow").show();
       var newPos = positions[current]+"px";
       $(".paper-arrow").css({left: newPos});
     }
     this.updateSubMenu();
   },
   updateSubMenu: function(){
     var subMenu = subMenus[current];
     
     var sub = $(".sub-menu .simple-navi ul");
     sub.empty();
     
     if(subMenu !== undefined && subMenu.length > 0){
sub.append($("
  • ").attr("class", "left").append($(""))); for(var i = 0; i < subMenu.length; i++){ sub.append($("
  • ") .append($("<a>") .attr("href", subMenu[i][1]) .append($("").text(subMenu[i][0])))); } sub.append($("
  • ").attr("class", "right").append($(""))); var center = positions[current]; width = sub.width(); var x = 330 + center - width/2; var dx = 0; if(width > 660){ dx = -center; }else if(x < -40){ dx = -x - 40; }else if(x + width > 660){ dx = 660 - width - x; } sub.css({"position": "relative", "left": (center+dx)+"px"}); } } }; })(); $(function(){ Menu.onLoad(); Doodles.onLoad(); }); runOnloadHook = function(){ EPFL.setup(); };