home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 March / maximum-cd-2012-03.iso / DiscContents / npp.5.9.6.2.Installer.exe / user.manual / sites / all / modules / dhtml_menu / dhtml_menu5dbc.js < prev   
Encoding:
JavaScript  |  2011-07-18  |  4.8 KB  |  165 lines

  1. // $Id: dhtml_menu.js,v 1.18.2.10 2009/01/12 10:13:30 arancaytar Exp $
  2.  
  3. /**
  4.  * @file dhtml_menu.js
  5.  * The Javascript code for DHTML Menu
  6.  */
  7.  
  8. Drupal.dhtmlMenu = {};
  9.  
  10. /**
  11.  * Initialize the module's JS functions
  12.  */
  13. Drupal.behaviors.dhtmlMenu = function() {
  14.   // Do not run this function more than once.
  15.   if (Drupal.dhtmlMenu.init) {
  16.     return;
  17.   }
  18.   else {
  19.     Drupal.dhtmlMenu.init = true;
  20.   }
  21.  
  22.   // Get the settings.
  23.   var effects = Drupal.settings.dhtmlMenu;
  24.  
  25.   $('.collapsed').removeClass('expanded');
  26.  
  27.   // Get cookie
  28.   if (!effects.siblings) {
  29.     var cookie = Drupal.dhtmlMenu.cookieGet();
  30.     for (var i in cookie) {
  31.       // If the cookie was not applied to the HTML code yet, do so now.
  32.       var li = $('#dhtml_menu-' + cookie[i]).parents('li:first');
  33.       if ($(li).hasClass('collapsed')) {
  34.         Drupal.dhtmlMenu.toggleMenu(li);
  35.       }
  36.     }
  37.   }
  38.  
  39.   /* Add jQuery effects and listeners to all menu items.
  40.    * The ~ (sibling) selector is unidirectional and selects 
  41.    * only the latter element, so we must use siblings() to get 
  42.    * back to the link element.
  43.    */
  44.    $('ul.menu li.dhtml-menu:not(.leaf,.no-dhtml)').each(function() {
  45.     var li = this;
  46.     if (effects.clone) {
  47.       var ul = $(li).find('ul:first');
  48.       if (ul.length) {
  49.         $(li).find('a:first').clone().prependTo(ul).wrap('<li class="leaf fake-leaf"></li>');
  50.       }
  51.     }
  52.  
  53.     if (effects.doubleclick) {
  54.       $(li).find('a:first').dblclick(function(e) {
  55.         window.location = this.href;
  56.       });
  57.     }
  58.  
  59.     $(li).find('a:first').click(function(e) {
  60.       Drupal.dhtmlMenu.toggleMenu($(li));
  61.       return false;
  62.     });
  63.   });
  64. }
  65.  
  66. /**
  67.  * Toggles the menu's state between open and closed.
  68.  *
  69.  * @param li
  70.  *   Object. The <li> element that will be expanded or collapsed.
  71.  */
  72. Drupal.dhtmlMenu.toggleMenu = function(li) {
  73.   var effects = Drupal.settings.dhtmlMenu;
  74.  
  75.   // If the menu is expanded, collapse it.
  76.   if($(li).hasClass('expanded')) {
  77.     if (effects.slide) {
  78.       $(li).find('ul:first').animate({height: 'hide', opacity: 'hide'}, '1000');
  79.     }
  80.     else $(li).find('ul:first').css('display', 'none');
  81.  
  82.     // If children are closed automatically, find and close them now.
  83.     if (effects.children) {
  84.       if (effects.slide) {
  85.         $(li).find('li.expanded').find('ul:first').animate({height: 'hide', opacity: 'hide'}, '1000');
  86.       }
  87.       else $(li).find('li.expanded').find('ul:first').css('display', 'none');
  88.  
  89.       $(li).find('li.expanded').removeClass('expanded').addClass('collapsed')
  90.     }
  91.  
  92.     $(li).removeClass('expanded').addClass('collapsed');
  93.   }
  94.  
  95.   // Otherwise, expand it.
  96.   else {
  97.     if (effects.slide) {
  98.       $(li).find('ul:first').animate({height: 'show', opacity: 'show'}, '1000');
  99.     }
  100.     else $(li).find('ul:first').css('display', 'block');
  101.     $(li).removeClass('collapsed').addClass('expanded');
  102.  
  103.     // If the siblings effect is on, close all sibling menus.
  104.     if (effects.siblings) {
  105.       var id = $(li).find('a:first').attr('id');
  106.  
  107.       // Siblings are all open menus that are neither parents nor children of this menu.
  108.       $(li).find('li').addClass('own-children-temp');
  109.       
  110.       // If the relativity option is on, select only the siblings that have the same parent
  111.       if (effects.relativity) {
  112.         var siblings = $(li).parent().find('li.expanded').not('.own-children-temp').not(':has(#' + id + ')');
  113.       }
  114.       // Otherwise, select all menus of the same level
  115.       else {
  116.         var siblings = $('ul.menu li.expanded').not('.own-children-temp').not(':has(#' + id + ')');
  117.       }
  118.  
  119.       // If children should not get closed automatically...
  120.       if (!effects.children) {
  121.         // Remove items that are currently hidden from view (do not close these).
  122.         $('li.collapsed li.expanded').addClass('sibling-children-temp');
  123.         // Only close the top-most open sibling, not its children.
  124.         $(siblings).find('li.expanded').addClass('sibling-children-temp');
  125.         siblings = $(siblings).not('.sibling-children-temp');
  126.       }
  127.  
  128.       $('.own-children-temp, .sibling-children-temp').removeClass('own-children-temp').removeClass('sibling-children-temp');
  129.  
  130.       if (effects.slide) {
  131.         $(siblings).find('ul:first').animate({height: 'hide', opacity: 'hide'}, '1000');
  132.       }
  133.       else $(siblings).find('ul:first').css('display', 'none');
  134.  
  135.       $(siblings).removeClass('expanded').addClass('collapsed');
  136.     }
  137.   }
  138.  
  139.   // Save the current state of the menus in the cookie.
  140.   Drupal.dhtmlMenu.cookieSet();
  141. }
  142.  
  143. /**
  144.  * Reads the dhtml_menu cookie.
  145.  */
  146. Drupal.dhtmlMenu.cookieGet = function() {
  147.   var c = /dhtml_menu=(.*?)(;|$)/.exec(document.cookie);
  148.   if (c) {
  149.     return c[1];
  150.   }
  151.   else return '';
  152. }
  153.  
  154. /**
  155.  * Saves the dhtml_menu cooki.
  156.  */
  157. Drupal.dhtmlMenu.cookieSet = function() {
  158.   var expanded = new Array();
  159.   $('li.expanded').each(function() {
  160.     expanded.push($(this).find('a:first').attr('id').substr(5));
  161.   });
  162.   document.cookie = 'dhtml_menu=' + expanded.join(',') + ';path=/';
  163. }
  164.  
  165.