Minor dependency updates
[yaffs-website] / vendor / mehrpadin / superfish / superfish.js
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  * This is not the original jQuery Superfish plugin.
13  * Please refer to the README for more information.
14  */
15
16 (function($){
17   $.fn.superfish = function(op){
18     var sf = $.fn.superfish,
19       c = sf.c,
20       $arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
21       over = function(){
22         var $$ = $(this), menu = getMenu($$);
23         clearTimeout(menu.sfTimer);
24         $$.showSuperfishUl().siblings().hideSuperfishUl();
25       },
26       out = function(){
27         var $$ = $(this), menu = getMenu($$), o = sf.op;
28         clearTimeout(menu.sfTimer);
29         menu.sfTimer=setTimeout(function(){
30           if ($$.children('.sf-clicked').length == 0){
31             o.retainPath=($.inArray($$[0],o.$path)>-1);
32             $$.hideSuperfishUl();
33             if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
34           }
35         },o.delay);
36       },
37       getMenu = function($menu){
38         var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
39         sf.op = sf.o[menu.serial];
40         return menu;
41       },
42       addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
43
44     return this.each(function() {
45       var s = this.serial = sf.o.length;
46       var o = $.extend({},sf.defaults,op);
47       o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels),
48       p = o.$path;
49       for (var l = 0; l < p.length; l++){
50         p.eq(l).addClass([o.hoverClass,c.bcClass].join(' ')).filter('li:has(ul)').removeClass(o.pathClass);
51       }
52       sf.o[s] = sf.op = o;
53
54       $('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
55         if (o.autoArrows) addArrow( $(this).children('a:first-child, span.nolink:first-child') );
56       })
57       .not('.'+c.bcClass)
58         .hideSuperfishUl();
59
60       var $a = $('a, span.nolink',this);
61       $a.each(function(i){
62         var $li = $a.eq(i).parents('li');
63         $a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
64       });
65       o.onInit.call(this);
66
67     }).each(function() {
68       var menuClasses = [c.menuClass];
69       if (sf.op.dropShadows){
70         menuClasses.push(c.shadowClass);
71       }
72       $(this).addClass(menuClasses.join(' '));
73     });
74   };
75
76   var sf = $.fn.superfish;
77   sf.o = [];
78   sf.op = {};
79
80   sf.c = {
81     bcClass: 'sf-breadcrumb',
82     menuClass: 'sf-js-enabled',
83     anchorClass: 'sf-with-ul',
84     arrowClass: 'sf-sub-indicator',
85     shadowClass: 'sf-shadow'
86   };
87   sf.defaults = {
88     hoverClass: 'sfHover',
89     pathClass: 'overideThisToUse',
90     pathLevels: 1,
91     delay: 800,
92     animation: {opacity:'show'},
93     speed: 'fast',
94     autoArrows: true,
95     dropShadows: true,
96     disableHI: false, // true disables hoverIntent detection
97     onInit: function(){}, // callback functions
98     onBeforeShow: function(){},
99     onShow: function(){},
100     onHide: function(){}
101   };
102   $.fn.extend({
103     hideSuperfishUl : function(){
104       var o = sf.op,
105         not = (o.retainPath===true) ? o.$path : '';
106       o.retainPath = false;
107       var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
108           .children('ul').addClass('sf-hidden');
109       o.onHide.call($ul);
110       return this;
111     },
112     showSuperfishUl : function(){
113       var o = sf.op,
114         sh = sf.c.shadowClass+'-off',
115         $ul = this.addClass(o.hoverClass)
116           .children('ul.sf-hidden').hide().removeClass('sf-hidden');
117       o.onBeforeShow.call($ul);
118       $ul.animate(o.animation,o.speed,function(){ o.onShow.call($ul); });
119       return this;
120     }
121   });
122 })(jQuery);