simplemenu.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. hoverClass : "sfhover", animation : { opacity:"show", delay: 750 }
  25. })
  26. .find(">li[ul]")
  27. .mouseover(function(){
  28. $("ul", this).bgIframe({opacity:false});
  29. })
  30. .find("a")
  31. .focus(function(){
  32. $("ul", $("#simplemenu>li[ul]")).bgIframe({opacity:false});
  33. });
  34. $('#simplemenu').children('li.expanded').addClass('root');
  35. });
  36. /*
  37. * Superfish v1.3 - jQuery menu widget
  38. *
  39. * Copyright (c) 2007 Joel Birch
  40. *
  41. * Dual licensed under the MIT and GPL licenses:
  42. * http://www.opensource.org/licenses/mit-license.php
  43. * http://www.gnu.org/licenses/gpl.html
  44. *
  45. * YOU MAY DELETE THIS CHANGELOG:
  46. * v1.2.1 altered: 2nd July 07. added hide() before animate to make work for jQuery 1.1.3. See comment in 'over' function.
  47. * v1.2.2 altered: 2nd August 07. changed over function .find('ul') to .find('>ul') for smoother animations
  48. * Also deleted the iframe removal lines - not necessary it turns out
  49. * 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
  50. * .superfish rule in CSS instead of top:-999em
  51. * v1.3 : Pretty much a complete overhaul to make all original features work in 1.1.3.1 and above.
  52. * .superfish rule reverted back to top:-999em (which is better)
  53. */
  54. (function($){
  55. $.fn.superfish = function(o){
  56. var $sf = this,
  57. defaults = {
  58. hoverClass : 'sfHover',
  59. pathClass : 'overideThisToUse',
  60. delay : 800,
  61. animation : {opacity:'show'},
  62. speed : 'normal'
  63. },
  64. over = function(){
  65. clearTimeout(this.sfTimer);
  66. clearTimeout($sf[0].sfTimer);
  67. $(this)
  68. .showSuperfishUl()
  69. .siblings()
  70. .hideSuperfishUl();
  71. },
  72. out = function(){
  73. var $$ = $(this);
  74. if ( !$$.is('.'+o.bcClass) ) {
  75. this.sfTimer=setTimeout(function(){
  76. $$.hideSuperfishUl();
  77. if (!$('.'+o.hoverClass,$sf).length) {
  78. over.call($currents.hideSuperfishUl());
  79. }
  80. },o.delay);
  81. }
  82. };
  83. $.fn.extend({
  84. hideSuperfishUl : function(){
  85. return this
  86. .removeClass(o.hoverClass)
  87. .find('ul:visible')
  88. .hide()
  89. .end();
  90. },
  91. showSuperfishUl : function(){
  92. return this
  93. .addClass(o.hoverClass)
  94. .find('>ul:hidden')
  95. .animate(o.animation,o.speed,function(){
  96. $(this).removeAttr('style');
  97. })
  98. .end();
  99. },
  100. applySuperfishHovers : function(){
  101. return this[($.fn.hoverIntent) ? 'hoverIntent' : 'hover'](over,out);
  102. }
  103. });
  104. o = $.extend({bcClass:'sfbreadcrumb'},defaults,o || {});
  105. var $currents = $('.'+o.pathClass,this).filter('li[ul]');
  106. if ($currents.length) {
  107. $currents.each(function(){
  108. $(this).removeClass(o.pathClass).addClass(o.hoverClass+' '+o.bcClass);
  109. });
  110. }
  111. var $sfHovAr=$('li[ul]',this).applySuperfishHovers(over,out)
  112. .find('a').each(function(){
  113. var $a = $(this), $li = $a.parents('li');
  114. $a.focus(function(){
  115. over.call($li);
  116. return false;
  117. }).blur(function(){
  118. $li.removeClass(o.hoverClass);
  119. });
  120. })
  121. .end()
  122. .not('.'+o.bcClass)
  123. .hideSuperfishUl()
  124. .end();
  125. $(window).unload(function(){
  126. $sfHovAr.unbind('mouseover').unbind('mouseout');
  127. });
  128. return this.addClass('superfish').blur(function(){
  129. out.call(this);
  130. });
  131. };
  132. })(jQuery);
  133. /* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
  134. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  135. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  136. *
  137. * $LastChangedDate: 2007-03-07 15:07:51 -0600 (Wed, 07 Mar 2007) $
  138. * $Rev: 1505 $
  139. */
  140. /**
  141. * The bgiframe is chainable and applies the iframe hack to get
  142. * around zIndex issues in IE6. It will only apply itself in IE
  143. * and adds a class to the iframe called 'bgiframe'.
  144. *
  145. * It does take borders into consideration but all values
  146. * need to be in pixels and the element needs to have
  147. * position relative or absolute.
  148. *
  149. * NOTICE: This plugin uses CSS expersions in order to work
  150. * with an element's borders, height and with and can result in poor
  151. * performance when used on an element that changes properties
  152. * like size and position a lot. Two of these expressions can be
  153. * removed if border doesn't matter and performance does.
  154. * See lines 39 and 40 below and set top: 0 and left: 0
  155. * instead of their current values.
  156. *
  157. * @example $('div').bgiframe();
  158. * @before <div><p>Paragraph</p></div>
  159. * @result <div><iframe class="bgiframe".../><p>Paragraph</p></div>
  160. *
  161. * @name bgiframe
  162. * @type jQuery
  163. * @cat Plugins/bgiframe
  164. * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
  165. */
  166. jQuery.fn.bgIframe = jQuery.fn.bgiframe = function() {
  167. // This is only for IE6
  168. if ( !(jQuery.browser.msie && typeof XMLHttpRequest == 'function') ) return this;
  169. var html = '<iframe class="bgiframe" src="javascript:;" tabindex="-1" '
  170. +'style="display:block; position:absolute; '
  171. +'top: expression(((parseInt(this.parentNode.currentStyle.borderTopWidth) || 0) * -1) + \'px\'); '
  172. +'left:expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth) || 0) * -1) + \'px\'); '
  173. +'z-index:-1; filter:Alpha(Opacity=\'0\'); '
  174. +'width:expression(this.parentNode.offsetWidth + \'px\'); '
  175. +'height:expression(this.parentNode.offsetHeight + \'px\')"/>';
  176. return this.each(function() {
  177. if ( !jQuery('iframe.bgiframe', this)[0] )
  178. this.insertBefore( document.createElement(html), this.firstChild );
  179. });
  180. };