123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- (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();
- // Allow resize event handlers to recalculate sizes/positions.
- $(window).triggerHandler('resize');
- 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('Show shortcuts');
- $('#toolbar div.toolbar-drawer').addClass('collapsed');
- $('#toolbar a.toggle')
- .removeClass('toggle-active')
- .attr('title', toggle_text)
- .html(toggle_text);
- $('body').removeClass('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('Hide shortcuts');
- $('#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 $toolbar = $('#toolbar');
- var height = $toolbar.outerHeight();
- // In modern browsers (including IE9), when box-shadow is defined, use the
- // normal height.
- var cssBoxShadowValue = $toolbar.css('box-shadow');
- var boxShadow = (typeof cssBoxShadowValue !== 'undefined' && cssBoxShadowValue !== 'none');
- // In IE8 and below, we use the shadow filter to apply box-shadow styles to
- // the toolbar. It adds some extra height that we need to remove.
- if (!boxShadow && /DXImageTransform\.Microsoft\.Shadow/.test($toolbar.css('filter'))) {
- height -= $toolbar[0].filters.item("DXImageTransform.Microsoft.Shadow").strength;
- }
- return height;
- };
- })(jQuery);
|