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 @ 70a4c29b

1
/**
2
 * @file
3
 * Adds javascript functions for font resizing.
4
 */
5
(function ($) {
6
$(document).ready(function() {
7
  var originalFontSize = $('body').css('font-size');
8

    
9
  // Reset font size
10
  $(".resetFont").click(function() {
11
    mayoColumnsResetHeight();
12
    $('body').css('font-size', originalFontSize);
13
    mayoColumnsAdjustHeight();
14
    return false;
15
  });
16

    
17
  // Increase font size
18
  $(".increaseFont").click(function() {
19
    var currentFontSize = $('body').css('font-size');
20
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
21
    var newFontSizeNum = currentFontSizeNum + 1;
22
    if (20 >= newFontSizeNum) { /* max 20px */
23
      var newFontSize = newFontSizeNum + 'px';
24
      mayoColumnsResetHeight();
25
      $('body').css('font-size', newFontSize);
26
      mayoColumnsAdjustHeight();
27
    }
28
    return false;
29
  });
30

    
31
  // Decrease font size
32
  $(".decreaseFont").click(function() {
33
    var currentFontSize = $('body').css('font-size');
34
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
35
    var newFontSizeNum = currentFontSizeNum - 1;
36
    if (10 <= newFontSizeNum) { /* min 10px */
37
      var newFontSize = newFontSizeNum + 'px';
38
      mayoColumnsResetHeight();
39
      $('body').css('font-size', newFontSize);
40
      mayoColumnsAdjustHeight();
41
    }
42
    return false;
43
  });
44
});
45
})(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

    
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
}