This mini module leverages the power of jQuery to make the login block collapsible with a minimum of fuss. It mimics, in some ways, the login block effect from the LoginToboggan module. It create a block that has a link that acts as a trigger to show/hide the login block if it's on the same page.

This mini-module has 4 files, .info, .module, .js and .css. The CSS is unnecessary for the functioning. If you don't have the CSS aggregator turned on, you'd probably just want to append the CSS file to you theme's style.css file.

Create a directory "zmod" in the one of the usual locations for custom module (e.g. sites/all/modules or sites/default/modules) Save the code below, each block of code as a file, in that directory. Next go to admin/build/modules and enable Zmod Module, and go to admin/build/blocks and enable the Zmod block.

Put it somewhere near the top of the page (for example in the header). If the login block is on the same page and JS is enabled, then it will be hidden by default. By clicking on the login link, the block will expand. For a site visitor without JS, clicking on the link will take them to /user/login. If the user is logged in, the block displays a "logout" link. Note, you could also get the same effect by putting this code in a custom block in PHP format and cutting out the call to drupal_add_css().

zmod.info

; $Id$
name = Zmod Module
description = Custom utility functions

zmod.module

function zmod_block($op = 'list', $delta = 0, $edit = array()) {
  global $user;

  if ($op == 'list') {
    $blocks = array();
    $blocks[0]['info'] = t('User login/logout link');
    return $blocks;
  }
  elseif ($op == 'view') {
    $block = array();
    $module_path = drupal_get_path('module', 'zmod');
    drupal_add_css($module_path .'/zmod.css');

    switch ($delta) {
      case 0:
        if (!$user->uid) {
          $block['subject'] = '';
          $block['content'] = l(t('Login / Register'), 'user/login', array('id' => 'toggle-login'));
          drupal_add_js($module_path .'/zmod.js', 'module');
        }
        else {
          $block['subject'] = '';
          $block['content'] = check_plain($user->name) .' - '. l(t('Log out'), 'logout');
        }
        return $block;
    }
  }
}

Don't forget to leave out the ?> at the end, as it is known to cause problems.

zmod.js

if (Drupal.jsEnabled) {
  (function($) {
    $(document).ready(function() {
    $('#block-user-0').hide();
    $('#toggle-login').click(function() {
      $('#block-user-0').slideToggle('fast');
      return false;
    });
  });
  })(jQuery);
}

zmod.css

#block-zmod-0 {
 font-variant:small-caps;
 font-weight:bold;
 margin-right:15px;
 margin-top:8px;
 padding-right:15px;
 text-align:right;
}