svn: /web/php/trunk/js/ common.js

[email protected] (Stewart Lord)
Newsgroups php.webmaster
Message-ID <[email protected]>
stewartlord                              Tue, 04 Jan 2011 05:38:14 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=307058

Log:
Fixed a couple of problems with the mega drop-down menu. It no longer requires
two clicks to switch the current menu when the current menu has no sub-menu.
Also, fixed an issue where repeatedly clicking the same link could break the
dom (we now ignore clicks while animating).

Changed paths:
    U   web/php/trunk/js/common.js

Modified: web/php/trunk/js/common.js
===================================================================
--- web/php/trunk/js/common.js	2011-01-04 05:30:18 UTC (rev 307057)
+++ web/php/trunk/js/common.js	2011-01-04 05:38:14 UTC (rev 307058)
@@ -6,27 +6,35 @@
         event.preventDefault();

         var clickedMenu = $(this);
-        var activeMenu  = $('#headmenu li.current');
         var container   = $('#mega-drop-down #menu-container');

+        // ignore clicks if we're busy.
+        if (container.hasClass('busy')) return;
+        container.addClass('busy');
+
         // function to activate the clicked menu.
         var activate = function(){
             clickedMenu.addClass('current');
             clickedMenu.find("div.children").appendTo(container);
-            container.find("div.children").slideUp(0).slideDown("fast");
+            container.find("div.children").slideUp(0).slideDown("fast",
+                function(){ container.removeClass('busy'); }
+            );
         };

         // if there is an active menu, deactivate it first.
+        var activeMenu    = $('#headmenu li.current');
+        var activeSubMenu = container.find("div.children");
         if (activeMenu.length) {
             activeMenu.removeClass('current');
-            var children = container.find("div.children");
-            if (children) {
-                children.slideUp('fast', function(){
-                    children.appendTo(activeMenu);
-                    if (activeMenu[0] != clickedMenu[0])
-                        activate();
-                });
-            }
+        }
+        if (activeSubMenu.length) {
+            activeSubMenu.slideUp('fast', function(){
+                activeSubMenu.appendTo(activeMenu);
+                if (activeMenu[0] != clickedMenu[0])
+                    activate();
+                else
+                    container.removeClass('busy');
+            });
         } else {
             activate();
         }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.