From: Michael J. Rubinsky Date: Mon, 6 Dec 2010 23:15:58 +0000 (-0500) Subject: Clean up event binding, use a catch-all click handler. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=13a61fdb13adb6f60baa38d08f590af17e6ea885;p=horde.git Clean up event binding, use a catch-all click handler. --- diff --git a/kronolith/js/mobile.js b/kronolith/js/mobile.js index d68cabab1..963d7ec1b 100644 --- a/kronolith/js/mobile.js +++ b/kronolith/js/mobile.js @@ -553,7 +553,7 @@ } // Insert day cell. - td = $('').attr({'id': 'kronolithMonth' + dateString}).data('date', dateString); + td = $('').attr({ 'id': 'kronolithMonth' + dateString, 'class': 'kronolithMonthDay' }).data('date', dateString); if (day.getMonth() != date.getMonth()) { td.addClass('kronolithMinicalEmpty'); } @@ -719,6 +719,39 @@ } }, + /** + * Catch-all event handler for the click event. + * + * @param object e An event object. + */ + clickHandler: function(e) + { + var elt = $(e.target); + while (elt && elt != window.document && elt.parent().length) { + if (elt.hasClass('kronolithPrevDay')) { + KronolithMobile.showPrevDay(); + return; + } + if (elt.hasClass('kronolithNextDay')) { + KronolithMobile.showNextDay(); + return; + } + if (elt.hasClass('kronolithMinicalNext')) { + KronolithMobile.showNextMonth(); + return; + } + if (elt.hasClass('kronolithMinicalPrev')) { + KronolithMobile.showPrevMonth(); + return; + } + if (elt.hasClass('kronolithMonthDay')) { + KronolithMobile.selectMonthDay(elt.data('date')); + return; + } + elt = elt.parent(); + } + }, + onDocumentReady: function() { // Set up HordeMobile. @@ -733,18 +766,10 @@ }); }); - // Bind click events - $('.kronolithDayHeader .kronolithPrevDay').bind('click', KronolithMobile.showPrevDay); - $('.kronolithDayHeader .kronolithNextDay').bind('click', KronolithMobile.showNextDay); - - $('#kronolithMinicalPrev').bind('click', KronolithMobile.showPrevMonth); - $('#kronolithMinicalNext').bind('click', KronolithMobile.showNextMonth); + // Bind click and swipe events + $(document).click(KronolithMobile.clickHandler); $('body').bind('swipeleft', KronolithMobile.handleSwipe); $('body').bind('swiperight', KronolithMobile.handleSwipe); - - $('td').live('click', function(e) { - KronolithMobile.selectMonthDay($(this).data('date')); - }); } }; $(KronolithMobile.onDocumentReady); diff --git a/kronolith/templates/mobile/month.html.php b/kronolith/templates/mobile/month.html.php index c51fdd84f..f1679b6c9 100644 --- a/kronolith/templates/mobile/month.html.php +++ b/kronolith/templates/mobile/month.html.php @@ -13,9 +13,9 @@
- ">< + ">< today->format('F Y') ?> - ">> + ">>