MediaWiki:Common.js

From The Internet: Issues at the Frontier (course wiki)
Revision as of 19:49, 6 January 2009 by BerkmanSysop (talk | contribs) (added calendar ajax js)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

/*** Place in MediaWiki:Common.js ****/
function makeRequest(url) {
  var httpRequest;				
 
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
      httpRequest = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // IE
    try {
      httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
 
  if (!httpRequest) {
    alert("Giving up :( Cannot create an XMLHTTP instance");
    return false;
  }
  httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
  httpRequest.open("GET", url, true);
  httpRequest.send(null);
}
 
function alertContents(httpRequest) {
 
  if (httpRequest.readyState == 4) {
    if (httpRequest.status == 200) {
        document.getElementById("p-calendar").innerHTML = httpRequest.responseText;
    } else {
        document.getElementById("p-calendar").innerHTML = "<p>There was a problem with the request.</p>";
    }
  }
}