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 15:27, 21 June 2011 (update). 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 bodyStyle = document.getElementsByTagName('body')[0].style;

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

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

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

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