superfish-1.4.8.js 3.6 KB

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