jsos

college code for operating system fundamentals in js

git clone https://9o.is/git/jsos.git

interface.js

(1397B)


      1 window.onload=function() {
      2 
      3   // get tab container
      4   var container = document.getElementById("tabContainer");
      5     // set current tab
      6     var navitem = container.querySelector(".tabs ul li");
      7     //store which tab we are on
      8     var ident = navitem.id.split("_")[1];
      9     navitem.parentNode.setAttribute("data-current",ident);
     10     //set current tab with class of activetabheader
     11     navitem.setAttribute("class","tabActiveHeader");
     12 
     13     //hide two tab contents we don't need
     14     var pages = container.querySelectorAll(".tabpage");
     15     for (var i = 1; i < pages.length; i++) {
     16       pages[i].style.display="none";
     17     }
     18 
     19     //this adds click event to tabs
     20     var tabs = container.querySelectorAll(".tabs ul li");
     21     for (var i = 0; i < tabs.length; i++) {
     22       tabs[i].onclick=displayPage;
     23     }
     24 }
     25 
     26 // on click of one of tabs
     27 function displayPage() {
     28   var current = this.parentNode.getAttribute("data-current");
     29   //remove class of activetabheader and hide old contents
     30   document.getElementById("tabHeader_" + current).removeAttribute("class");
     31   document.getElementById("tabpage_" + current).style.display="none";
     32 
     33   var ident = this.id.split("_")[1];
     34   //add class of activetabheader to new active tab and show contents
     35   this.setAttribute("class","tabActiveHeader");
     36   document.getElementById("tabpage_" + ident).style.display="block";
     37   this.parentNode.setAttribute("data-current",ident);
     38 }