Projet

Général

Profil

Révision a8cee257

Ajouté par Assos Assos il y a plus de 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/dhtml_menu/dhtml_menu.js
1
// $Id: dhtml_menu.js,v 1.49 2009/11/12 21:47:59 arancaytar Exp $
2 1

  
3 2

  
4 3

  
......
16 15
 * Initialize the module's JS functions
17 16
 */
18 17
Drupal.behaviors.dhtmlMenu = {
19
  attach: function() {
18
  attach: function(context, settings) {
20 19
    var settings = Drupal.settings.dhtmlMenu;
21 20

  
22 21
    // Initialize the animation effects from the settings.
......
29 28
    }
30 29

  
31 30
    // Sanitize by removing "expanded" on menus already marked "collapsed".
32
    $('li.dhtml-menu.collapsed.expanded').removeClass('expanded');
31
    $('li.dhtml-menu.collapsed.expanded', context).removeClass('expanded');
33 32

  
34 33
    /* Relevant only on "open-only" menus:
35 34
     * The links of expanded items should be marked for emphasis.
36 35
     */
37 36
    if (settings.nav == 'open') {
38
      $('li.dhtml-menu.expanded').addClass('dhtml-menu-open');
37
      $('li.dhtml-menu.expanded', context).addClass('dhtml-menu-open');
39 38
    }
40 39

  
41 40
    /* Relevant only when hovering:
......
55 54
    else if (settings.nav == 'hover') {
56 55
      var freeze = false;
57 56
      $('ul.menu').mouseenter(function() {freeze = false});
57
      $('ul.menu').focus(function() {freeze = false});
58 58
      $('body').mouseleave(function() {freeze = true});
59
      $('body').blur(function() {freeze = true});
59 60
    }
60 61

  
61 62
    /* Relevant only on bullet-icon expansion:
......
63 64
     */
64 65
    else if (settings.nav == 'bullet') {
65 66
      var bullet = $('<a href="#" class="dhtml-menu-icon"></a>');
66
      var rtl = $('html').attr('dir') == 'rtl' ? Math.ceil($('.menu li').css('margin-right').replace('px', '')) + 1 : 0;
67
      var rtl = 0;
68
      if ($('html').attr('dir') === 'rtl') {
69
        if (typeof($('.menu li').css('margin-right')) !== 'undefined') {
70
          rtl = Math.ceil($('.menu li').css('margin-right').replace('px', '')) + 1;
71
        }
72
      }
67 73
    }
68 74

  
69 75
    /* Relevant only when adding cloned links:
......
75 81
    }
76 82

  
77 83
    /* Add jQuery effects and listeners to all menu items. */
78
    $('ul.menu li.dhtml-menu:not(.leaf)').each(function() {
84
    $('ul.menu li.dhtml-menu:not(.leaf,.dhtml-processed)', context).each(function() {
85
      $(this).addClass("dhtml-processed");
79 86
      var li = $(this);
80 87
      var link = $(this).find('a:first');
81 88
      var ul = $(this).find('ul:first');
......
105 112
         * - @TODO: Explore whether "float:right" in dhtml_menu-rtl.css could solve this.
106 113
         */
107 114
        else if (settings.nav == 'bullet') {
108
          li.addClass('dhtml-folder');
115
          li.addClass('dhtml-folder dhtml-menu-processed');
109 116
          var b = bullet.clone().prependTo(link).click(function(e) {
110 117
            Drupal.dhtmlMenu.toggleMenu(li, link, ul);
111 118
            if (settings.effects.remember) {
......
125 132
         * - Add mouse-hovering events.
126 133
         */
127 134
        else if (settings.nav == 'hover') {
135
          link.focus(function(e) {
136
            Drupal.dhtmlMenu.switchMenu(li, link, ul, true);
137
          });
128 138
          link.mouseenter(function(e) {
129 139
              Drupal.dhtmlMenu.switchMenu(li, link, ul, true);
130 140
          });
......
142 152
              }, 10);
143 153
            }
144 154
          });
155
          li.blur(function(e) {
156
            // Only collapse the menu if it was initially collapsed.
157
            if (li.hasClass('start-collapsed')) {
158
              /* As explained earlier, this event fires before the body event.
159
               * We need to wait to make sure that the user isn't browsing a
160
               * context menu right now, in which case the menu isn't collapsed.
161
               */
162
              setTimeout(function() {
163
                if (!freeze) {
164
                  Drupal.dhtmlMenu.switchMenu(li, link, ul, false);
165
                }
166
              }, 10);
167
            }
168
          });
145 169
        }
146 170

  
147 171
        /* When using menus that cannot collapse:
......
174 198
    });
175 199

  
176 200
    // When using LTR, all icons can be shifted as one, as the text width is not relevant.
177
    if (settings.nav == 'bullet' && !rtl) {
201
    if (settings.nav == 'bullet' && !rtl && $('.menu li.dhtml-folder').length) {
178 202
      // Shift overlay to the left by the width of the icon and the distance between icon and text.
179
      var shift = '-' + (Math.ceil(($('.menu li').css('margin-left').replace('px', ''))) + 16) + 'px';
180
      // Shift the overlay using a negative left-hand offset, and the text using a negative right-hand margin.
181
      $('.dhtml-menu-icon').css('left', shift).css('margin-right', shift);
203
      if ($('.menu li').hasClass('margin-left')) {
204
        // Saved for a later backport if needs.
205
        if (typeof($('.menu li').css('margin-right')) !== 'undefined') {
206
          var shift = '-' + (Math.ceil(($('.menu li').css('margin-left').replace('px', ''))) + 16) + 'px';
207
          // Shift the overlay using a negative left-hand offset, and the text using a negative right-hand margin.
208
          $('.dhtml-menu-icon').css('left', shift).css('margin-right', shift);
209
        }
210
      }
182 211
    }
183 212
  }
184 213
}

Formats disponibles : Unified diff