From 199c6722b26352dc6f525b2781afbe06a1b92f1b Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 6 Dec 2010 17:01:23 -0500 Subject: [PATCH] Better way to deal with the requirement for events to be bound before jqm is loaded. 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 | 11 ++-- imp/lib/Application.php | 17 +++++++ imp/mobile.php | 11 ++-- kronolith/lib/Application.php | 56 +++++++++++++++++++++ kronolith/mobile.php | 7 +-- kronolith/templates/common-header-mobile.inc | 75 ---------------------------- 6 files changed, 80 insertions(+), 97 deletions(-) delete mode 100644 kronolith/templates/common-header-mobile.inc diff --git a/horde/templates/common-header-mobile.inc b/horde/templates/common-header-mobile.inc index 5db951290..feb2d8dac 100644 --- a/horde/templates/common-header-mobile.inc +++ b/horde/templates/common-header-mobile.inc @@ -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(); diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 6d4dd7f46..5dd2effc0 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -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") . '"; + });' + ); + } } diff --git a/imp/mobile.php b/imp/mobile.php index a15cf20b7..71a1f6b32 100644 --- a/imp/mobile.php +++ b/imp/mobile.php @@ -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'])) { diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index f881fd086..62b80c36f 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -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; + } + }); + + });' + ); + } + } diff --git a/kronolith/mobile.php b/kronolith/mobile.php index cd41b7903..4e85e5954 100644 --- a/kronolith/mobile.php +++ b/kronolith/mobile.php @@ -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 index 248de8497..000000000 --- a/kronolith/templates/common-header-mobile.inc +++ /dev/null @@ -1,75 +0,0 @@ - - - - - <?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('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(); -- 2.11.0