Browse Source

Adding a new actions class in the display lib see #4615

Julio Montoya 13 years ago
parent
commit
3e845907b0
3 changed files with 77 additions and 18 deletions
  1. 19 7
      main/admin/settings.php
  2. 18 0
      main/inc/lib/display.lib.php
  3. 40 11
      main/template/default/layout/head.tpl

+ 19 - 7
main/admin/settings.php

@@ -278,18 +278,30 @@ $action_images['extra']     	= 'wizard.png';
 $action_images['tracking']     	= 'statistics.png';
 $action_images['gradebook2']    = 'gradebook.png';
 
+$action_images['search']        = 'search.png';
+$action_images['stylesheets']   = 'stylesheets.png';
+$action_images['templates']     = 'template.png';
+$action_images['plugins']       = 'plugins.png';
+
 // Grabbing the categories.
 $resultcategories = api_get_settings_categories(array('stylesheets', 'Plugins', 'Templates', 'Search'));
 
-echo "<div class=\"actions\">";
+$action_array = array();
+
+$resultcategories[] = array('category' => 'search');
+$resultcategories[] = array('category' => 'stylesheets');
+$resultcategories[] = array('category' => 'templates');
+$resultcategories[] = array('category' => 'plugins');
 foreach ($resultcategories as $row) {
-    echo "<a href=\"".api_get_self()."?category=".$row['category']."\">".Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category'])),'',ICON_SIZE_MEDIUM)."</a>";
+    $url = array();    
+    $url['url'] = api_get_self()."?category=".$row['category'];
+    $url['content'] = Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category'])),'',ICON_SIZE_MEDIUM);    
+    if (strtolower($row['category']) == strtolower($_GET['category'])) {
+        $url['active'] = true;
+    }
+    $action_array[] = $url;
 }
-echo "<a href=\"".api_get_self()."?category=Search\">".Display::return_icon($action_images['search'], api_ucfirst(get_lang('Search')),'',ICON_SIZE_MEDIUM)."</a>";
-echo "<a href=\"".api_get_self()."?category=stylesheets\">".Display::return_icon($action_images['stylesheets'], api_ucfirst(get_lang('Stylesheets')),'',ICON_SIZE_MEDIUM)."</a>";
-echo "<a href=\"".api_get_self()."?category=Templates\">".Display::return_icon($action_images['templates'], api_ucfirst(get_lang('Templates')),'',ICON_SIZE_MEDIUM)."</a>";
-echo "<a href=\"".api_get_self()."?category=Plugins\">".Display::return_icon($action_images['plugins'], api_ucfirst(get_lang('Plugins')),'',ICON_SIZE_MEDIUM)."</a>";
-echo "</div>";
+echo Display::actions($action_array);
 
 $form_search = new FormValidator('search_settings', 'get', api_get_self() , null, array('class'=>'vertical'));
 $form_search->addElement('text', 'search_field');

+ 18 - 0
main/inc/lib/display.lib.php

@@ -1412,4 +1412,22 @@ class Display {
         }
         return $html;        
     }    
+    
+    function actions($items) {
+        if (!empty($items)) {
+            $html = '<div class="new_actions"><ul class="nav nav-pills">';        
+            foreach ($items as $value) {
+                $class = null;
+                if (isset($value['active']) && $value['active']) {
+                    $class = 'class ="active"';
+                }
+                $html .= "<li $class >"; 
+                $html .= self::url($value['content'], $value['url']);
+                $html .= '</li>'; 
+            }        
+            $html .= '</ul></div>';
+        }
+        return $html;
+        
+    }
 } //end class Display

+ 40 - 11
main/template/default/layout/head.tpl

@@ -77,22 +77,51 @@ function get_url_params(q, attribute) {
 
 $(document).scroll(function() {
     // Top bar scroll effect
-    if($('body').width() > 959) {
-    if ($('.subnav').length) {
-        if (!$('.subnav').attr('data-top')) {
+    if ($('body').width() > 959) {
+        if ($('.subnav').length) {
+            if (!$('.subnav').attr('data-top')) {
+                // If already fixed, then do nothing
+                if ($('.subnav').hasClass('subnav-fixed')) return;
+                // Remember top position
+                var offset = $('.subnav').offset();
+                $('.subnav').attr('data-top', offset.top);
+            }
+
+            if ($('.subnav').attr('data-top') - $('.subnav').outerHeight() <= $(this).scrollTop()) {
+                $('.subnav').addClass('subnav-fixed');
+            } else {
+                $('.subnav').removeClass('subnav-fixed');
+            }
+        }
+    }
+    
+    
+    if ($('.new_actions').length) {
+        if (!$('.new_actions').attr('data-top')) {
             // If already fixed, then do nothing
-            if ($('.subnav').hasClass('subnav-fixed')) return;
+            if ($('.new_actions').hasClass('new_actions-fixed')) return;
             // Remember top position
-            var offset = $('.subnav').offset()
-            $('.subnav').attr('data-top', offset.top);
+            var offset = $('.new_actions').offset();
+            
+            var more_top = 0;
+            if ($('.subnav').hasClass('new_actions-fixed')) {
+                more_top = 50;
+            }
+            
+            $('.new_actions').attr('data-top', offset.top + more_top);
+            
         }
-
-        if ($('.subnav').attr('data-top') - $('.subnav').outerHeight() <= $(this).scrollTop())
-            $('.subnav').addClass('subnav-fixed');
-        else
-            $('.subnav').removeClass('subnav-fixed');
+        
+        if ($('.new_actions').attr('data-top') - $('.new_actions').outerHeight() <= $(this).scrollTop()) {
+            $('.new_actions').addClass('new_actions-fixed');
+              
+        } else {
+            $('.new_actions').removeClass('new_actions-fixed');
         }
     }
+    
+    
+    
 });
 
 $(document).ready(function() {