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 13:28, 21 June 2011 (Update code). 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.
$(function() {

  var fontsizerbuttons =
    '<li id="fontsizer">' +
      '<input type="submit" id="fontsizer-minus" name="minus" value="−">' +
      '<input type="submit" id="fontsizer-reset" name="reset" value="Font">' +
      '<input type="submit" id="fontsizer-plus" name="plus" value="+">' +
    '</li>';

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

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

  $('#fontsizer-minus').click(function() {
    var currentSize = parseInt(bodyTag.style.fontSize.replace('%', ''));
    if (!currentSize) {
      currentSize = 100;
    }
    if (currentSize > 50) {
      if (currentSize <= 100) {
        currentSize -= 5;
      } else {
        currentSize -= 10;
      }
    }
    bodyTag.style.fontSize = currentSize + '%';
    $('#fontsizer-reset').attr('value', currentSize + '%');
  });

  $('#fontsizer-plus').click(function() {
    var currentSize = parseInt(bodyTag.style.fontSize.replace('%', ''));
    if (!currentSize) {
      currentSize = 100;
    }
    if (currentSize < 200) {
      if (currentSize < 100) {
        currentSize += 5;
      } else {
        currentSize += 10;
      }
    }
    bodyTag.style.fontSize = currentSize + '%';
    $('#fontsizer-reset').attr('value', currentSize + '%');
  });

  $('#fontsizer-reset').click(function() {
    bodyTag.style.fontSize = '100%';
    $('#fontsizer-reset').attr('value', '100%');
  });
});