From f7b41b560ed0b7a081e82fe851bf6bb13c160030 Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Fri, 29 Jan 2010 16:36:22 +0300 Subject: [PATCH] * mttMenu submenu logics changed --- src/ajax.js | 92 ++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 4c5b505..aa8da33 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1132,55 +1132,54 @@ function mttMenu(container, options) this.menuOpen = false; this.options = options || {}; this.submenu = []; + this.curSubmenu = null; + this.showTimer = null; - //create submenus - this.container.find('li.mtt-menu-indicator').each(function() - { - var submenu = new mttMenu($(this).attr('submenu')); - submenu.$caller = $(this); - submenu.parent = menu; - if(menu.root) submenu.root = menu.root; //!! be careful with circular references - else submenu.root = menu; - menu.submenu.push(submenu); - - var showTimer, hideTimer; - $(this).hover( - function(){ - clearTimeout(hideTimer); - showTimer = setTimeout(function(){ - submenu.showSub(); - }, 300); - }, - function(){ - clearTimeout(showTimer); - hideTimer = setTimeout(function(){ - submenu.hide(); - }, 400); - } - ); - - submenu.container.hover( - function(){ - clearTimeout(hideTimer); - submenu.$caller.addClass('mtt-menu-item-active'); - }, - function(){ - hideTimer = setTimeout(function(){ - submenu.hide(); - }, 400); - submenu.$caller.removeClass('mtt-menu-item-active'); - } - ) - .find('li').click(function(){ - submenu.root.onclick(this, submenu); - return false; - }); - }); - - //if(!this.root) this.container.find('li').click(function(){ menu.onclick(this, menu); return false; + }) + .each(function(){ + + var submenu = 0; + if($(this).is('.mtt-menu-indicator')) + { + submenu = new mttMenu($(this).attr('submenu')); + submenu.$caller = $(this); + submenu.parent = menu; + if(menu.root) submenu.root = menu.root; //!! be careful with circular references + else submenu.root = menu; + menu.submenu.push(submenu); + + submenu.container.find('li').click(function(){ + submenu.root.onclick(this, submenu); + return false; + }); + } + + $(this).hover( + function(){ + if(!$(this).is('.mtt-menu-item-active')) menu.container.find('li').removeClass('mtt-menu-item-active'); + clearTimeout(menu.showTimer); + if(menu.curSubmenu && menu.curSubmenu.menuOpen && menu.curSubmenu != submenu) + { + menu.container.find('li').removeClass('mtt-menu-item-active'); + var curSubmenu = menu.curSubmenu; + hideTimer = setTimeout(function(){ + curSubmenu.hide(); + }, 400); + } + + if(!submenu || menu.curSubmenu == submenu && menu.curSubmenu.menuOpen) return; + menu.curSubmenu = submenu; + menu.showTimer = setTimeout(function(){ + submenu.showSub(); + }, 300); + $(this).addClass('mtt-menu-item-active'); + }, + null + ); + }); this.onclick = function(item, fromMenu) @@ -1194,6 +1193,7 @@ function mttMenu(container, options) { for(var i in this.submenu) this.submenu[i].hide(); this.container.hide(); + this.container.find('li').removeClass('mtt-menu-item-active'); this.menuOpen = false; } @@ -1247,7 +1247,7 @@ function mttMenu(container, options) var y = offset.top + this.parent.container.offset().top-this.parent.container.find('li:first').offset().top; if(y + this.container.outerHeight(true) > $(window).height() + $(document).scrollTop()) y = $(window).height() + $(document).scrollTop()- this.container.outerHeight(true) - 1; if(y<0) y=0; - this.container.css({ position: 'absolute', top: y, left: x /*, 'min-width': this.$caller.outerWidth()*/ }).show(); + this.container.css({ position: 'absolute', top: y, left: x, width:this.container.width() /*, 'min-width': this.$caller.outerWidth()*/ }).show(); this.menuOpen = true; }