Use Horde methods to output CSS/JS on new mobile pages to take advantage of caching...
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 22 Nov 2010 09:03:42 +0000 (02:03 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 22 Nov 2010 18:35:55 +0000 (11:35 -0700)
framework/Core/lib/Horde.php
framework/Core/lib/Horde/Script/Files.php
horde/templates/common-header-mobile.inc
imp/mobile.php
imp/templates/mobile/head.html.php
kronolith/mobile.php
kronolith/templates/mobile/head.html.php

index 111e504..884b933 100644 (file)
@@ -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
index 311c97d..e9c3268 100644 (file)
 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;
index 77cef30..592738f 100644 (file)
@@ -1,17 +1,40 @@
 <?php
+
 header('Content-type: text/html; charset=UTF-8');
 header('Vary: Accept-Language');
+
 ?>
 <!DOCTYPE html>
 <html>
 <head>
   <title><?php echo htmlspecialchars(Horde_Util::nonInputVar('title')) ?></title>
-  <link type="text/css" rel="stylesheet" href="<?php echo $GLOBALS['registry']->get('jsuri', 'horde') ?>/jquery.mobile/jquery.mobile.min.css" />
-  <script type="text/javascript" src="<?php echo $GLOBALS['registry']->get('jsuri', 'horde') ?>/jquery.mobile/jquery.min.js"></script>
-  <script type="text/javascript">
-  $(window.document).bind('mobileinit', function() {
-      $.mobile.page.prototype.options.backBtnText = '<?php echo _("Back") ?>';
-      $.mobile.loadingMessage = '<?php echo _("loading") ?>';
-  });
-  </script>
-  <script type="text/javascript" src="<?php echo $GLOBALS['registry']->get('jsuri', 'horde') ?>/jquery.mobile/jquery.mobile.min.js"></script>
+<?php
+
+/* CSS Files. */
+$horde_css = $GLOBALS['injector']->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();
index d07de70..2ef6373 100644 (file)
@@ -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');
index 7e21f89..55e5548 100644 (file)
@@ -1,5 +1,2 @@
-  <link type="text/css" rel="stylesheet" href="<?php echo $GLOBALS['registry']->get('themesuri', 'imp') ?>/mobile.css" />
-  <script type="text/javascript" src="<?php echo $GLOBALS['registry']->get('jsuri', 'horde') ?>/horde-jquery.js"></script>
-  <script type="text/javascript" src="<?php echo $GLOBALS['registry']->get('jsuri') ?>/mobile.js"></script>
 </head>
 <body>
index 4032579..811b0de 100644 (file)
@@ -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');
index d20c4ee..55e5548 100644 (file)
@@ -1,7 +1,2 @@
-  <script type="text/javascript" src="<?php echo $this->registry->get('jsuri', 'horde')?>/horde-jquery.js"></script>
-  <script type="text/javascript" src="<?php echo $this->registry->get('jsuri', 'horde') ?>/date/en-US.js"></script>
-  <script type="text/javascript" src="<?php echo $this->registry->get('jsuri', 'horde') ?>/date/date.js"></script>
-  <script type="text/javascript" src="<?php echo $this->registry->get('jsuri', 'kronolith') ?>/mobile.js"></script>
-  <link href="<?php echo $this->registry->get('themesuri');?>/mobile.css" rel="stylesheet" type="text/css" />
 </head>
-<body>
\ No newline at end of file
+<body>