From 00a838f699082d234ece56b1d838667715ba13b4 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 4 Aug 2009 22:47:55 -0600 Subject: [PATCH] Optimize output of CSS/JS --- ingo/blacklist.php | 7 ++----- ingo/filters.php | 2 ++ ingo/forward.php | 1 + ingo/js/filters.js | 19 +++++++++++++++++++ ingo/js/new_folder.js | 26 ++++++++++++++++++++++++++ ingo/js/rule.js | 16 ++++++++++++++++ ingo/lib/Ingo.php | 32 +++++++++++++++++++++++++++++++- ingo/rule.php | 7 +++---- ingo/script.php | 1 + ingo/spam.php | 7 ++----- ingo/templates/common-header.inc | 3 ++- ingo/templates/filters/filter.html | 2 +- ingo/templates/filters/header.inc | 12 ------------ ingo/templates/javascript/new_folder.js | 17 ----------------- ingo/templates/menu.inc | 2 +- ingo/templates/rule/filter.inc | 2 +- ingo/templates/rule/header.inc | 12 ------------ ingo/vacation.php | 1 + ingo/whitelist.php | 1 + 19 files changed, 110 insertions(+), 60 deletions(-) create mode 100644 ingo/js/filters.js create mode 100644 ingo/js/new_folder.js create mode 100644 ingo/js/rule.js delete mode 100644 ingo/templates/javascript/new_folder.js diff --git a/ingo/blacklist.php b/ingo/blacklist.php index f89092535..bf26bebe6 100644 --- a/ingo/blacklist.php +++ b/ingo/blacklist.php @@ -96,11 +96,8 @@ $folder_list = Ingo::flistSelect($blacklist_folder, 'filters', 'actionvalue', $filters = &$ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $bl_rule = $filters->findRule(Ingo_Storage::ACTION_BLACKLIST); -/* Include new folder JS if necessary. */ -if ($registry->hasMethod('mail/createFolder')) { - Horde::addScriptFile('new_folder.js'); -} - +Ingo::prepareMenu(); +Ingo::addNewFolderJs(); $title = _("Blacklist Edit"); require INGO_TEMPLATES . '/common-header.inc'; require INGO_TEMPLATES . '/menu.inc'; diff --git a/ingo/filters.php b/ingo/filters.php index a37c794dc..5ac3aed86 100644 --- a/ingo/filters.php +++ b/ingo/filters.php @@ -141,6 +141,8 @@ $filter_list = $filters->getFilterList(); Horde::addScriptFile('tooltips.js', 'horde', true); Horde::addScriptFile('stripe.js', 'horde', true); +Horde::addScriptFile('filters.js', 'ingo', true); +Ingo::prepareMenu(); $title = _("Filter Rules"); require INGO_TEMPLATES . '/common-header.inc'; require INGO_TEMPLATES . '/menu.inc'; diff --git a/ingo/forward.php b/ingo/forward.php index 30bc6c47d..cc7e270d8 100644 --- a/ingo/forward.php +++ b/ingo/forward.php @@ -98,6 +98,7 @@ $form_title .= ' ' . Horde_Help::link('ingo', 'forward'); $form->setTitle($form_title); $title = _("Forwards Edit"); +Ingo::prepareMenu(); require INGO_TEMPLATES . '/common-header.inc'; require INGO_TEMPLATES . '/menu.inc'; $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false)), $vars, 'forward.php', 'post'); diff --git a/ingo/js/filters.js b/ingo/js/filters.js new file mode 100644 index 000000000..4d947ee16 --- /dev/null +++ b/ingo/js/filters.js @@ -0,0 +1,19 @@ +/** + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + */ + +var IngoFilters = { + + moveFromTo: function(from, to, upurl, downurl) + { + var steps = to - from; + if (steps < 0) { + window.location = upurl + '&steps=' + -steps; + } else if (steps > 0) { + window.location = downurl + '&steps=' + steps; + } + return true; + } + +}; diff --git a/ingo/js/new_folder.js b/ingo/js/new_folder.js new file mode 100644 index 000000000..420e2b89e --- /dev/null +++ b/ingo/js/new_folder.js @@ -0,0 +1,26 @@ +/** + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + */ + +var IngoNewFolder = { + + newFolderName: function(name, tagname) + { + var form = document.getElementsByName(name); + var selector = form[0].elements.namedItem(tagname); + + if (selector.selectedIndex == 1){ + var folder = window.prompt(this.folderprompt . '\n', ''); + + if ((folder != null) && (folder != '')) { + form[0].actionID.value = 'create_folder'; + form[0].new_folder_name.value = folder; + form[0].submit(); + } + } + + return true; + } + +}; diff --git a/ingo/js/rule.js b/ingo/js/rule.js new file mode 100644 index 000000000..7dc089077 --- /dev/null +++ b/ingo/js/rule.js @@ -0,0 +1,16 @@ +/** + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + */ + +var IngoRule = { + + delete_condition: function(num) + { + document.rule.actionID.value = 'rule_delete'; + document.rule.conditionnumber.value = num; + document.rule.submit(); + return true; + } + +}; diff --git a/ingo/lib/Ingo.php b/ingo/lib/Ingo.php index 364bc48a4..7e2e381ce 100644 --- a/ingo/lib/Ingo.php +++ b/ingo/lib/Ingo.php @@ -22,6 +22,9 @@ class Ingo */ const USER_HEADER = '++USER_HEADER++'; + /* getMenu() cache. */ + static private $_menuCache = null; + /** * Generates a folder widget. * If an application is available that provides a folderlist method @@ -53,7 +56,7 @@ class Ingo $text .= $onchange . ';'; } if ($createfolder) { - $text .= 'newFolderName(\'' . $form . '\', \'' . + $text .= 'IngoNewFolder.newFolderName(\'' . $form . '\', \'' . $tagname . '\');'; } $text .= '"'; @@ -413,4 +416,31 @@ class Ingo return $menu; } + /** + * Prepares and caches Ingo's list of menu items. + * + * @return string The menu text. + */ + static public function prepareMenu() + { + if (!self::$_menuCache) { + self::$_menuCache = self::getMenu()->render(); + } + + return self::$_menuCache; + } + + /** + * Add new_folder.js to the list of output javascript files. + */ + static public function addNewFolderJs() + { + if ($GLOBALS['registry']->hasMethod('mail/createFolder')) { + Horde::addScriptFile('new_folder.js', 'ingo', true); + Horde::addInlineScript(array( + 'IngoNewFolder.folderprompt = ' . Horde_Serialize::serialize(_("Please enter the name of the new folder:"), Horde_Serialize::JSON, Horde_Nls::getCharset()) + )); + } + } + } diff --git a/ingo/rule.php b/ingo/rule.php index 9d32fa60d..c5750f7ad 100644 --- a/ingo/rule.php +++ b/ingo/rule.php @@ -189,11 +189,10 @@ if (!$rule) { exit; } -if ($registry->hasMethod('mail/createFolder')) { - Horde::addScriptFile('new_folder.js'); -} - $title = $rule['name']; +Horde::addScriptFile('rule.js', 'ingo', true); +Ingo::prepareMenu(); +Ingo::addNewFolderJs(); require INGO_TEMPLATES . '/common-header.inc'; require INGO_TEMPLATES . '/menu.inc'; require INGO_TEMPLATES . '/rule/header.inc'; diff --git a/ingo/script.php b/ingo/script.php index f96d01557..e3f225481 100644 --- a/ingo/script.php +++ b/ingo/script.php @@ -49,6 +49,7 @@ case 'show_active': } $title = _("Filter Script Display"); +Ingo::prepareMenu(); require INGO_TEMPLATES . '/common-header.inc'; require INGO_TEMPLATES . '/menu.inc'; require INGO_TEMPLATES . '/script/header.inc'; diff --git a/ingo/spam.php b/ingo/spam.php index 28a040c62..c7467e2b3 100644 --- a/ingo/spam.php +++ b/ingo/spam.php @@ -146,11 +146,6 @@ if (!$form->isSubmitted()) { $vars->set('new_folder_name', ''); } -/* Include new folder JS if necessary. */ -if ($registry->hasMethod('mail/createFolder')) { - Horde::addScriptFile('new_folder.js'); -} - /* Set form title. */ $form_title = _("Spam Filtering"); if (!empty($spam_rule['disable'])) { @@ -160,6 +155,8 @@ $form_title .= ' ' . Horde_Help::link('ingo', 'spam'); $form->setTitle($form_title); $title = _("Spam Filtering"); +Ingo::prepareMenu(); +Ingo::addNewFolderJs(); require INGO_TEMPLATES . '/common-header.inc'; require INGO_TEMPLATES . '/menu.inc'; $form->renderActive($renderer, $vars, 'spam.php', 'post'); diff --git a/ingo/templates/common-header.inc b/ingo/templates/common-header.inc index 491d41cfd..9a3ec8ff6 100644 --- a/ingo/templates/common-header.inc +++ b/ingo/templates/common-header.inc @@ -14,10 +14,11 @@ if (!empty($title)) { + <?php echo htmlspecialchars($page_title) ?> - + > diff --git a/ingo/templates/filters/filter.html b/ingo/templates/filters/filter.html index 72b206e03..de9d0f365 100644 --- a/ingo/templates/filters/filter.html +++ b/ingo/templates/filters/filter.html @@ -26,7 +26,7 @@ - + diff --git a/ingo/templates/filters/header.inc b/ingo/templates/filters/header.inc index 55851b36c..52571f078 100644 --- a/ingo/templates/filters/header.inc +++ b/ingo/templates/filters/header.inc @@ -1,15 +1,3 @@ -
diff --git a/ingo/templates/javascript/new_folder.js b/ingo/templates/javascript/new_folder.js deleted file mode 100644 index e2c3cedea..000000000 --- a/ingo/templates/javascript/new_folder.js +++ /dev/null @@ -1,17 +0,0 @@ -function newFolderName(name, tagname) -{ - var form = document.getElementsByName(name); - var selector = form[0].elements.namedItem(tagname); - - if (selector.selectedIndex == 1){ - var folder = window.prompt('\n', ''); - - if ((folder != null) && (folder != '')) { - form[0].actionID.value = 'create_folder'; - form[0].new_folder_name.value = folder; - form[0].submit(); - } - } - - return true; -} diff --git a/ingo/templates/menu.inc b/ingo/templates/menu.inc index 1c1e9cf18..71b6f2bd5 100644 --- a/ingo/templates/menu.inc +++ b/ingo/templates/menu.inc @@ -13,7 +13,7 @@ - render() ?> +
diff --git a/ingo/templates/rule/filter.inc b/ingo/templates/rule/filter.inc index 804d96238..d4ef8bd42 100644 --- a/ingo/templates/rule/filter.inc +++ b/ingo/templates/rule/filter.inc @@ -30,7 +30,7 @@ - getImageDir('horde')) ?> + getImageDir('horde')) ?>   diff --git a/ingo/templates/rule/header.inc b/ingo/templates/rule/header.inc index bac9a58c8..24ce582b8 100644 --- a/ingo/templates/rule/header.inc +++ b/ingo/templates/rule/header.inc @@ -1,15 +1,3 @@ - -
diff --git a/ingo/vacation.php b/ingo/vacation.php index 4c11dfaef..16a203621 100644 --- a/ingo/vacation.php +++ b/ingo/vacation.php @@ -149,6 +149,7 @@ $form_title .= ' ' . Horde_Help::link('ingo', 'vacation'); $form->setTitle($form_title); $title = _("Vacation Edit"); +Ingo::prepareMenu(); require INGO_TEMPLATES . '/common-header.inc'; require INGO_TEMPLATES . '/menu.inc'; $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false)), $vars, 'vacation.php', 'post'); diff --git a/ingo/whitelist.php b/ingo/whitelist.php index 1f9124c20..287da95c3 100644 --- a/ingo/whitelist.php +++ b/ingo/whitelist.php @@ -54,6 +54,7 @@ $filters = &$ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $wl_rule = $filters->findRule(Ingo_Storage::ACTION_WHITELIST); $title = _("Whitelist Edit"); +Ingo::prepareMenu(); require INGO_TEMPLATES . '/common-header.inc'; require INGO_TEMPLATES . '/menu.inc'; require INGO_TEMPLATES . '/whitelist/whitelist.inc'; -- 2.11.0