MediaWiki:Common.js

From Wikimedia District of Columbia
Revision as of 00:17, 19 January 2012 by Kirill Lokshin (talk | contribs) (Testing)
Jump to navigation Jump to search

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* sidebar modifications for anonymous users */

function removeSidebarSection(section) {
  try {
    var target = "p-" + section;
    var sidebar = document.getElementById("mw-panel");
    var element = document.getElementById(target);
    sidebar.removeChild(element);
  } catch (e) {
    return;
   }
}

function customizeSidebarForAnon() {
  removeSidebarSection("Internal");
  removeSidebarSection("tb");
}

function isObject(obj) {
  return typeof obj == "object" && obj != null;
}
 
function isArray(obj) {
  return isObject(obj) && obj.constructor.toString().indexOf("Array") != -1;
}

Array.prototype.Contains = function(element,strict) {
  for (i in this) {
    if (this[i] == element && !strict || this[i] === element) return true;
  }
  return false;
}

if (!isArray(wgUserGroups)) {
  addOnloadHook(customizeSidebarForAnon);
}

/* add membership payment button */
if ( ( mw.config.get('wgPageName') == 'Membership' ) && ( wgNamespaceNumber == 0 ) ) {
  $('#membershipbutton').html('<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="QTRS8N8RD8WNL"><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>');
}

/* add calendar */
if ( ( mw.config.get('wgPageName') == 'Calendar' ) && ( wgNamespaceNumber == 0 ) ) {
  $('#calendarwidget').html('<iframe src="http://www.google.com/calendar/embed?src=wikidc.org_svr4b3s6n6rs8mt189kbc4uegg%40group.calendar.google.com&ctz=America/New_York" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>');
}

/* add donate button */
if ( ( mw.config.get('wgPageName') == 'Donate' ) && ( wgNamespaceNumber == 0 ) ) {
  $('#donatebutton').html('<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="PSCZL9L3NKNRQ"><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>');
}