From: Michael J. Rubinsky Date: Mon, 6 Dec 2010 20:00:44 +0000 (-0500) Subject: Properly bind these events. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=94d569b8b73d3b1e37f73084e8b3817ccfb55be1;p=horde.git Properly bind these events. Certain events need to be bound _before_ jquery mobile initializes (mobileinit, page*, etc...) otherwise, the event handlers won't run on first pageload. This means that we can't always use the global common-header-mobile template for all apps. --- diff --git a/kronolith/js/mobile.js b/kronolith/js/mobile.js index 9a1c10790..d68cabab1 100644 --- a/kronolith/js/mobile.js +++ b/kronolith/js/mobile.js @@ -733,53 +733,18 @@ }); }); - // Day View + // Bind click events $('.kronolithDayHeader .kronolithPrevDay').bind('click', KronolithMobile.showPrevDay); $('.kronolithDayHeader .kronolithNextDay').bind('click', KronolithMobile.showNextDay); - $('#dayview').bind('pageshow', function(event, ui) { - KronolithMobile.view = 'day'; - }); - - // Event view - $('#eventview').bind('pageshow', function(event, ui) { - KronolithMobile.view = 'event'; - }); - // Set up the month view $('#kronolithMinicalPrev').bind('click', KronolithMobile.showPrevMonth); $('#kronolithMinicalNext').bind('click', KronolithMobile.showNextMonth); - $('#monthview').bind('pageshow', 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); - } - }); - - // Set up overview - $('#overview').bind('pageshow', function(event, ui) { - KronolithMobile.view = 'overview'; - if (!KronolithMobile.haveOverview) { - KronolithMobile.loadEvents(KronolithMobile.date, KronolithMobile.date.clone().addDays(7), 'overview'); - KronolithMobile.haveOverview = true; - } - }); + $('body').bind('swipeleft', KronolithMobile.handleSwipe); + $('body').bind('swiperight', KronolithMobile.handleSwipe); $('td').live('click', function(e) { KronolithMobile.selectMonthDay($(this).data('date')); }); - - // Load today's events. - // @TODO once https://github.com/jquery/jquery-mobile/issues/issue/508 - // is fixed, move this to #dayview's pageshow event, as well as - // fix monthview initialization. - KronolithMobile.date = new Date(); - $('.kronolithDayDate').html(KronolithMobile.date.toString('ddd') + ' ' + KronolithMobile.date.toString('d')); - KronolithMobile.loadEvents(KronolithMobile.date, KronolithMobile.date, 'day'); - - $('body').bind('swipeleft', KronolithMobile.handleSwipe); - $('body').bind('swiperight', KronolithMobile.handleSwipe); } }; $(KronolithMobile.onDocumentReady); diff --git a/kronolith/mobile.php b/kronolith/mobile.php index 87fef3095..cd41b7903 100644 --- a/kronolith/mobile.php +++ b/kronolith/mobile.php @@ -28,14 +28,7 @@ if (!file_exists($GLOBALS['registry']->get('jsfs', 'horde') . '/date/' . $datejs $datejs = 'en-US.js'; } -require $registry->get('templates', 'horde') . '/common-header-mobile.inc'; - -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'; +require $registry->get('templates', 'kronolith') . '/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 new file mode 100644 index 000000000..248de8497 --- /dev/null +++ b/kronolith/templates/common-header-mobile.inc @@ -0,0 +1,75 @@ + + + + + <?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();