toolbar.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. (function ($) {
  2. Drupal.toolbar = Drupal.toolbar || {};
  3. /**
  4. * Attach toggling behavior and notify the overlay of the toolbar.
  5. */
  6. Drupal.behaviors.toolbar = {
  7. attach: function(context) {
  8. // Set the initial state of the toolbar.
  9. $('#toolbar', context).once('toolbar', Drupal.toolbar.init);
  10. // Toggling toolbar drawer.
  11. $('#toolbar a.toggle', context).once('toolbar-toggle').click(function(e) {
  12. Drupal.toolbar.toggle();
  13. // Allow resize event handlers to recalculate sizes/positions.
  14. $(window).triggerHandler('resize');
  15. return false;
  16. });
  17. }
  18. };
  19. /**
  20. * Retrieve last saved cookie settings and set up the initial toolbar state.
  21. */
  22. Drupal.toolbar.init = function() {
  23. // Retrieve the collapsed status from a stored cookie.
  24. var collapsed = $.cookie('Drupal.toolbar.collapsed');
  25. // Expand or collapse the toolbar based on the cookie value.
  26. if (collapsed == 1) {
  27. Drupal.toolbar.collapse();
  28. }
  29. else {
  30. Drupal.toolbar.expand();
  31. }
  32. };
  33. /**
  34. * Collapse the toolbar.
  35. */
  36. Drupal.toolbar.collapse = function() {
  37. var toggle_text = Drupal.t('Show shortcuts');
  38. $('#toolbar div.toolbar-drawer').addClass('collapsed');
  39. $('#toolbar a.toggle')
  40. .removeClass('toggle-active')
  41. .attr('title', toggle_text)
  42. .html(toggle_text);
  43. $('body').removeClass('toolbar-drawer').css('paddingTop', Drupal.toolbar.height());
  44. $.cookie(
  45. 'Drupal.toolbar.collapsed',
  46. 1,
  47. {
  48. path: Drupal.settings.basePath,
  49. // The cookie should "never" expire.
  50. expires: 36500
  51. }
  52. );
  53. };
  54. /**
  55. * Expand the toolbar.
  56. */
  57. Drupal.toolbar.expand = function() {
  58. var toggle_text = Drupal.t('Hide shortcuts');
  59. $('#toolbar div.toolbar-drawer').removeClass('collapsed');
  60. $('#toolbar a.toggle')
  61. .addClass('toggle-active')
  62. .attr('title', toggle_text)
  63. .html(toggle_text);
  64. $('body').addClass('toolbar-drawer').css('paddingTop', Drupal.toolbar.height());
  65. $.cookie(
  66. 'Drupal.toolbar.collapsed',
  67. 0,
  68. {
  69. path: Drupal.settings.basePath,
  70. // The cookie should "never" expire.
  71. expires: 36500
  72. }
  73. );
  74. };
  75. /**
  76. * Toggle the toolbar.
  77. */
  78. Drupal.toolbar.toggle = function() {
  79. if ($('#toolbar div.toolbar-drawer').hasClass('collapsed')) {
  80. Drupal.toolbar.expand();
  81. }
  82. else {
  83. Drupal.toolbar.collapse();
  84. }
  85. };
  86. Drupal.toolbar.height = function() {
  87. var $toolbar = $('#toolbar');
  88. var height = $toolbar.outerHeight();
  89. // In modern browsers (including IE9), when box-shadow is defined, use the
  90. // normal height.
  91. var cssBoxShadowValue = $toolbar.css('box-shadow');
  92. var boxShadow = (typeof cssBoxShadowValue !== 'undefined' && cssBoxShadowValue !== 'none');
  93. // In IE8 and below, we use the shadow filter to apply box-shadow styles to
  94. // the toolbar. It adds some extra height that we need to remove.
  95. if (!boxShadow && /DXImageTransform\.Microsoft\.Shadow/.test($toolbar.css('filter'))) {
  96. height -= $toolbar[0].filters.item("DXImageTransform.Microsoft.Shadow").strength;
  97. }
  98. return height;
  99. };
  100. })(jQuery);