Better way to deal with the requirement for events to be bound before jqm is loaded.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 6 Dec 2010 22:01:23 +0000 (17:01 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 6 Dec 2010 22:08:08 +0000 (17:08 -0500)
Mobile apps should implement an {app}_Application::mobileInitCallback() method that is
responsible for bringing in any additional javascript files and setting up event bindings
that must be done prior to jqm being initialized. At the minimum, this would include
a mobileinit handler to localize the Back and Loading text.

horde/templates/common-header-mobile.inc
imp/lib/Application.php
imp/mobile.php
kronolith/lib/Application.php
kronolith/mobile.php
kronolith/templates/common-header-mobile.inc [deleted file]

index 5db9512..feb2d8d 100644 (file)
@@ -24,15 +24,10 @@ Horde::includeStylesheetFiles(array(
 /* JS Files. */
 $GLOBALS['injector']->getInstance('Horde_Script_Files')->prototypejs = false;
 Horde::addScriptFile('jquery.mobile/jquery.min.js', 'horde');
+Horde::addScriptFile('horde-jquery.js', 'horde');
+Horde::addScriptFile('mobile.js', 'horde');
 
-/* Inline script. */
-Horde::addInlineScript(
-  '$(window.document).bind("mobileinit", function() {
-      $.mobile.page.prototype.options.backBtnText = "' . _("Back") .'";
-      $.mobile.loadingMessage = "' . _("loading") . '";
-  });'
-);
-Horde::outputInlineScript();
+$GLOBALS['registry']->callAppMethod($GLOBALS['registry']->getApp(), 'mobileInitCallback');
 
 Horde::addScriptFile('jquery.mobile/jquery.mobile.min.js', 'horde');
 Horde::includeScriptFiles();
index 6d4dd7f..5dd2eff 100644 (file)
@@ -685,4 +685,21 @@ class IMP_Application extends Horde_Registry_Application
         $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->init();
     }
 
+    /**
+     * Callback, called from common-template-mobile.inc that sets up the jquery
+     * mobile init hanler.
+     */
+    public function mobileInitCallback()
+    {
+        Horde::addScriptFile('mobile.js');
+        require IMP_TEMPLATES . '/mobile/javascript_defs.php';
+
+        /* Inline script. */
+        Horde::addInlineScript(
+          '$(window.document).bind("mobileinit", function() {
+              $.mobile.page.prototype.options.backBtnText = "' . _("Back") .'";
+              $.mobile.loadingMessage = "' . _("loading") . '";
+           });'
+        );
+    }
 }
index a15cf20..71a1f6b 100644 (file)
@@ -16,6 +16,9 @@
 require_once dirname(__FILE__) . '/lib/Application.php';
 Horde_Registry::appInit('imp', array('impmode' => 'mobile'));
 
+$title = _("Mobile Mail");
+require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
+
 $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/mobile'));
 new Horde_View_Helper_Text($view);
 
@@ -36,14 +39,6 @@ if (empty($conf['user']['allow_folders'])) {
 
 $view->portal = Horde::getServiceLink('portal', 'horde')->setRaw(false);
 $view->logout = Horde::getServiceLink('logout')->setRaw(false);
-$title = _("Mobile Mail");
-
-require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
-
-Horde::addScriptFile('horde-jquery.js', 'horde');
-Horde::addScriptFile('mobile.js', 'horde');
-Horde::addScriptFile('mobile.js', 'imp');
-include IMP_TEMPLATES . '/mobile/javascript_defs.php';
 
 echo $view->render('head.html.php');
 if (!empty($conf['user']['allow_folders'])) {
index f881fd0..62b80c3 100644 (file)
@@ -567,4 +567,60 @@ class Kronolith_Application extends Horde_Registry_Application
         }
     }
 
+    /**
+     * Callback, called from common-template-mobile.inc that sets up the jquery
+     * mobile init hanler.
+     */
+    public function mobileInitCallback()
+    {
+        $datejs = str_replace('_', '-', $GLOBALS['language']) . '.js';
+        if (!file_exists($GLOBALS['registry']->get('jsfs', 'horde') . '/date/' . $datejs)) {
+            $datejs = 'en-US.js';
+        }
+
+        Horde::addScriptFile('date/' . $datejs, 'horde');
+        Horde::addScriptFile('date/date.js', 'horde');
+        Horde::addScriptFile('mobile.js');
+        require KRONOLITH_TEMPLATES . '/mobile/javascript_defs.php';
+
+        /* Inline script. */
+        Horde::addInlineScript(
+          '$(window.document).bind("mobileinit", function() {
+              $.mobile.page.prototype.options.backBtnText = "' . _("Back") .'";
+              $.mobile.loadingMessage = "' . _("loading") . '";
+
+              // Setup event bindings to populate views on pagebeforeshow
+              KronolithMobile.date = new Date();
+              $("#dayview").live("pagebeforeshow", function() {
+                  KronolithMobile.view = "day";
+                  $(".kronolithDayDate").html(KronolithMobile.date.toString("ddd") + " " + KronolithMobile.date.toString("d"));
+                  KronolithMobile.loadEvents(KronolithMobile.date, KronolithMobile.date, "day");
+              });
+
+              $("#monthview").live("pagebeforeshow", function(event, ui) {
+                KronolithMobile.view = "month";
+                // (re)build the minical only if we need to
+                if (!$(".kronolithMinicalDate").data("date") ||
+                    ($(".kronolithMinicalDate").data("date").toString("M") != KronolithMobile.date.toString("M"))) {
+                    KronolithMobile.moveToMonth(KronolithMobile.date);
+                }
+              });
+
+              $("#eventview").live("pageshow", function(event, ui) {
+                    KronolithMobile.view = "event";
+              });
+
+              // Set up overview
+              $("#overview").live("pageshow", function(event, ui) {
+                  KronolithMobile.view = "overview";
+                  if (!KronolithMobile.haveOverview) {
+                      KronolithMobile.loadEvents(KronolithMobile.date, KronolithMobile.date.clone().addDays(7), "overview");
+                      KronolithMobile.haveOverview = true;
+                  }
+              });
+
+           });'
+        );
+    }
+
 }
index cd41b79..4e85e59 100644 (file)
@@ -23,12 +23,7 @@ $view->registry = $registry;
 $view->portal = Horde::getServiceLink('portal', 'horde')->setRaw(false);
 $view->logout = Horde::getServiceLink('logout')->setRaw(false);
 
-$datejs = str_replace('_', '-', $GLOBALS['language']) . '.js';
-if (!file_exists($GLOBALS['registry']->get('jsfs', 'horde') . '/date/' . $datejs)) {
-    $datejs = 'en-US.js';
-}
-
-require $registry->get('templates', 'kronolith') . '/common-header-mobile.inc';
+require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
 
 echo $view->render('head');
 echo $view->render('day');
diff --git a/kronolith/templates/common-header-mobile.inc b/kronolith/templates/common-header-mobile.inc
deleted file mode 100644 (file)
index 248de84..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-<?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>
-<?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('jquery.mobile/jquery.min.js', 'horde');
-Horde::addScriptFile('horde-jquery.js', 'horde');
-Horde::addScriptFile('mobile.js', 'horde');
-Horde::addScriptFile('date/' . $datejs, 'horde');
-Horde::addScriptFile('date/date.js', 'horde');
-Horde::addScriptFile('mobile.js', 'kronolith');
-require KRONOLITH_TEMPLATES . '/mobile/javascript_defs.php';
-
-/* Inline script. */
-Horde::addInlineScript(
-  '$(window.document).bind("mobileinit", function() {
-      $.mobile.page.prototype.options.backBtnText = "' . _("Back") .'";
-      $.mobile.loadingMessage = "' . _("loading") . '";
-
-      // Setup event bindings to populate views on pagebeforeshow
-      KronolithMobile.date = new Date();
-      $("#dayview").live("pagebeforeshow", function() {
-          KronolithMobile.view = "day";
-          $(".kronolithDayDate").html(KronolithMobile.date.toString("ddd") + " " + KronolithMobile.date.toString("d"));
-          KronolithMobile.loadEvents(KronolithMobile.date, KronolithMobile.date, "day");
-      });
-
-      $("#monthview").live("pagebeforeshow", function(event, ui) {
-        KronolithMobile.view = "month";
-        // (re)build the minical only if we need to
-        if (!$(".kronolithMinicalDate").data("date") ||
-            ($(".kronolithMinicalDate").data("date").toString("M") != KronolithMobile.date.toString("M"))) {
-            KronolithMobile.moveToMonth(KronolithMobile.date);
-        }
-      });
-
-      $("#eventview").live("pageshow", function(event, ui) {
-            KronolithMobile.view = "event";
-      });
-
-      // Set up overview
-      $("#overview").live("pageshow", function(event, ui) {
-          KronolithMobile.view = "overview";
-          if (!KronolithMobile.haveOverview) {
-              KronolithMobile.loadEvents(KronolithMobile.date, KronolithMobile.date.clone().addDays(7), "overview");
-              KronolithMobile.haveOverview = true;
-          }
-      });
-
-   });'
-);
-Horde::outputInlineScript();
-
-Horde::addScriptFile('jquery.mobile/jquery.mobile.min.js', 'horde');
-Horde::includeScriptFiles();