From 52310babe85f8cee7c0f94ced7c4098cbb43a866 Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 27 May 2011 11:45:49 +0200 Subject: [PATCH] allow for vertical scrolling of calendar (pan and zoom) --- source/Ox.UI/js/Calendar/Ox.Calendar.js | 37 ++++++++++++++++++------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/source/Ox.UI/js/Calendar/Ox.Calendar.js b/source/Ox.UI/js/Calendar/Ox.Calendar.js index c54a8c00..4302a2cd 100644 --- a/source/Ox.UI/js/Calendar/Ox.Calendar.js +++ b/source/Ox.UI/js/Calendar/Ox.Calendar.js @@ -73,6 +73,12 @@ Ox.Calendar = function(options, self) { key_shift_0: function() { zoomToSelected(); }, + key_shift_down: function() { + scrollTo(1000000, true); + }, + key_shift_up: function() { + scrollTo(0, true); + }, key_up: function() { scrollBy(-1); } @@ -639,6 +645,14 @@ Ox.Calendar = function(options, self) { return event; } + function getSelectedEventElement() { + var $element = null; + if (self.options.selected !== '') { + $element = getEventElementById(self.options.selected); + } + return $element; + } + function getBackgroundElements(zoom) { // fixme: duplicated var $elements = [], @@ -760,7 +774,7 @@ Ox.Calendar = function(options, self) { panTo(new Date(+self.options.date + ms)); } - function panTo(date) { + function panTo(date, line) { var delta = (date - self.options.date) / 1000 * getPixelsPerSecond(), // 250 ms for half the width of the visible area ms = 250 * Math.min(Math.abs(delta) / (self.$content.width() / 2), 1); @@ -779,11 +793,15 @@ Ox.Calendar = function(options, self) { self.$scrollbar.animate({ marginLeft: -delta / getScrollbarFactor() + 'px' }, ms); + if (!Ox.isUndefined(line)) { + scrollTo(line * 16 + 8 - self.$container.height() / 2, true); + } }; function panToSelected() { if (self.options.selected !== '') { - panTo(getEventCenter(getSelectedEvent())); + var line = getSelectedEventElement().data('line'); + panTo(getEventCenter(getSelectedEvent()), line); } } @@ -864,8 +882,11 @@ Ox.Calendar = function(options, self) { // sort events by start, ascending return a.startTime - b.startTime; }).forEach(function(event) { - overlaps(event, calendarEvent) && - getEventElement(event).appendTo($line); + if (overlaps(event, calendarEvent)) { + getEventElement(event) + .data({line: line}) + .appendTo($line); + } }); }); } @@ -977,12 +998,8 @@ Ox.Calendar = function(options, self) { var event = getSelectedEvent(), eventDuration = getEventDuration(event), zoom = getZoom(); - if (zoom == self.options.zoom) { - panToSelected(); - } else { - self.options.date = getEventCenter(event); - zoomTo(zoom); - } + zoom != self.options.zoom && zoomTo(zoom); + panToSelected(); } function getZoom() { var zoom;