/* clickMenu - v0.1.4 (2007-03-20) * Copyright (c) 2007 Roman Weich * http://p.sohei.org * * Changelog: * v 0.1.4 - 2007-03-20 * -fix: the default options were overwritten by the context related options * -fix: hiding a submenu all hover- and click-events were unbound, even the ones not defined in this plugin - unbinding should work now * v 0.1.3 - 2007-03-13 * -fix: some display problems ie had when no width was set on the submenu, so on ie the width for each submenu will be explicitely set * -fix: the fix to the ie-width-problem is a fix to the "ie does not support css min-width stuff" problem too which displayed some submenus too narrow (it looked just not right) * -fix: some bugs, when user the was too fast with the mouse * v 0.1.2 - 2007-03-11 * -change: made a lot changes in the traversing routines to speed things up (having better memory usage now as well) * -change: added $.fn.clickMenu.setDefaults() for setting global defaults * -fix: hoverbug when a main menu item had no submenu * -fix: some bugs i found while rewriting most of the stuff * v 0.1.1 - 2007-03-04 * -change: the width of the submenus is no longer fixed, its set in the plugin now * -change: the submenu-arrow is now an img, not the background-img of the list element - that allows better positioning, and background-changes on hover (you have to set the image through the arrowSrc option) * -fix: clicking on a clickMenu while another was already open, didn't close the open one * -change: clicking on the open main menu item will close it * -fix: on an open menu moving the mouse to a main menu item and moving it fastly elsewere hid the whole menu * v 0.1.0 - 2007-03-03 */ (function($) { var defaults = { onClick: function(){ $(this).find('>a').each(function(){ if ( this.href ) { window.location = this.href; } }); }, arrowSrc: '', subDelay: 300, mainDelay: 10, fadeTime: 50 }; $.fn.clickMenu = function(options) { var shown = false; var fxChange = false; var liOffset = ( ($.browser.msie) ? 4 : 2 ); var settings = $.extend({}, defaults, options); var changeFX = function() { //change the $.fx function - through wich we can stop running animations if ( !fxChange ) { // thanks to Lincoln - http://www.nabble.com/forum/ViewPost.jtp?post=8863654&framed=y // Modify fx function by converting first to a String jQuery.fx = String(jQuery.fx).replace(RegExp("13\\);"), "13);if (options.saveTimer){ eval('elem.ivTimer=z.timer');}"); // make it a Function again jQuery.fx = Function( "elem", "options", "prop", jQuery.fx.substring (jQuery.fx.indexOf('{')+1, jQuery.fx.lastIndexOf('}'))); fxChange = true; } }; //stop the current animation var stopFade = function(elem) { if ( elem.ivTimer && elem.inFade ) { // thanks to Lincoln - http://www.nabble.com/forum/ViewPost.jtp?post=8863654&framed=y window.clearInterval(elem.ivTimer); if(elem.queue && elem.queue['fx']) { elem.queue['fx'].length = 0; } //remove the stuff.. elem.inFade = elem.ivTimer = false; } }; var hideDIV = function(div, delay) { //a timer running to show the div? if ( div.timer && !div.isVisible ) { clearTimeout(div.timer); } else if (div.timer) { return; //hide-timer already running } if ( div.isVisible ) { div.timer = setTimeout(function() { //remove events $(getAllChilds(getOneChild(div, 'UL'), 'LI')).unbind('mouseover', liHoverIn).unbind('mouseout', liHoverOut).unbind('click', settings.onClick); //hide it div.inFade = true; $(div).fadeOut({duration: settings.fadeTime, saveTimer: true, complete: function(){ div.inFade = null; div.isVisible = false; }}); div.timer = null; }, delay); } }; var showDIV = function(div, delay) { if ( div.timer ) { clearTimeout(div.timer); } if ( !div.isVisible ) { div.timer = setTimeout(function() { //check if the mouse is still over the parent item - if not dont show the submenu if ( !checkClass(div.parentNode, 'hover') ) { return; } //assign events to all div>ul>li-elements $(getAllChilds(getOneChild(div, 'UL'), 'LI')).mouseover(liHoverIn).mouseout(liHoverOut).click(settings.onClick); //ie? - add iframe if ( $.browser.msie && !getOneChild(div, 'IFRAME') ) { /* thanks to Mark Gibson - http://www.nabble.com/forum/ViewPost.jtp?post=6504414&framed=y */ //TODO: clone node $(div).append('