Projet

Général

Profil

Paste
Télécharger (3,85 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / libraries / superfish-version / superfish.js @ 5a7e6170

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

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

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

    
47
      $('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
48
        if (o.autoArrows) addArrow( $('>a:first-child',this) );
49
      })
50
      .not('.'+c.bcClass)
51
        .hideSuperfishUl();
52

    
53
      var $a = $('a',this);
54
      $a.each(function(i){
55
        var $li = $a.eq(i).parents('li');
56
        $a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
57
      });
58
      o.onInit.call(this);
59

    
60
    }).each(function() {
61
      var menuClasses = [c.menuClass];
62
      if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
63
      $(this).addClass(menuClasses.join(' '));
64
    });
65
  };
66

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