Upgrade to 4.2.8
[usit-rt.git] / share / static / js / superfish.js
1
2 /*
3  * Superfish v1.5.1 - jQuery menu widget
4  * Copyright (c) 2013 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  */
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>'),
18                         over = function(e){
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).length<1){
30                                                 o.onIdle.call(this);
31                                                 over.call(o.$path);
32                                         }
33                                 },o.delay);     
34                         },
35                         getMenu = function($child){
36                                 if ($child.hasClass(c.menuClass)){
37                                         $.error('Superfish requires you to update to a version of hoverIntent that supports event-delegation, such as this one: https://github.com/joeldbirch/onHoverIntent');
38                                 }
39                                 var menu = $child.closest('.'+c.menuClass)[0];
40                                 sf.op = sf.o[menu.serial];
41                                 return menu;
42                         },
43                         applyHandlers = function($menu){
44                                 var targets = 'li:has(ul)';
45                                 if ($.fn.hoverIntent && !sf.op.disableHI){
46                                         $menu.hoverIntent(over, out, targets);
47                                 } else {
48                                         $menu.on('mouseenter', targets, over);
49                                         $menu.on('mouseleave', targets, out);
50                                 }
51                                 $menu.on('focusin', targets, over);
52                                 $menu.on('focusout', targets, out);
53                         },
54                         addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
55                         
56                 return this.addClass(c.menuClass).each(function() {
57                         var s = this.serial = sf.o.length;
58                         var o = $.extend({},sf.defaults,op);
59                         var $$ = $(this);
60                         o.$path = $$.find('li.'+o.pathClass).slice(0,o.pathLevels).each(function(){
61                                 $(this).addClass(o.hoverClass+' '+c.bcClass)
62                                         .filter('li:has(ul)').removeClass(o.pathClass);
63                         });
64                         sf.o[s] = sf.op = o;
65                         
66                         applyHandlers($$);
67                         
68                         $$.find('li:has(ul)').each(function() {
69                                 if (o.autoArrows) {
70                                         addArrow( $('>a:first-child',this) );
71                                 }
72                         })
73                         .not('.'+c.bcClass)
74                                 .hideSuperfishUl();
75                         
76                         o.onInit.call(this);
77                         
78                 });
79         };
80
81         var sf = $.fn.superfish;
82         sf.o = [];
83         sf.op = {};
84
85         sf.c = {
86                 bcClass     : 'sf-breadcrumb',
87                 menuClass   : 'sf-js-enabled',
88                 anchorClass : 'sf-with-ul',
89                 arrowClass  : 'sf-sub-indicator'
90         };
91         sf.defaults = {
92                 hoverClass      : 'sfHover',
93                 pathClass       : 'overideThisToUse',
94                 pathLevels      : 1,
95                 delay           : 800,
96                 animation       : {opacity:'show'},
97                 speed           : 'normal',
98                 autoArrows      : true,
99                 disableHI       : false,                // true disables hoverIntent detection
100                 onInit          : function(){}, // callback functions
101                 onBeforeShow: function(){},
102                 onShow          : function(){},
103                 onHide          : function(){},
104                 onIdle          : function(){}
105         };
106         $.fn.extend({
107                 hideSuperfishUl : function(){
108                         var o = sf.op,
109                                 not = (o.retainPath===true) ? o.$path : '';
110                         o.retainPath = false;
111                         var $ul = $('li.'+o.hoverClass,this).add(this).not(not).removeClass(o.hoverClass)
112                                         .find('>ul').hide().css('visibility','hidden');
113                         o.onHide.call($ul);
114                         return this;
115                 },
116                 showSuperfishUl : function(){
117                         var o = sf.op,
118                                 $ul = this.addClass(o.hoverClass)
119                                         .find('>ul:hidden').css('visibility','visible');
120                         o.onBeforeShow.call($ul);
121                         $ul.animate(o.animation,o.speed,function(){ o.onShow.call($ul); });
122                         return this;
123                 }
124         });
125
126 })(jQuery);