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