2009-07-04 05:37:30 +00:00
|
|
|
(function ($) {
|
|
|
|
|
2012-05-08 02:57:33 +00:00
|
|
|
"use strict";
|
|
|
|
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar = Drupal.toolbar || {};
|
|
|
|
|
2009-07-04 05:37:30 +00:00
|
|
|
/**
|
2010-01-26 21:42:37 +00:00
|
|
|
* Attach toggling behavior and notify the overlay of the toolbar.
|
2009-07-04 05:37:30 +00:00
|
|
|
*/
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.behaviors.toolbar = {
|
2012-08-24 12:19:11 +00:00
|
|
|
attach: function(context, settings) {
|
|
|
|
var $toolbar = $('#toolbar').once('toolbar');
|
|
|
|
if ($toolbar.length) {
|
2009-07-04 05:37:30 +00:00
|
|
|
|
2012-08-24 12:19:11 +00:00
|
|
|
// Set the initial state of the toolbar.
|
|
|
|
Drupal.toolbar.init();
|
|
|
|
|
|
|
|
$(window).on('resize.toolbar', Drupal.toolbar.height);
|
|
|
|
|
|
|
|
// Toggling toolbar drawer.
|
|
|
|
$toolbar.find('a.toggle').once('toolbar-toggle').click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
Drupal.toolbar.toggle();
|
|
|
|
// Allow resize event handlers to recalculate sizes/positions.
|
|
|
|
$(window).triggerHandler('resize');
|
|
|
|
});
|
|
|
|
}
|
2009-07-04 05:37:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve last saved cookie settings and set up the initial toolbar state.
|
|
|
|
*/
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar.init = function() {
|
2009-07-04 05:37:30 +00:00
|
|
|
// Retrieve the collapsed status from a stored cookie.
|
2010-01-26 21:42:37 +00:00
|
|
|
var collapsed = $.cookie('Drupal.toolbar.collapsed');
|
2009-07-04 05:37:30 +00:00
|
|
|
|
|
|
|
// Expand or collapse the toolbar based on the cookie value.
|
2012-06-23 16:50:41 +00:00
|
|
|
if (collapsed === '1') {
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar.collapse();
|
2009-07-04 05:37:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar.expand();
|
2009-07-04 05:37:30 +00:00
|
|
|
}
|
2010-01-04 16:08:52 +00:00
|
|
|
};
|
2009-07-04 05:37:30 +00:00
|
|
|
|
|
|
|
/**
|
2010-01-26 21:42:37 +00:00
|
|
|
* Collapse the toolbar.
|
2009-07-04 05:37:30 +00:00
|
|
|
*/
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar.collapse = function() {
|
2010-12-01 07:05:26 +00:00
|
|
|
var toggle_text = Drupal.t('Show shortcuts');
|
2009-10-17 00:51:53 +00:00
|
|
|
$('#toolbar div.toolbar-drawer').addClass('collapsed');
|
2009-11-15 21:13:26 +00:00
|
|
|
$('#toolbar a.toggle')
|
|
|
|
.removeClass('toggle-active')
|
|
|
|
.attr('title', toggle_text)
|
|
|
|
.html(toggle_text);
|
2010-05-23 18:23:32 +00:00
|
|
|
$('body').removeClass('toolbar-drawer').css('paddingTop', Drupal.toolbar.height());
|
2009-07-04 05:37:30 +00:00
|
|
|
$.cookie(
|
2010-01-26 21:42:37 +00:00
|
|
|
'Drupal.toolbar.collapsed',
|
2010-01-04 16:08:52 +00:00
|
|
|
1,
|
2009-11-17 18:51:19 +00:00
|
|
|
{
|
|
|
|
path: Drupal.settings.basePath,
|
|
|
|
// The cookie should "never" expire.
|
|
|
|
expires: 36500
|
|
|
|
}
|
2009-07-04 05:37:30 +00:00
|
|
|
);
|
2012-08-24 12:19:11 +00:00
|
|
|
Drupal.toolbar.height();
|
|
|
|
$(document).trigger('offsettopchange');
|
2010-01-04 16:08:52 +00:00
|
|
|
};
|
2009-07-04 05:37:30 +00:00
|
|
|
|
|
|
|
/**
|
2010-01-26 21:42:37 +00:00
|
|
|
* Expand the toolbar.
|
2009-07-04 05:37:30 +00:00
|
|
|
*/
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar.expand = function() {
|
2010-12-01 07:05:26 +00:00
|
|
|
var toggle_text = Drupal.t('Hide shortcuts');
|
2009-10-17 00:51:53 +00:00
|
|
|
$('#toolbar div.toolbar-drawer').removeClass('collapsed');
|
2009-11-15 21:13:26 +00:00
|
|
|
$('#toolbar a.toggle')
|
|
|
|
.addClass('toggle-active')
|
|
|
|
.attr('title', toggle_text)
|
|
|
|
.html(toggle_text);
|
2010-05-23 18:23:32 +00:00
|
|
|
$('body').addClass('toolbar-drawer').css('paddingTop', Drupal.toolbar.height());
|
2009-07-04 05:37:30 +00:00
|
|
|
$.cookie(
|
2010-01-26 21:42:37 +00:00
|
|
|
'Drupal.toolbar.collapsed',
|
2010-01-04 16:08:52 +00:00
|
|
|
0,
|
2009-11-17 18:51:19 +00:00
|
|
|
{
|
|
|
|
path: Drupal.settings.basePath,
|
|
|
|
// The cookie should "never" expire.
|
|
|
|
expires: 36500
|
|
|
|
}
|
2009-07-04 05:37:30 +00:00
|
|
|
);
|
2012-08-24 12:19:11 +00:00
|
|
|
Drupal.toolbar.height();
|
|
|
|
$(document).trigger('offsettopchange');
|
2010-01-04 16:08:52 +00:00
|
|
|
};
|
2009-07-04 05:37:30 +00:00
|
|
|
|
|
|
|
/**
|
2010-01-26 21:42:37 +00:00
|
|
|
* Toggle the toolbar.
|
2009-07-04 05:37:30 +00:00
|
|
|
*/
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar.toggle = function() {
|
2009-11-15 21:13:26 +00:00
|
|
|
if ($('#toolbar div.toolbar-drawer').hasClass('collapsed')) {
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar.expand();
|
2009-07-04 05:37:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-01-26 21:42:37 +00:00
|
|
|
Drupal.toolbar.collapse();
|
2009-07-04 05:37:30 +00:00
|
|
|
}
|
2010-01-04 16:08:52 +00:00
|
|
|
};
|
2009-07-04 05:37:30 +00:00
|
|
|
|
2010-05-23 18:23:32 +00:00
|
|
|
Drupal.toolbar.height = function() {
|
2012-08-24 12:19:11 +00:00
|
|
|
// @TODO this needs to be cached outside this function.
|
2012-03-12 03:11:11 +00:00
|
|
|
var $toolbar = $('#toolbar');
|
|
|
|
var height = $toolbar.outerHeight();
|
2012-08-24 12:19:11 +00:00
|
|
|
$toolbar.attr('data-offset-top', height);
|
2010-05-23 18:23:32 +00:00
|
|
|
return height;
|
|
|
|
};
|
|
|
|
|
2009-07-04 05:37:30 +00:00
|
|
|
})(jQuery);
|