simplemenu.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. var animation = {};
  21. animation[Drupal.settings.simplemenu.effect] = 'toggle';
  22. // Build menu
  23. $('#simplemenu')
  24. .append(simplemenu)
  25. .superfish( {
  26. animation: animation,
  27. delay: Drupal.settings.simplemenu.hideDelay,
  28. speed: Drupal.settings.simplemenu.effectSpeed
  29. } )
  30. .find(">li:has(ul)")
  31. .mouseover(function(){
  32. $("ul", this).bgIframe({opacity:false});
  33. })
  34. .find("a")
  35. .focus(function(){
  36. $("ul", $(".nav>li:has(ul)")).bgIframe({opacity:false});
  37. })
  38. .end()
  39. .end()
  40. .find("a")
  41. .removeAttr('title');
  42. $('#simplemenu').children('li.expanded').addClass('root');
  43. });
  44. /*
  45. * Superfish v1.3 - jQuery menu widget
  46. *
  47. * Copyright (c) 2007 Joel Birch
  48. *
  49. * Dual licensed under the MIT and GPL licenses:
  50. * http://www.opensource.org/licenses/mit-license.php
  51. * http://www.gnu.org/licenses/gpl.html
  52. *
  53. * YOU MAY DELETE THIS CHANGELOG:
  54. * v1.2.1 altered: 2nd July 07. added hide() before animate to make work for jQuery 1.1.3. See comment in 'over' function.
  55. * v1.2.2 altered: 2nd August 07. changed over function .find('ul') to .find('>ul') for smoother animations
  56. * Also deleted the iframe removal lines - not necessary it turns out
  57. * 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
  58. * .superfish rule in CSS instead of top:-999em
  59. * v1.3 : Pretty much a complete overhaul to make all original features work in 1.1.3.1 and above.
  60. * .superfish rule reverted back to top:-999em (which is better)
  61. */
  62. (function($){
  63. $.fn.superfish = function(o){
  64. var $sf = this,
  65. defaults = {
  66. hoverClass : 'sfHover',
  67. pathClass : 'overideThisToUse',
  68. delay : 800,
  69. animation : {opacity:'show'},
  70. speed : 'normal'
  71. },
  72. over = function(){
  73. clearTimeout(this.sfTimer);
  74. clearTimeout($sf[0].sfTimer);
  75. $(this)
  76. .showSuperfishUl()
  77. .siblings()
  78. .hideSuperfishUl();
  79. },
  80. out = function(){
  81. var $$ = $(this);
  82. if ( !$$.is('.'+o.bcClass) ) {
  83. this.sfTimer=setTimeout(function(){
  84. $$.hideSuperfishUl();
  85. if (!$('.'+o.hoverClass,$sf).length) {
  86. over.call($currents.hideSuperfishUl());
  87. }
  88. },o.delay);
  89. }
  90. };
  91. $.fn.extend({
  92. hideSuperfishUl : function(){
  93. return this
  94. .removeClass(o.hoverClass)
  95. .find('ul:visible')
  96. .hide()
  97. .end();
  98. },
  99. showSuperfishUl : function(){
  100. return this
  101. .addClass(o.hoverClass)
  102. .find('>ul:hidden')
  103. .animate(o.animation,o.speed,function(){
  104. $(this).removeAttr('style');
  105. })
  106. .end();
  107. },
  108. applySuperfishHovers : function(){
  109. return this[($.fn.hoverIntent) ? 'hoverIntent' : 'hover'](over,out);
  110. }
  111. });
  112. o = $.extend({bcClass:'sfbreadcrumb'},defaults,o || {});
  113. var $currents = $('.'+o.pathClass,this).filter('li[ul]');
  114. if ($currents.length) {
  115. $currents.each(function(){
  116. $(this).removeClass(o.pathClass).addClass(o.hoverClass+' '+o.bcClass);
  117. });
  118. }
  119. var $sfHovAr=$('li[ul]',this).applySuperfishHovers(over,out)
  120. .find('a').each(function(){
  121. var $a = $(this), $li = $a.parents('li');
  122. $a.focus(function(){
  123. over.call($li);
  124. return false;
  125. }).blur(function(){
  126. $li.removeClass(o.hoverClass);
  127. });
  128. })
  129. .end()
  130. .not('.'+o.bcClass)
  131. .hideSuperfishUl()
  132. .end();
  133. $(window).unload(function(){
  134. $sfHovAr.unbind('mouseover').unbind('mouseout');
  135. });
  136. return this.addClass('superfish').blur(function(){
  137. out.call(this);
  138. });
  139. };
  140. })(jQuery);
  141. /* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
  142. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  143. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  144. *
  145. * $LastChangedDate: 2007-07-21 18:45:56 -0500 (Sat, 21 Jul 2007) $
  146. * $Rev: 2447 $
  147. *
  148. * Version 2.1.1
  149. */
  150. (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);