Difference between revisions of "User:Svip/monobook.js"

From The Infosphere, the Futurama Wiki
Jump to navigation Jump to search
m
m
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
var barWidth = 200;
var topAmount = 500;
var currentAmount = 0;
function updateDonationNotice() {
function updateDonationNotice() {
   if(!document.getElementById("donation-progress-number"))
   if(!document.getElementById("donation-progress-number"))
     return;
     return;
   var number = document.getElementById("donation-progress-number");
   getDonation();
  var bar = document.getElementById("donation-progress-indicator");
  var barWidth = 200;
  var topAmount = 500;
  var currentAmount = 0;
  wfMsg('donation-amount', currentAmount, 'donation-progress-number');
  var nowWidth = (currentAmount/topAmount)*barWidth;
  number.innerHTML = currentAmount;
  bar.style.width = nowWidth + "px";
}
}


addOnloadHook(updateDonationNotice);
addOnloadHook(updateDonationNotice);


function wfMsg(msg, variable, elId) {
function getDonation() {
   var url = "/api.php?action=query&meta=allmessages&ammessages="+msg+"&amlang=en";
   var url = "/api.php?action=query&meta=allmessages&ammessages=donation-amount&amlang=en&format=xml";
   sajax_do_call(wfMsgEnd, [variable, elId], document.getElementById(elId));
   ajax(url, getDonationEnd, []);
}
 
function getDonationEnd(xml, data) {
  var doc = xml.documentElement;
  var currentAmount = parseInt(doc.getElementsByTagName("message")[0].firstChild.data);
  var nowWidth = (currentAmount/topAmount)*barWidth;
  var number = document.getElementById("donation-progress-number");
  number.innerHTML = currentAmount;
  var progBar = document.getElementById("donation-progress-indicator");
  progBar.setAttribute("style", "width: " + nowWidth + "px");
}
}


function wfMsgEnd(variable) {
function ajax(url, callbackFunction, data) {
   variable = document.getElementById(elId).innerHTML;
   var request = new XMLHttpRequest();
  request.open("GET", url, true);
  //request.setRequestHeader("Content-Type",
  //                        "application/x-www-form-urlencoded");
  request.onreadystatechange = function() {
    var done = 4, ok = 200;
    if (request.readyState == done) {
      if (request.status == ok) {
        if (request.responseXML) {
          callbackFunction(request.responseXML, data);
        }
      } else {
        if (request.responseXML) {
          alert(request.responseXML);
        } else {
          //alert('Fejl:  Serveren stak mig i ryggen og skred. ' + request.status)
        }
      }
    }
  };
  request.send(null);
}
}
//addOnloadHook(function() {if(wgPageName == 'Main_Page') importScript('User:Svip/brains.js')});

Latest revision as of 19:05, 23 July 2009

var barWidth = 200;
var topAmount = 500;
var currentAmount = 0;

function updateDonationNotice() {
  if(!document.getElementById("donation-progress-number"))
    return;
  getDonation();
}

addOnloadHook(updateDonationNotice);

function getDonation() {
  var url = "/api.php?action=query&meta=allmessages&ammessages=donation-amount&amlang=en&format=xml";
  ajax(url, getDonationEnd, []);
}

function getDonationEnd(xml, data) {
  var doc = xml.documentElement;
  var currentAmount = parseInt(doc.getElementsByTagName("message")[0].firstChild.data);
  var nowWidth = (currentAmount/topAmount)*barWidth;
  var number = document.getElementById("donation-progress-number");
  number.innerHTML = currentAmount;
  var progBar = document.getElementById("donation-progress-indicator");
  progBar.setAttribute("style", "width: " + nowWidth + "px");
}

function ajax(url, callbackFunction, data) {
  var request =  new XMLHttpRequest();
  request.open("GET", url, true);
  //request.setRequestHeader("Content-Type",
  //                         "application/x-www-form-urlencoded");
  request.onreadystatechange = function() {
    var done = 4, ok = 200;
    if (request.readyState == done) {
      if (request.status == ok) {
        if (request.responseXML) {
          callbackFunction(request.responseXML, data);
        }
      } else {
        if (request.responseXML) {
          alert(request.responseXML);
        } else {
          //alert('Fejl:  Serveren stak mig i ryggen og skred. ' + request.status)
        }
      }
    }
  };
  request.send(null);
}

//addOnloadHook(function() {if(wgPageName == 'Main_Page') importScript('User:Svip/brains.js')});