← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14678: Refactors menu code, removes old code and renames/moves some functions

 

------------------------------------------------------------
revno: 14678
committer: Mark Polak <markpo@xxxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-04 23:13:39 +0200
message:
  Refactors menu code, removes old code and renames/moves some functions
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/menu.css
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.menu.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/menu.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/menu.css	2014-04-03 10:43:18 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/menu.css	2014-04-04 21:13:39 +0000
@@ -362,18 +362,18 @@
     overflow-x: hidden;
 }
 
-#menuDropDown1 ul {
+#appsDropDown ul {
     height: 330px;
 }
 
-#menuDropDown1 .caret-up-background,
-#menuDropDown1 .caret-up-border
+#appsDropDown .caret-up-background,
+#appsDropDown .caret-up-border
 {
     left: 296px;
 }
 
-#menuDropDown3 .caret-up-background,
-#menuDropDown3 .caret-up-border
+#profileDropDown .caret-up-background,
+#profileDropDown .caret-up-border
 {
     left: 292px;
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.menu.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.menu.js	2014-04-03 15:58:51 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.menu.js	2014-04-04 21:13:39 +0000
@@ -369,14 +369,14 @@
     $.template('appMenuItemTemplate', markup);
 
     function renderDropDownFavorites() {
-        var selector = '#menuDropDown1 .menuDropDownBox',
+        var selector = '#appsDropDown .menuDropDownBox',
             apps = dhis2.menu.getOrderedAppList();
 
-        $('#menuDropDown1').addClass('app-menu-dropdown ui-helper-clearfix');
+        $('#appsDropDown').addClass('app-menu-dropdown ui-helper-clearfix');
         $(selector).html('');
         $.tmpl( "appMenuItemTemplate", apps).appendTo(selector);
-        $('#menuDropDown1 .menu-drop-down-scroll .apps-menu-more').remove();
-        $('.apps-menu-more').clone().css('display', 'table').addClass('ui-helper-clearfix').appendTo($('#menuDropDown1 .menu-drop-down-scroll'));
+        $('#appsDropDown .menu-drop-down-scroll .apps-menu-more').remove();
+        $('.apps-menu-more').clone().css('display', 'table').addClass('ui-helper-clearfix').appendTo($('#appsDropDown .menu-drop-down-scroll'));
     }
 
     function renderAppManager(selector) {
@@ -476,6 +476,10 @@
      * TODO: Check the urls (they seem to be specific to the dev location atm)
      */
     $(function () {
+        var menuTimeout = 500,
+            closeTimer = null,
+            dropDownId = null;
+
         $.ajax('../dhis-web-commons/menu/getModules.action').success(function (data) {
             if (typeof data.modules === 'object') {
                 menu.addMenuItems(data.modules);
@@ -485,7 +489,7 @@
             //TODO: Translate this error message
             var error_template = '<li class="app-menu-error"><a href="' + window.location.href +'">Unable to load your apps, click to refresh</a></li>';
             $('#' + selector).addClass('app-menu').html('<ul>' + error_template + '</ul>');
-            $('#menuDropDown1 .menuDropDownBox').html(error_template);
+            $('#appsDropDown .menuDropDownBox').html(error_template);
         });
 
         /**
@@ -505,12 +509,11 @@
         $(window).resize(twoColumnRowFix);
 
         /**
-         * Adds a scrolling mechanism that modifies the height of the menu box to show only two rows
-         * Additionally it makes space for the scrollbar and shows/hides the more apps button
+         * Adds a scrolling mechanism that makes space for the scrollbar and shows/hides the more apps button
          */
         $('.menu-drop-down-scroll').scroll(function (event) {
             var self = $(this),
-                moreAppsElement = $('#menuDropDown1 > .apps-menu-more');
+                moreAppsElement = $('#appsDropDown > .apps-menu-more');
 
             if (self.scrollTop() < 10) {
                 moreAppsElement.show();
@@ -526,43 +529,68 @@
 
         });
 
+        function showDropDown( id )
+        {
+            var newDropDownId = "#" + id,
+                position = $(newDropDownId + '_button').position();
+
+            cancelHideDropDownTimeout();
+
+            $(newDropDownId).css('position', 'absolute');
+            $(newDropDownId).css('top', '55px');
+            $(newDropDownId).css('left', Math.ceil(position.left - Math.ceil(parseInt($(newDropDownId).innerWidth(), 10) - 108)) + 'px');
+
+
+            if ( dropDownId != newDropDownId ) {
+                hideDropDown();
+
+                dropDownId = newDropDownId;
+
+                $( dropDownId ).show();
+            }
+        }
+
+        function hideDropDown() {
+            if ( dropDownId ) {
+                if ($( dropDownId ).attr( 'data-clicked-open' ) === 'true') {
+                    return;
+                }
+                $( dropDownId ).hide();
+
+                dropDownId = null;
+            }
+        }
+
+        function hideDropDownTimeout() {
+            closeTimer = window.setTimeout( hideDropDown, menuTimeout );
+        }
+
+        function cancelHideDropDownTimeout() {
+            if ( closeTimer ) {
+                window.clearTimeout( closeTimer );
+
+                closeTimer = null;
+            }
+        }
+
         // Set show and hide drop down events on top menu
-
-        $( "#menuLink1" ).hover( function()
-            {
-                showDropDown( "menuDropDown1" );
-            },
-            function()
-            {
-                hideDropDownTimeout();
-            } );
-
-        $( "#menuLink2" ).hover( function()
-            {
-                showDropDown( "menuDropDown2" );
-            },
-            function()
-            {
-                hideDropDownTimeout();
-            } );
-
-        $( "#menuLink3" ).hover( function()
-            {
-                showDropDown( "menuDropDown3" );
-            },
-            function()
-            {
-                hideDropDownTimeout();
-            } );
-
-        $( "#menuDropDown1, #menuDropDown2, #menuDropDown3" ).hover( function()
-            {
-                cancelHideDropDownTimeout();
-            },
-            function()
-            {
-                hideDropDownTimeout();
-            } );
+        $( "#appsMenuLink" ).hover(function() {
+            showDropDown( "appsDropDown" );
+        }, function() {
+            hideDropDownTimeout();
+        });
+
+        $( "#profileMenuLink" ).hover(function() {
+            showDropDown( "profileDropDown" );
+        }, function() {
+            hideDropDownTimeout();
+        });
+
+        $( "#appsDropDown, #profileDropDown" ).hover(function() {
+            cancelHideDropDownTimeout();
+        }, function() {
+            hideDropDownTimeout();
+        });
 
 
         $('.drop-down-menu-link').get().forEach(function (element, index, elements) {

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js	2014-04-03 15:58:51 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js	2014-04-04 21:13:39 +0000
@@ -41,64 +41,6 @@
 }
 
 // -----------------------------------------------------------------------------
-// Menu functions
-// -----------------------------------------------------------------------------
-
-var menuTimeout = 500;
-var closeTimer = null;
-var dropDownId = null;
-
-function showDropDown( id )
-{
-    var newDropDownId = "#" + id,
-        position = $(newDropDownId + '_button').position();
-
-    cancelHideDropDownTimeout();
-
-    $(newDropDownId).css('position', 'absolute');
-    $(newDropDownId).css('top', '55px');
-    $(newDropDownId).css('left', Math.ceil(position.left - Math.ceil(parseInt($(newDropDownId).innerWidth(), 10) - 108)) + 'px');
-
-
-    if ( dropDownId != newDropDownId )
-    {   
-        hideDropDown();
-
-        dropDownId = newDropDownId;
-        
-        $( dropDownId ).show();
-    }
-}
-
-function hideDropDown()
-{
-	if ( dropDownId )
-	{
-        if ($( dropDownId ).attr( 'data-clicked-open' ) === 'true') {
-            return;
-        }
-	    $( dropDownId ).hide();
-	    
-	    dropDownId = null;
-	}
-}
-
-function hideDropDownTimeout()
-{
-    closeTimer = window.setTimeout( "hideDropDown()", menuTimeout );
-}
-
-function cancelHideDropDownTimeout()
-{
-    if ( closeTimer )
-    {
-        window.clearTimeout( closeTimer );
-        
-        closeTimer = null;
-    }
-}
-
-// -----------------------------------------------------------------------------
 // Leftbar
 // -----------------------------------------------------------------------------
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2014-04-02 17:19:53 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2014-04-04 21:13:39 +0000
@@ -87,19 +87,19 @@
       </span>
       
       <ul id="menuLinkArea">
-        <li id="menuDropDown3_button">
-            <a id="menuLink3" class="menu-link drop-down-menu-link">
+        <li id="profileDropDown_button">
+            <a id="profileMenuLink" class="menu-link drop-down-menu-link">
               <i class="fa fa-user"></i>$i18n.getString( "profile" )
           </a>
         </li>
-        <li id="menuDropDown1_button">
-          <a id="menuLink1" class="menu-link drop-down-menu-link">
+        <li id="appsDropDown_button">
+          <a id="appsMenuLink" class="menu-link drop-down-menu-link">
             <i class="fa fa-th"></i>$i18n.getString( "applications" )
           </a>
           </li>
       </ul>
 
-      <div id="menuDropDown1" class="menuDropDownArea app-menu-dropdown menuLink1_menu" >
+      <div id="appsDropDown" class="menuDropDownArea app-menu-dropdown appsMenuLink_menu" >
         <div class="caret-up-border"></div>
         <div class="caret-up-background"></div>
         <div class="menu-drop-down-wrap">
@@ -110,7 +110,7 @@
         <div class="apps-menu-more"><a href="../dhis-web-commons-about/modules.action">$i18n.getString( "more_applications" )</a></div>
       </div>
 
-	  <div id="menuDropDown3" class="menuDropDownArea app-menu-dropdown ui-helper-clearfix menuLink3_menu">
+	  <div id="profileDropDown" class="menuDropDownArea app-menu-dropdown ui-helper-clearfix profileMenuLink_menu">
         <div class="caret-up-border"></div>
         <div class="caret-up-background"></div>
         <ul class="menuDropDownBox">