simplemenu.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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').css('margin-top', '20px');
  20. // Build menu
  21. $('#simplemenu')
  22. .append(simplemenu)
  23. .superfish()
  24. .find(">li[ul]")
  25. .mouseover(function(){
  26. $("ul", this).bgiframe({opacity:false});
  27. })
  28. .find("a")
  29. .focus(function(){
  30. $("ul", $("#simplemenu>li[ul]")).bgiframe({opacity:false});
  31. });
  32. $('#simplemenu').children('li.expanded').addClass('root');
  33. });
  34. /*
  35. * Superfish v1.3.2 - jQuery menu widget
  36. *
  37. * Copyright (c) 2007 Joel Birch
  38. *
  39. * Dual licensed under the MIT and GPL licenses:
  40. * http://www.opensource.org/licenses/mit-license.php
  41. * http://www.gnu.org/licenses/gpl.html
  42. *
  43. * YOU SHOULD DELETE THIS CHANGELOG TO REDUCE FILE SIZE:
  44. * v1.2.1 altered: 2nd July 07. added hide() before animate to make work for jQuery 1.1.3. See comment in 'over' function.
  45. * v1.2.2 altered: 2nd August 07. changed over function .find('ul') to .find('>ul') for smoother animations
  46. * Also deleted the iframe removal lines - not necessary it turns out
  47. * 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
  48. * .superfish rule in CSS instead of top:-999em
  49. * v1.3 : Pretty much a complete overhaul to make all original features work in 1.1.3.1 and above.
  50. * .superfish rule reverted back to top:-999em (which is better).
  51. * v1.3.1 altered: 'li[ul]' to $('li:has(ul)') to work with jQuery 1.2
  52. * v1.3.2: added onshow callback option. 'this' keyword refers to revealed ul.
  53. fixed bug whereby multiple menus on a page shared options. Now each menu can have separate options.
  54. fixed IE6 and IE7 bug whereby under certain circumstances => 3rd tier menus appear instantly with text missing when revisited
  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. onshow : function(){} // in your function, 'this' is the revealed ul
  66. },
  67. over = function(){
  68. clearTimeout(this.sfTimer);
  69. $(this)
  70. .showSuperfishUl(o)
  71. .siblings()
  72. .hideSuperfishUl(o);
  73. },
  74. out = function(){
  75. var $$ = $(this);
  76. if ( !$$.is('.'+o.bcClass) ) {
  77. this.sfTimer=setTimeout(function(){
  78. $$.hideSuperfishUl(o);
  79. var sf = $$.parents('ul.superfish:first')[0];
  80. if (!$('.'+o.hoverClass,sf).length) {
  81. over.call(sf.o.$currents.hideSuperfishUl(o));
  82. }
  83. },o.delay);
  84. }
  85. };
  86. $.fn.extend({
  87. hideSuperfishUl : function(o){
  88. return this
  89. .removeClass(o.hoverClass)
  90. .find('ul')
  91. .hide()
  92. .css('visibility','hidden')
  93. .end();
  94. },
  95. showSuperfishUl : function(o){
  96. return this
  97. .addClass(o.hoverClass)
  98. .find('>ul:hidden')
  99. .css('visibility','visible')
  100. .animate(o.animation,o.speed,function(){
  101. o.onshow.call(this);
  102. })
  103. .end();
  104. },
  105. applySuperfishHovers : function(){
  106. return this[($.fn.hoverIntent) ? 'hoverIntent' : 'hover'](over,out);
  107. }
  108. });
  109. return this
  110. .addClass('superfish')
  111. .each(function(){
  112. o = $.extend({bcClass:'sfbreadcrumb'},defaults,o || {});
  113. o = $.extend(o,{$currents:$('li.'+o.pathClass+':has(ul)',this)});
  114. this.o = o;
  115. if (o.$currents.length) {
  116. o.$currents.each(function(){
  117. $(this).removeClass(o.pathClass).addClass(o.hoverClass+' '+o.bcClass);
  118. });
  119. }
  120. var $sfHovAr=$('li:has(ul)',this)
  121. .applySuperfishHovers(over,out)
  122. .find('a').each(function(){
  123. var $a = $(this), $li = $a.parents('li');
  124. $a.focus(function(){
  125. over.call($li);
  126. return false;
  127. }).blur(function(){
  128. out.call(this);
  129. $li.removeClass(o.hoverClass);
  130. return false;
  131. });
  132. })
  133. .end()
  134. .not('.'+o.bcClass)
  135. .hideSuperfishUl(o)
  136. .end();
  137. $(window).unload(function(){
  138. $sfHovAr.unbind('mouseover').unbind('mouseout');
  139. $('ul.superfish').each(function(){
  140. this.o = this.o.$currents = null; // clean up
  141. });
  142. });
  143. });
  144. };
  145. })(jQuery);
  146. /* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
  147. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  148. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  149. *
  150. * $LastChangedDate: 2007-07-21 18:45:56 -0500 (Sat, 21 Jul 2007) $
  151. * $Rev: 2447 $
  152. *
  153. * Version 2.1.1
  154. */
  155. (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);