simplemenu.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // $Id$
  2. $(document).ready(function() {
  3. // get the Drupal basepath
  4. var basePath = Drupal.settings.simplemenu.basePath;
  5. // get the element to add the menu to
  6. var element = Drupal.settings.simplemenu.element;
  7. var menu = '<ul id="simplemenu" class="clear-block"></ul>';
  8. switch (Drupal.settings.simplemenu.placement) {
  9. case 'prepend':
  10. $(menu).prependTo(element);
  11. break;
  12. case 'append':
  13. $(menu).appendTo(element);
  14. break;
  15. case 'replace':
  16. $(element).html(menu);
  17. break;
  18. }
  19. $('body').addClass('simplemenu-enabled');
  20. // Build menu
  21. $('#simplemenu')
  22. .append(simplemenu)
  23. .superfish( { speed: 'fast' } )
  24. .find(">li:has(ul)")
  25. .mouseover(function(){
  26. $("ul", this).bgIframe({opacity:false});
  27. })
  28. .find("a")
  29. .focus(function(){
  30. $("ul", $(".nav>li:has(ul)")).bgIframe({opacity:false});
  31. })
  32. .end()
  33. .end()
  34. .find("a")
  35. .removeAttr('title');
  36. $('#simplemenu').children('li.expanded').addClass('root');
  37. });
  38. /*
  39. * Superfish v1.3 - jQuery menu widget
  40. *
  41. * Copyright (c) 2007 Joel Birch
  42. *
  43. * Dual licensed under the MIT and GPL licenses:
  44. * http://www.opensource.org/licenses/mit-license.php
  45. * http://www.gnu.org/licenses/gpl.html
  46. *
  47. * YOU MAY DELETE THIS CHANGELOG:
  48. * v1.2.1 altered: 2nd July 07. added hide() before animate to make work for jQuery 1.1.3. See comment in 'over' function.
  49. * v1.2.2 altered: 2nd August 07. changed over function .find('ul') to .find('>ul') for smoother animations
  50. * Also deleted the iframe removal lines - not necessary it turns out
  51. * v1.2.3 altered: jquery 1.1.3.1 broke keyboard access - had to change quite a few things and set display:none on the
  52. * .superfish rule in CSS instead of top:-999em
  53. * v1.3 : Pretty much a complete overhaul to make all original features work in 1.1.3.1 and above.
  54. * .superfish rule reverted back to top:-999em (which is better)
  55. */
  56. (function($){
  57. $.fn.superfish = function(o){
  58. var $sf = this,
  59. defaults = {
  60. hoverClass : 'sfHover',
  61. pathClass : 'overideThisToUse',
  62. delay : 800,
  63. animation : {opacity:'show'},
  64. speed : 'normal'
  65. },
  66. over = function(){
  67. clearTimeout(this.sfTimer);
  68. clearTimeout($sf[0].sfTimer);
  69. $(this)
  70. .showSuperfishUl()
  71. .siblings()
  72. .hideSuperfishUl();
  73. },
  74. out = function(){
  75. var $$ = $(this);
  76. if ( !$$.is('.'+o.bcClass) ) {
  77. this.sfTimer=setTimeout(function(){
  78. $$.hideSuperfishUl();
  79. if (!$('.'+o.hoverClass,$sf).length) {
  80. over.call($currents.hideSuperfishUl());
  81. }
  82. },o.delay);
  83. }
  84. };
  85. $.fn.extend({
  86. hideSuperfishUl : function(){
  87. return this
  88. .removeClass(o.hoverClass)
  89. .find('ul:visible')
  90. .hide()
  91. .end();
  92. },
  93. showSuperfishUl : function(){
  94. return this
  95. .addClass(o.hoverClass)
  96. .find('>ul:hidden')
  97. .animate(o.animation,o.speed,function(){
  98. $(this).removeAttr('style');
  99. })
  100. .end();
  101. },
  102. applySuperfishHovers : function(){
  103. return this[($.fn.hoverIntent) ? 'hoverIntent' : 'hover'](over,out);
  104. }
  105. });
  106. o = $.extend({bcClass:'sfbreadcrumb'},defaults,o || {});
  107. var $currents = $('.'+o.pathClass,this).filter('li[ul]');
  108. if ($currents.length) {
  109. $currents.each(function(){
  110. $(this).removeClass(o.pathClass).addClass(o.hoverClass+' '+o.bcClass);
  111. });
  112. }
  113. var $sfHovAr=$('li[ul]',this).applySuperfishHovers(over,out)
  114. .find('a').each(function(){
  115. var $a = $(this), $li = $a.parents('li');
  116. $a.focus(function(){
  117. over.call($li);
  118. return false;
  119. }).blur(function(){
  120. $li.removeClass(o.hoverClass);
  121. });
  122. })
  123. .end()
  124. .not('.'+o.bcClass)
  125. .hideSuperfishUl()
  126. .end();
  127. $(window).unload(function(){
  128. $sfHovAr.unbind('mouseover').unbind('mouseout');
  129. });
  130. return this.addClass('superfish').blur(function(){
  131. out.call(this);
  132. });
  133. };
  134. })(jQuery);
  135. /* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
  136. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  137. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  138. *
  139. * $LastChangedDate: 2007-07-21 18:45:56 -0500 (Sat, 21 Jul 2007) $
  140. * $Rev: 2447 $
  141. *
  142. * Version 2.1.1
  143. */
  144. (function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};})(jQuery);