Projet

Général

Profil

Paste
Télécharger (4,04 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / nice_menus / js / superfish.js @ 0ccfec7f

1
;
2
/*!
3
 * Superfish v1.4.8 - jQuery menu widget
4
 * Copyright (c) 2008 Joel Birch
5
 *
6
 * Dual licensed under the MIT and GPL licenses:
7
 *         http://www.opensource.org/licenses/mit-license.php
8
 *         http://www.gnu.org/licenses/gpl.html
9
 *
10
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
11
 */
12
(function($){
13
  $.fn.superfish = function(op){
14

    
15
    var sf = $.fn.superfish,
16
    c = sf.c,
17
    $arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
18
    over = function(){
19
      var $$ = $(this), menu = getMenu($$);
20
      clearTimeout(menu.sfTimer);
21
      $$.showSuperfishUl().siblings().hideSuperfishUl();
22
    },
23
    out = function(){
24
      var $$ = $(this), menu = getMenu($$), o = sf.op;
25
      clearTimeout(menu.sfTimer);
26
      menu.sfTimer = setTimeout(function(){
27
        o.retainPath = ($.inArray($$[0],o.$path) > -1);
28
        $$.hideSuperfishUl();
29
        if (o.$path.length && $$.parents(['li.', o.hoverClass].join('')).length < 1){
30
          over.call(o.$path);
31
        }
32
      }, o.delay);
33
    },
34
    getMenu = function($menu){
35
      var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
36
      sf.op = sf.o[menu.serial];
37
      return menu;
38
    },
39
    addArrow = function($a){
40
      $a.addClass(c.anchorClass).append($arrow.clone());
41
    };
42

    
43
    return this.each(function() {
44
      var s = this.serial = sf.o.length;
45
      var o = $.extend({},sf.defaults,op);
46
      o.$path = $('li.' + o.pathClass,this).slice(0, o.pathLevels).each(function(){
47
        $(this).addClass([o.hoverClass,c.bcClass].join(' '))
48
        .filter('li:has(ul)').removeClass(o.pathClass);
49
      });
50
      sf.o[s] = sf.op = o;
51

    
52
      $('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
53
        if (o.autoArrows) {
54
          addArrow($('>a:first-child',this));
55
        }
56
      })
57
      .not('.' + c.bcClass)
58
      .hideSuperfishUl();
59

    
60
      var $a = $('a',this);
61
      $a.each(function(i){
62
        var $li = $a.eq(i).parents('li');
63
        $a.eq(i).focus(function(){
64
          over.call($li);
65
        }).blur(function(){
66
          out.call($li);
67
        });
68
      });
69
      o.onInit.call(this);
70

    
71
    }).each(function() {
72
      var menuClasses = [c.menuClass];
73
      if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) {
74
        menuClasses.push(c.shadowClass);
75
      }
76
      $(this).addClass(menuClasses.join(' '));
77
    });
78
  };
79

    
80
  var sf = $.fn.superfish;
81
  sf.o = [];
82
  sf.op = {};
83
  sf.IE7fix = function(){
84
    var o = sf.op;
85
    if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity != undefined) {
86
      this.toggleClass(sf.c.shadowClass + '-off');
87
    }
88
  };
89
  sf.c = {
90
    bcClass     : 'sf-breadcrumb',
91
    menuClass   : 'sf-js-enabled',
92
    anchorClass : 'sf-with-ul',
93
    arrowClass  : 'sf-sub-indicator',
94
    shadowClass : 'sf-shadow'
95
  };
96
  sf.defaults = {
97
    hoverClass        : 'sfHover',
98
    pathClass        : 'overideThisToUse',
99
    pathLevels        : 1,
100
    delay                : 800,
101
    animation        : {
102
      opacity:'show'
103
    },
104
    speed               : 'normal',
105
    autoArrows           : true,
106
    dropShadows : true,
107
    // true disables hoverIntent detection.
108
    disableHI     : false,
109
    onInit          : function(){}, // callback functions
110
    onBeforeShow: function(){},
111
    onShow          : function(){},
112
    onHide          : function(){}
113
  };
114
  $.fn.extend({
115
    hideSuperfishUl : function() {
116
      var o = sf.op,
117
      not = (o.retainPath === true) ? o.$path : '';
118
      o.retainPath = false;
119
      var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
120
      .find('>ul').hide().css('visibility','hidden');
121
      o.onHide.call($ul);
122
      return this;
123
    },
124
    showSuperfishUl : function(){
125
      var o = sf.op,
126
      sh = sf.c.shadowClass + '-off',
127
      $ul = this.addClass(o.hoverClass)
128
      .find('>ul:hidden').css('visibility','visible');
129
      sf.IE7fix.call($ul);
130
      o.onBeforeShow.call($ul);
131
      $ul.animate(o.animation,o.speed,function(){
132
        sf.IE7fix.call($ul);
133
        o.onShow.call($ul);
134
      });
135
      return this;
136
    }
137
  });
138

    
139
})(jQuery);