Jump to content

User:Edokter/FontSizer.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Edokter (talk | contribs) at 16:39, 20 June 2011. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var fontsizerbuttons =
  '<li id="fontsizer">' +
    '<input type="submit" id="fontsizer-minus" name="minus" value="−" onclick="clickMinus()">' +
    '<input type="submit" id="fontsizer-reset" name="reset" value="100%" onclick="clickReset()">' +
    '<input type="submit" id="fontsizer-plus" name="plus" value="+" onclick="clickPlus()">' +
  '</li>';

var bodytag = document.getElementsByTagName('body')[0];

function updateButton(size) {
  var buttonval = document.getElementById('fontsizer-reset');
  buttonval.value = size + '%';
}

function clickMinus() {
  var currentSize = bodytag.style.fontSize.replace('%', '');
  if (!currentSize) {
    currentSize = 100;
  }
  if (currentSize > 100) {
    currentSize -= 10;
  } else {
    currentSize -= 5;
  }
  bodytag.style.fontSize = currentSize + '%';
  updateButton(currentSize);
}

function clickReset() {
  bodytag.style.fontSize = '100%';
  updateButton(100);
}

function clickPlus() {
  var currentSize = bodytag.style.fontSize.replace('%', '');
  if (!currentSize) {
    currentSize = 100;
  }
  if (currentSize < 100) {
    currentSize += 5;
  } else {
    currentSize += 10;
  }
  bodytag.style.fontSize = currentSize + '%';
  updateButton(currentSize);
}

$(function() {
  $('div#p-personal ul').append(fontsizerbuttons);
});