simplemenu.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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').append(simplemenu).children('li.expanded').addClass('root').superfish({
  22. animation : { opacity:"show", delay: 750 }
  23. })
  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. });
  33. /*
  34. * Superfish - jQuery menu widget
  35. *
  36. * Copyright (c) 2007 Joel Birch
  37. *
  38. * Dual licensed under the MIT and GPL licenses:
  39. * http://www.opensource.org/licenses/mit-license.php
  40. * http://www.gnu.org/licenses/gpl.html
  41. *
  42. * Last updated: 18/3/07 to remove iframes on 'out'
  43. */
  44. (function($){
  45. $.fn.superfish = function(o){
  46. var defaults = {
  47. hoverClass : "sfHover",
  48. delay : 500,
  49. animation : {opacity:"show"},
  50. speed : "normal"
  51. },
  52. over = function(){
  53. var $$ = $(this);
  54. clearTimeout(this.sfTimer);
  55. if (!$$.is("."+o.hoverClass)) {
  56. $$.addClass(o.hoverClass)
  57. .find("ul")
  58. .animate(o.animation,o.speed)
  59. .end()
  60. .siblings()
  61. .removeClass(o.hoverClass);
  62. }
  63. },
  64. out = function(){
  65. var $$ = $(this);
  66. this.sfTimer=setTimeout(function(){
  67. $$.removeClass(o.hoverClass)
  68. .find("iframe", this)
  69. .remove();
  70. },o.delay);
  71. };
  72. o = $.extend(defaults, o || {});
  73. var sfHovAr=$("li",this)
  74. .hover(over,out)
  75. .find("a").each(function() {
  76. var $a = $(this), $li = $a.parents("li");
  77. $a.focus(function(){ $li.each(over); })
  78. .blur(function(){ $li.each(out); });
  79. }).end();
  80. $(window).unload(function() {
  81. sfHovAr.unbind("mouseover").unbind("mouseout");
  82. });
  83. return this;
  84. };
  85. })(jQuery);
  86. /* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
  87. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  88. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  89. *
  90. * $LastChangedDate: 2007-03-07 15:07:51 -0600 (Wed, 07 Mar 2007) $
  91. * $Rev: 1505 $
  92. */
  93. /**
  94. * The bgiframe is chainable and applies the iframe hack to get
  95. * around zIndex issues in IE6. It will only apply itself in IE
  96. * and adds a class to the iframe called 'bgiframe'.
  97. *
  98. * It does take borders into consideration but all values
  99. * need to be in pixels and the element needs to have
  100. * position relative or absolute.
  101. *
  102. * NOTICE: This plugin uses CSS expersions in order to work
  103. * with an element's borders, height and with and can result in poor
  104. * performance when used on an element that changes properties
  105. * like size and position a lot. Two of these expressions can be
  106. * removed if border doesn't matter and performance does.
  107. * See lines 39 and 40 below and set top: 0 and left: 0
  108. * instead of their current values.
  109. *
  110. * @example $('div').bgiframe();
  111. * @before <div><p>Paragraph</p></div>
  112. * @result <div><iframe class="bgiframe".../><p>Paragraph</p></div>
  113. *
  114. * @name bgiframe
  115. * @type jQuery
  116. * @cat Plugins/bgiframe
  117. * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
  118. */
  119. jQuery.fn.bgIframe = jQuery.fn.bgiframe = function() {
  120. // This is only for IE6
  121. if ( !(jQuery.browser.msie && typeof XMLHttpRequest == 'function') ) return this;
  122. var html = '<iframe class="bgiframe" src="javascript:;" tabindex="-1" '
  123. +'style="display:block; position:absolute; '
  124. +'top: expression(((parseInt(this.parentNode.currentStyle.borderTopWidth) || 0) * -1) + \'px\'); '
  125. +'left:expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth) || 0) * -1) + \'px\'); '
  126. +'z-index:-1; filter:Alpha(Opacity=\'0\'); '
  127. +'width:expression(this.parentNode.offsetWidth + \'px\'); '
  128. +'height:expression(this.parentNode.offsetHeight + \'px\')"/>';
  129. return this.each(function() {
  130. if ( !jQuery('iframe.bgiframe', this)[0] )
  131. this.insertBefore( document.createElement(html), this.firstChild );
  132. });
  133. };