Projet

Général

Profil

Paste
Télécharger (2,33 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / mayo / js / mayo-fontsize.js @ fbb05e21

1 85ad3d82 Assos Assos
/**
2
 * @file
3 d7f58da2 Florent Torregrosa
 * Adds javascript functions for font resizing.
4 85ad3d82 Assos Assos
 */
5 70a4c29b Assos Assos
(function ($) {
6
$(document).ready(function() {
7
  var originalFontSize = $('body').css('font-size');
8 85ad3d82 Assos Assos
9
  // Reset font size
10 70a4c29b Assos Assos
  $(".resetFont").click(function() {
11 85ad3d82 Assos Assos
    mayoColumnsResetHeight();
12 70a4c29b Assos Assos
    $('body').css('font-size', originalFontSize);
13 85ad3d82 Assos Assos
    mayoColumnsAdjustHeight();
14
    return false;
15
  });
16
17
  // Increase font size
18 70a4c29b Assos Assos
  $(".increaseFont").click(function() {
19
    var currentFontSize = $('body').css('font-size');
20 85ad3d82 Assos Assos
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
21
    var newFontSizeNum = currentFontSizeNum + 1;
22
    if (20 >= newFontSizeNum) { /* max 20px */
23
      var newFontSize = newFontSizeNum + 'px';
24
      mayoColumnsResetHeight();
25 70a4c29b Assos Assos
      $('body').css('font-size', newFontSize);
26 85ad3d82 Assos Assos
      mayoColumnsAdjustHeight();
27
    }
28
    return false;
29
  });
30
31
  // Decrease font size
32 70a4c29b Assos Assos
  $(".decreaseFont").click(function() {
33
    var currentFontSize = $('body').css('font-size');
34 85ad3d82 Assos Assos
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
35
    var newFontSizeNum = currentFontSizeNum - 1;
36
    if (10 <= newFontSizeNum) { /* min 10px */
37
      var newFontSize = newFontSizeNum + 'px';
38
      mayoColumnsResetHeight();
39 70a4c29b Assos Assos
      $('body').css('font-size', newFontSize);
40 85ad3d82 Assos Assos
      mayoColumnsAdjustHeight();
41
    }
42
    return false;
43
  });
44
});
45 70a4c29b Assos Assos
})(jQuery);
46
47
function mayoEqualHeight(group) {
48
  var tallest = 0;
49
  group.each(function() {
50
    var thisHeight = jQuery(this).height();
51
    if (thisHeight > tallest) {
52
      tallest = thisHeight;
53
    }
54
  });
55
  group.height(tallest);
56
}
57 85ad3d82 Assos Assos
58
function mayoColumnsResetHeight() {
59
  // reset height of column blocks to 'auto' before chaning font size
60
  // so that the column blocks can change the size based on the new
61
  // font size
62
  if (mayoFunctionExists('mayoEqualHeight')) {
63
    jQuery("#top-columns .column-block").height('auto');
64
    jQuery("#bottom-columns .column-block").height('auto');
65
  }
66
}
67
function mayoColumnsAdjustHeight() {
68
  // equalize the height of the column blocks to the tallest height
69
  if (mayoFunctionExists('mayoEqualHeight')) {
70
    mayoEqualHeight(jQuery("#top-columns .column-block"));
71
    mayoEqualHeight(jQuery("#bottom-columns .column-block"));
72
  }
73
}
74
function mayoFunctionExists(function_name) {
75
  if (typeof function_name == 'string') {
76
    return (typeof this.window[function_name] == 'function');
77
  }
78
  else {
79
    return (function_name instanceof Function);
80
  }
81
}