Projet

Général

Profil

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

root / drupal7 / modules / toolbar / toolbar.js @ c7768a53

1
(function ($) {
2

    
3
Drupal.toolbar = Drupal.toolbar || {};
4

    
5
/**
6
 * Attach toggling behavior and notify the overlay of the toolbar.
7
 */
8
Drupal.behaviors.toolbar = {
9
  attach: function(context) {
10

    
11
    // Set the initial state of the toolbar.
12
    $('#toolbar', context).once('toolbar', Drupal.toolbar.init);
13

    
14
    // Toggling toolbar drawer.
15
    $('#toolbar a.toggle', context).once('toolbar-toggle').click(function(e) {
16
      Drupal.toolbar.toggle();
17
      // Allow resize event handlers to recalculate sizes/positions.
18
      $(window).triggerHandler('resize');
19
      return false;
20
    });
21
  }
22
};
23

    
24
/**
25
 * Retrieve last saved cookie settings and set up the initial toolbar state.
26
 */
27
Drupal.toolbar.init = function() {
28
  // Retrieve the collapsed status from a stored cookie.
29
  var collapsed = $.cookie('Drupal.toolbar.collapsed');
30

    
31
  // Expand or collapse the toolbar based on the cookie value.
32
  if (collapsed == 1) {
33
    Drupal.toolbar.collapse();
34
  }
35
  else {
36
    Drupal.toolbar.expand();
37
  }
38
};
39

    
40
/**
41
 * Collapse the toolbar.
42
 */
43
Drupal.toolbar.collapse = function() {
44
  var toggle_text = Drupal.t('Show shortcuts');
45
  $('#toolbar div.toolbar-drawer').addClass('collapsed');
46
  $('#toolbar a.toggle')
47
    .removeClass('toggle-active')
48
    .attr('title',  toggle_text)
49
    .html(toggle_text);
50
  $('body').removeClass('toolbar-drawer').css('paddingTop', Drupal.toolbar.height());
51
  $.cookie(
52
    'Drupal.toolbar.collapsed',
53
    1,
54
    {
55
      path: Drupal.settings.basePath,
56
      // The cookie should "never" expire.
57
      expires: 36500
58
    }
59
  );
60
};
61

    
62
/**
63
 * Expand the toolbar.
64
 */
65
Drupal.toolbar.expand = function() {
66
  var toggle_text = Drupal.t('Hide shortcuts');
67
  $('#toolbar div.toolbar-drawer').removeClass('collapsed');
68
  $('#toolbar a.toggle')
69
    .addClass('toggle-active')
70
    .attr('title',  toggle_text)
71
    .html(toggle_text);
72
  $('body').addClass('toolbar-drawer').css('paddingTop', Drupal.toolbar.height());
73
  $.cookie(
74
    'Drupal.toolbar.collapsed',
75
    0,
76
    {
77
      path: Drupal.settings.basePath,
78
      // The cookie should "never" expire.
79
      expires: 36500
80
    }
81
  );
82
};
83

    
84
/**
85
 * Toggle the toolbar.
86
 */
87
Drupal.toolbar.toggle = function() {
88
  if ($('#toolbar div.toolbar-drawer').hasClass('collapsed')) {
89
    Drupal.toolbar.expand();
90
  }
91
  else {
92
    Drupal.toolbar.collapse();
93
  }
94
};
95

    
96
Drupal.toolbar.height = function() {
97
  var $toolbar = $('#toolbar');
98
  var height = $toolbar.outerHeight();
99
  // In modern browsers (including IE9), when box-shadow is defined, use the
100
  // normal height.
101
  var cssBoxShadowValue = $toolbar.css('box-shadow');
102
  var boxShadow = (typeof cssBoxShadowValue !== 'undefined' && cssBoxShadowValue !== 'none');
103
  // In IE8 and below, we use the shadow filter to apply box-shadow styles to
104
  // the toolbar. It adds some extra height that we need to remove.
105
  if (!boxShadow && /DXImageTransform\.Microsoft\.Shadow/.test($toolbar.css('filter'))) {
106
    height -= $toolbar[0].filters.item("DXImageTransform.Microsoft.Shadow").strength;
107
  }
108
  return height;
109
};
110

    
111
})(jQuery);