From c7bbd7c093001709b828a0a3038a1be4e6fee4cd Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sat, 1 Aug 2009 17:03:24 -0600 Subject: [PATCH] Improvements to CSS/JS loading --- imp/index-dimp.php | 8 ++--- imp/js/src/imp.js | 75 ++++++++++++++++++++++------------------- imp/templates/common-header.inc | 8 ++--- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/imp/index-dimp.php b/imp/index-dimp.php index 86e582d6a..defadbc8d 100644 --- a/imp/index-dimp.php +++ b/imp/index-dimp.php @@ -36,11 +36,11 @@ if (is_readable(IMP_BASE . '/config/menu.php')) { /* Add the site specific javascript now. */ if (!empty($site_menu)) { foreach ($site_menu as $key => $menu_item) { - if ($menu_item == 'separator') { - continue; + if ($menu_item != 'separator') { + foreach (array('menu', 'tab') as $val) { + $js_code[] = 'DimpCore.clickObserveHandler({ d: $(\'' . $val . $key . '\'), f: function() { ' . $menu_item['action'] . ' } })'; + } } - $js_code[] = 'DimpCore.clickObserveHandler({ d: $(\'menu' . $key . '\'), f: function() { ' . $menu_item['action'] . ' } })'; - $js_code[] = 'DimpCore.clickObserveHandler({ d: $(\'tab' . $key . '\'), f: function() { ' . $menu_item['action'] . ' } })'; } } diff --git a/imp/js/src/imp.js b/imp/js/src/imp.js index c2dd05eed..81318bed5 100644 --- a/imp/js/src/imp.js +++ b/imp/js/src/imp.js @@ -5,47 +5,52 @@ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. */ -var IMP = window.IMP || {}; - -IMP.menuFolderSubmit = function(clear) -{ - var mf = $('menuform'); - - if ((!this.menufolder_load || clear) && - $F(mf.down('SELECT[name="mailbox"]'))) { - this.menufolder_load = true; - mf.submit(); +document.observe('dom:loaded', function() { + if (!window.IMP) { + window.IMP = {}; } -}; -/** - * Use DOM manipulation to un-block images. - */ -IMP.unblockImages = function(e) -{ - var elt = e.element().up('TABLE.mimeStatusMessage'); - - elt.next('.htmlMessage').select('[blocked]').each(function(e) { - var src = decodeURIComponent(e.readAttribute('blocked')); - if (e.hasAttribute('src')) { - e.writeAttribute('src', src); - } else if (e.hasAttribute('background')) { - e.writeAttribute('background', src); - } else if (e.style.backgroundImage) { - e.setStyle({ backgroundImage: 'url(' + src + ')' }); - } - }); - - Effect.Fade(elt, { duration: 0.6, afterFinish: function() { elt.remove(); } }); + window.IMP.menuFolderSubmit = function(clear) + { + var mf = $('menuform'); - e.stop(); -}; + if ((!this.menufolder_load || clear) && + $F(mf.down('SELECT[name="mailbox"]'))) { + this.menufolder_load = true; + mf.submit(); + } + }; + + /** + * Use DOM manipulation to un-block images. + */ + window.IMP.unblockImages = function(e) + { + var elt = e.element().up('TABLE.mimeStatusMessage'); + + elt.next('.htmlMessage').select('[blocked]').each(function(e) { + var src = decodeURIComponent(e.readAttribute('blocked')); + if (e.hasAttribute('src')) { + e.writeAttribute('src', src); + } else if (e.hasAttribute('background')) { + e.writeAttribute('background', src); + } else if (e.style.backgroundImage) { + e.setStyle({ backgroundImage: 'url(' + src + ')' }); + } + }); + + Effect.Fade(elt, { + afterFinish: function() { elt.remove(); }, + duration: 0.6 + }); + + e.stop(); + }; -document.observe('dom:loaded', function() { // If menu is present, attach event handlers to folder switcher. var tmp = $('openfoldericon'); if (tmp) { - $('menuform').observe('change', IMP.menuFolderSubmit.bind(IMP)); - tmp.down().observe('click', IMP.menuFolderSubmit.bind(IMP, true)); + $('menuform').observe('change', window.IMP.menuFolderSubmit.bind(window.IMP)); + tmp.down().observe('click', window.IMP.menuFolderSubmit.bind(window.IMP, true)); } }); diff --git a/imp/templates/common-header.inc b/imp/templates/common-header.inc index 91d19113f..0145e1fd9 100644 --- a/imp/templates/common-header.inc +++ b/imp/templates/common-header.inc @@ -15,8 +15,6 @@ if (!empty($refresh_time) && !empty($refresh_url)) { $imp_view = Horde_Util::nonInputVar('imp_view'); switch ($imp_view) { case 'dimp': - include IMP_TEMPLATES . '/javascript_defs_dimp.php'; - $css = array(); if (!empty($GLOBALS['conf']['dimp']['css_files'])) { foreach ($GLOBALS['conf']['css_files'] as $css_file) { @@ -26,14 +24,14 @@ case 'dimp': ); } } - Horde::includeStylesheetFiles(array('additional' => $css, 'sub' => 'dimp')); + include IMP_TEMPLATES . '/javascript_defs_dimp.php'; break; default: - include IMP_TEMPLATES . '/javascript_defs.php'; - Horde::includeScriptFiles(); Horde::includeStylesheetFiles(); + Horde::includeScriptFiles(); + include IMP_TEMPLATES . '/javascript_defs.php'; break; } ?> -- 2.11.0