User:Bawolff/superPortal.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

//Start super portal
function new_option(id, class, content, select) {
//select is <select> element or <optgroup> to attach to
 var new_opt = document.createElement("option");
 new_opt.setAttribute('id', id);
 new_opt.setAttribute('name', id);
 new_opt.setAttribute('class', class);
 var new_text = document.createTextNode(content);
 //starting adding to tree 
 select.appendChild(new_opt);
 new_opt = document.getElementById(id);
 new_opt.appendChild(new_text);
}


function new_element (type, id, class) {
 var new_element = document.createElement(type);
 new_element.setAttribute('id', id);
 new_element.setAttribute('class', class);
 return new_element;
}

function LOCAL_initiate_superportal()
{
   // iterate over all < div >-elements
   for(
           var i=0; 
           LOCAL_div = document.getElementsByTagName("div")[i]; 
           i++
       ) {
       // if found the start element
       if (LOCAL_div.className == "superportal-start") {

           
           var LOCAL_initialSuperportal = document.createTextNode("Starting superportal system!");
           LOCAL_div.appendChild(LOCAL_initialSuperportal);
           var LOCAL_creationForm = new_element("form", "creation-form", "creation-form");
           LOCAL_creationForm.setAttribute("action", "javascript:return false;");
           LOCAL_div.appendChild(LOCAL_creationForm);
           LOCAL_creationForm = document.getElementById("creation-form");
    
           var LOCAL_newdiv = document.createElement("div");
           LOCAL_newdiv.setAttribute('id', 'LOCAL_newdiv');
           LOCAL_creationForm.appendChild(LOCAL_newdiv);
           var LOCAL_newdiv = document.getElementById("LOCAL_newdiv");
           LOCAL_newdiv.appendChild(document.createTextNode("News from: "));
           // drop down
           var LOCAL_countryMenu = new_element("select", "CountryMenu", "ContentSelectionMenu");
           LOCAL_countryMenu.setAttribute("onchange", "LOCAL_changeSelection(this.options[selectedIndex]);");
           LOCAL_newdiv.appendChild(LOCAL_countryMenu);
           LOCAL_countryMenu = document.getElementById("CountryMenu");
           new_option("CountryMenuCanada", "CountryMenu", "Canada", LOCAL_countryMenu);
           new_option("CountryMenuUSA", "CountryMenu", "United States", LOCAL_countryMenu);
           new_option("CountryMenuAustralia", "CountryMenu", "Australia", LOCAL_countryMenu);
           new_option("CountryMenuNZ", "CountryMenu", "New Zealand", LOCAL_countryMenu);
           //hide stuff to begin with
           LOCAL_changeSelection(null);

           //hide h2's for data container
           for (var i = 0;allh2 = document.getElementsByTagName("span")[i];i++) {
                if (allh2.className == "superportal-data-container") {
                  allh2.style.display = "none";
                }
           } 
      
       }
   }
   

}
function LOCAL_changeSelection(selected) {
 //!!!hide all
 for (var i = 0;allDivs = document.getElementsByTagName("div")[i];i++) {
  if (allDivs.className == "superportal-data") {
   allDivs.style.display = "none";
  }
 }
//if not null
if (selected)
{
  //!!!Show selected
  //alert("You selected " + selected.id);
  var  content = selected.id.substring(11, selected.id.length);
  //find div with desired content
  var contentDiv = document.getElementById("spdata-" + content);
  //make visible
  if (contentDiv) {
   contentDiv.style.display = "block";
  } else if (!contentDiv) {
   alert("ERROR: no spdata div -" + content);
  }
 }
}
addLoadEvent(LOCAL_initiate_superportal);