From: Michael M Slusarz Date: Wed, 28 Jul 2010 17:59:20 +0000 (-0600) Subject: Optimize sidebar loading X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2c1f6677f31a59f0e5cca50e87aa7b6a8dbad387;p=horde.git Optimize sidebar loading --- diff --git a/horde/js/sidebar.js b/horde/js/sidebar.js index 7ce40d817..c55611132 100644 --- a/horde/js/sidebar.js +++ b/horde/js/sidebar.js @@ -9,37 +9,17 @@ var HordeSidebar = { // Variables set in services/sidebar.php: // domain, path, refresh, rtl, tree, url, width - getCookie: function(name, deflt) - { - var cookie = document.cookie.toQueryParams('; '); - if (!cookie) { - cookie = document.cookie.toQueryParams(';'); - } - - return cookie[name] - ? unescape(cookie[name]) - : deflt; - }, - toggleSidebar: function() { var expanded = $('expandedSidebar').visible(), - expires = new Date(), - margin; + expires = new Date(); $('expandedSidebar', 'hiddenSidebar').invoke('toggle'); if ($('themelogo')) { $('themelogo').toggle(); } - margin = expanded - ? $('hiddenSidebar').down().getWidth() - : this.width; - if (this.rtl) { - $('horde_body').setStyle({ marginRight: margin + 'px' }); - } else { - $('horde_body').setStyle({ marginLeft: margin + 'px' }); - } + this.setMargin(!expanded); // Expire in one year. expires.setTime(expires.getTime() + 31536000000); @@ -67,18 +47,34 @@ var HordeSidebar = { this.resizeSidebar(); } - } + }, -}; + setMargin: function(expanded) + { + var margin = expanded + ? this.width + : $('hiddenSidebar').down().getWidth(); -document.observe('dom:loaded', function() { - $('hiddenSidebar').hide(); - if (HordeSidebar.getCookie('horde_sidebar_expanded', 1) != Number($('expandedSidebar').visible())) { - HordeSidebar.toggleSidebar(); - } - if (HordeSidebar.refresh) { - HordeSidebar.updateSidebar.bind(HordeSidebar).delay(HordeSidebar.refresh); + if (this.rtl) { + $('horde_body').setStyle({ marginRight: margin + 'px' }); + } else { + $('horde_body').setStyle({ marginLeft: margin + 'px' }); + } + }, + + onDomLoad: function() + { + if ($('hiddenSidebar').visible()) { + this.setMargin(false); + } + + if (this.refresh) { + this.updateSidebar.bind(this).delay(this.refresh); + } + + $('expandButton', 'hiddenSidebar').invoke('observe', 'click', this.toggleSidebar.bind(this)); } - $('expandButton', 'hiddenSidebar').invoke('observe', 'click', HordeSidebar.toggleSidebar.bind(HordeSidebar)); -}); +}; + +document.observe('dom:loaded', HordeSidebar.onDomLoad.bind(HordeSidebar)); diff --git a/horde/services/sidebar.php b/horde/services/sidebar.php index d9166dcec..8268df805 100644 --- a/horde/services/sidebar.php +++ b/horde/services/sidebar.php @@ -9,11 +9,12 @@ * * @author Michael Pawlowsky * @author Chuck Hagenbuch + * @author Michael Slusarz * @category Horde * @package Horde */ -require_once dirname(__FILE__) . '/../../lib/Application.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('horde', array('authentication' => 'none')); /* We may not be in global scope since this file can be included from other @@ -33,21 +34,36 @@ if (!Horde_Util::getFormData('ajaxui') && $ajax_url->pathInfo = 'sidebarUpdate'; $charset = $registry->getCharset(); + $rtl = intval(isset($registry->nlsconfig['rtl'][$language])); + $show_sidebar = !isset($_COOKIE['horde_sidebar_expanded']) || $_COOKIE['horde_sidebar_expanded']; + $width = intval($prefs->getValue('sidebar_width')); Horde::addInlineScript(array( 'HordeSidebar.domain = ' . Horde_Serialize::serialize($conf['cookie']['domain'], Horde_Serialize::JSON, $charset), 'HordeSidebar.path = ' . Horde_Serialize::serialize($conf['cookie']['path'], Horde_Serialize::JSON, $charset), 'HordeSidebar.refresh = ' . intval($prefs->getValue('menu_refresh_time')), - 'HordeSidebar.rtl = ' . intval(isset($registry->nlsconfig['rtl'][$language])), + 'HordeSidebar.rtl = ' . $rtl, 'HordeSidebar.url = ' . Horde_Serialize::serialize(strval($ajax_url), Horde_Serialize::JSON, $charset), - 'HordeSidebar.width = ' . intval($prefs->getValue('sidebar_width')) + 'HordeSidebar.width = ' . $width )); require $registry->get('templates', 'horde') . '/sidebar/sidebar.inc'; - echo '
'; + if ($show_sidebar) { + $style = $rtl + ? 'margin-right:' . $width . 'px' + : 'margin-left:' . $width . 'px'; + } else { + /* Default to 18px. If local theme changes alter this value, it will + * automatically be determined by javascript at load time. */ + $style = $rtl + ? 'margin-right:18px' + : 'margin-left:18px'; + } + + echo '
'; } else { - echo '
'; + echo '
'; } $GLOBALS['sidebarLoaded'] = true; diff --git a/horde/templates/sidebar/sidebar.inc b/horde/templates/sidebar/sidebar.inc index abdb1d91d..099426862 100644 --- a/horde/templates/sidebar/sidebar.inc +++ b/horde/templates/sidebar/sidebar.inc @@ -1,12 +1,12 @@