From cc839556cbd8d82f27cff2657e801fe341382eaa Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 22 Nov 2010 02:03:42 -0700 Subject: [PATCH] Use Horde methods to output CSS/JS on new mobile pages to take advantage of caching/compression --- framework/Core/lib/Horde.php | 3 ++- framework/Core/lib/Horde/Script/Files.php | 42 ++++++++++++++++++++----------- horde/templates/common-header-mobile.inc | 41 +++++++++++++++++++++++------- imp/mobile.php | 2 ++ imp/templates/mobile/head.html.php | 3 --- kronolith/mobile.php | 6 +++++ kronolith/templates/mobile/head.html.php | 7 +----- 7 files changed, 70 insertions(+), 34 deletions(-) diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 111e50484..884b933ce 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -175,7 +175,8 @@ HTML; * or to the list of script files to include via includeScriptFiles(). * * As long as one script file is added, 'prototype.js' will be - * automatically added. + * automatically added, if the prototypejs property of Horde_Script_Files + * is true (it is true by default). * * @param string $file The full javascript file name. * @param string $app The application name. Defaults to the current diff --git a/framework/Core/lib/Horde/Script/Files.php b/framework/Core/lib/Horde/Script/Files.php index 311c97d6b..e9c3268e2 100644 --- a/framework/Core/lib/Horde/Script/Files.php +++ b/framework/Core/lib/Horde/Script/Files.php @@ -16,11 +16,20 @@ class Horde_Script_Files { /** + * Automatically include prototypejs? + * + * @var boolean + */ + public $prototypejs = true; + + /** * The list of script files to add. * * @var array */ - protected $_files = array(); + protected $_files = array( + 'horde' => array() + ); /** * The list of files we have already included. @@ -69,11 +78,6 @@ class Horde_Script_Files $this->_included[$app][$url] = true; - // Always add prototype.js. - if (!isset($this->_included[$app]['prototype.js'])) { - $this->add('prototype.js', 'horde'); - } - $this->_files[$app][] = array( 'f' => basename($url), 'u' => $url, @@ -101,12 +105,6 @@ class Horde_Script_Files } $this->_included[$app][$file] = true; - // Always add prototype.js. - if (!isset($this->_included[$app]['prototype.js']) && - ($file != 'prototype.js')) { - $this->add('prototype.js', 'horde', $full); - } - // Add localized string for popup.js if (($file == 'popup.js') && ($app == 'horde')) { Horde::addInlineJsVars(array( @@ -167,9 +165,23 @@ class Horde_Script_Files return array(); } - /* Add accesskeys.js if access keys are enabled. */ - if ($GLOBALS['prefs']->getValue('widget_accesskey')) { - $this->_add('accesskeys.js', 'horde', false); + /* Add prototype.js? */ + if ($this->prototypejs) { + if (!isset($this->_included['horde']['prototype.js'])) { + $old = $this->_files['horde']; + $this->_files['horde'] = array(); + $this->_add('prototype.js', 'horde', false); + $this->_files['horde'] = array_merge($this->_files['horde'], $old); + } + + /* Add accesskeys.js if access keys are enabled. */ + if ($GLOBALS['prefs']->getValue('widget_accesskey')) { + $this->_add('accesskeys.js', 'horde', false); + } + } elseif (empty($this->_files['horde'])) { + /* Remove horde entry if nothing in it (was added on creation to + * ensure that it gets loaded first. */ + unset($this->_files['horde']); } return $this->_files; diff --git a/horde/templates/common-header-mobile.inc b/horde/templates/common-header-mobile.inc index 77cef30d2..592738fac 100644 --- a/horde/templates/common-header-mobile.inc +++ b/horde/templates/common-header-mobile.inc @@ -1,17 +1,40 @@ <?php echo htmlspecialchars(Horde_Util::nonInputVar('title')) ?> - - - - +getInstance('Horde_Themes_Css'); +$horde_css->addStylesheet( + $GLOBALS['registry']->get('jsfs', 'horde') . '/jquery.mobile/jquery.mobile.min.css', + $GLOBALS['registry']->get('jsuri', 'horde') . '/jquery.mobile/jquery.mobile.min.css' +); +$horde_css->addThemeStylesheet('mobile.css'); +Horde::includeStylesheetFiles(array( + 'nobase' => true +)); + +/* JS Files. */ +$GLOBALS['injector']->getInstance('Horde_Script_Files')->prototypejs = false; +Horde::addScriptFile(array( + array('jquery.mobile/jquery.min.js', 'horde'), + array('jquery.mobile/jquery.mobile.min.js', 'horde'), + array('horde-jquery.js', 'horde') +)); +Horde::includeScriptFiles(); + +/* Inline script. */ +Horde::addInlineScript( + '$(window.document).bind("mobileinit", function() { + $.mobile.page.prototype.options.backBtnText = "' . _("Back") .'"; + $.mobile.loadingMessage = "' . _("loading") . '"; + });' +); +Horde::outputInlineScript(); diff --git a/imp/mobile.php b/imp/mobile.php index d07de7062..2ef63732c 100644 --- a/imp/mobile.php +++ b/imp/mobile.php @@ -38,6 +38,8 @@ $view->portal = Horde::getServiceLink('portal', 'horde')->setRaw(false); $view->logout = Horde::getServiceLink('logout')->setRaw(false); $title = _("Mobile Mail"); +Horde::addScriptFile('mobile.js', 'imp'); + require $registry->get('templates', 'horde') . '/common-header-mobile.inc'; include IMP_TEMPLATES . '/mobile/javascript_defs.php'; echo $view->render('head.html.php'); diff --git a/imp/templates/mobile/head.html.php b/imp/templates/mobile/head.html.php index 7e21f8961..55e5548d3 100644 --- a/imp/templates/mobile/head.html.php +++ b/imp/templates/mobile/head.html.php @@ -1,5 +1,2 @@ - - - diff --git a/kronolith/mobile.php b/kronolith/mobile.php index 4032579ba..811b0de11 100644 --- a/kronolith/mobile.php +++ b/kronolith/mobile.php @@ -23,6 +23,12 @@ $view->registry = $registry; $view->portal = Horde::getServiceLink('portal', 'horde')->setRaw(false); $view->logout = Horde::getServiceLink('logout')->setRaw(false); +Horde::addScriptFile(array( + array('date/en-US.js', 'horde'), + array('date/date.js', 'horde'), + array('mobile.js', 'kronolith') +)); + require $registry->get('templates', 'horde') . '/common-header-mobile.inc'; require KRONOLITH_TEMPLATES . '/mobile/javascript_defs.php'; echo $view->render('head'); diff --git a/kronolith/templates/mobile/head.html.php b/kronolith/templates/mobile/head.html.php index d20c4eeed..55e5548d3 100644 --- a/kronolith/templates/mobile/head.html.php +++ b/kronolith/templates/mobile/head.html.php @@ -1,7 +1,2 @@ - - - - - - \ No newline at end of file + -- 2.11.0