drupal/modules/toolbar/toolbar.js

109 lines
2.7 KiB
JavaScript

// $Id$
(function ($) {
Drupal.toolbar = Drupal.toolbar || {};
/**
* Attach toggling behavior and notify the overlay of the toolbar.
*/
Drupal.behaviors.toolbar = {
attach: function(context) {
// Set the initial state of the toolbar.
$('#toolbar', context).once('toolbar', Drupal.toolbar.init);
// Toggling toolbar drawer.
$('#toolbar a.toggle', context).once('toolbar-toggle').click(function(e) {
Drupal.toolbar.toggle();
// As the toolbar is an overlay displaced region, overlay should be
// notified of it's height change to adapt its position.
$(window).triggerHandler('resize.overlay-event');
return false;
});
}
};
/**
* Retrieve last saved cookie settings and set up the initial toolbar state.
*/
Drupal.toolbar.init = function() {
// Retrieve the collapsed status from a stored cookie.
var collapsed = $.cookie('Drupal.toolbar.collapsed');
// Expand or collapse the toolbar based on the cookie value.
if (collapsed == 1) {
Drupal.toolbar.collapse();
}
else {
Drupal.toolbar.expand();
}
};
/**
* Collapse the toolbar.
*/
Drupal.toolbar.collapse = function() {
var toggle_text = Drupal.t('Open the drawer');
$('#toolbar div.toolbar-drawer').addClass('collapsed');
$('#toolbar a.toggle')
.removeClass('toggle-active')
.attr('title', toggle_text)
.html(toggle_text);
$('body').addClass('toolbar-drawer').css('paddingTop', Drupal.toolbar.height());
$.cookie(
'Drupal.toolbar.collapsed',
1,
{
path: Drupal.settings.basePath,
// The cookie should "never" expire.
expires: 36500
}
);
};
/**
* Expand the toolbar.
*/
Drupal.toolbar.expand = function() {
var toggle_text = Drupal.t('Close the drawer');
$('#toolbar div.toolbar-drawer').removeClass('collapsed');
$('#toolbar a.toggle')
.addClass('toggle-active')
.attr('title', toggle_text)
.html(toggle_text);
$('body').addClass('toolbar-drawer').css('paddingTop', Drupal.toolbar.height());
$.cookie(
'Drupal.toolbar.collapsed',
0,
{
path: Drupal.settings.basePath,
// The cookie should "never" expire.
expires: 36500
}
);
};
/**
* Toggle the toolbar.
*/
Drupal.toolbar.toggle = function() {
if ($('#toolbar div.toolbar-drawer').hasClass('collapsed')) {
Drupal.toolbar.expand();
}
else {
Drupal.toolbar.collapse();
}
};
Drupal.toolbar.height = function() {
var height = $('#toolbar').outerHeight();
// In IE, Shadow filter adds some extra height, so we need to remove it from
// the returned height.
if ($('#toolbar').css('filter').match(/DXImageTransform\.Microsoft\.Shadow/)) {
height -= $('#toolbar').get(0).filters.item("DXImageTransform.Microsoft.Shadow").strength;
}
return height;
};
})(jQuery);