From 96d03fc3860b9f621f4c55f5c04b29546947c8f5 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Mon, 10 Oct 2011 09:43:07 +0000 Subject: [PATCH] allow for selection of calendar events that are outside the current view --- source/Ox.UI/js/Calendar/Ox.Calendar.js | 31 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/source/Ox.UI/js/Calendar/Ox.Calendar.js b/source/Ox.UI/js/Calendar/Ox.Calendar.js index b1dd7ab1..2c63b77f 100644 --- a/source/Ox.UI/js/Calendar/Ox.Calendar.js +++ b/source/Ox.UI/js/Calendar/Ox.Calendar.js @@ -633,14 +633,23 @@ Ox.Calendar = function(options, self) { return $element; } + function getEventLine(id) { + var line = -1; + Ox.forEach(self.lineEvents, function(events, line_) { + if (Ox.getPositionById(events, id) > -1) { + line = line_; + return false; + } + }); + return line; + } + function getLines() { self.lineEvents = []; self.$content.find('.OxLine').remove(); self.options.events.filter(function(event) { // filter out events with types not shown - // and events outside the visible area <-- commented out to keep layout from changing - return self.options.showTypes.indexOf(event.type) > -1 - /*&& overlaps(event, calendarEvent)*/; + return self.options.showTypes.indexOf(event.type) > -1; }).sort(function(a, b) { // sort events (dates first, people last, longer before shorter) if (a.type == 'date' && b.type != 'date') { @@ -858,16 +867,17 @@ Ox.Calendar = function(options, self) { marginLeft: -delta / getScrollbarFactor() + 'px' }, ms); if (!Ox.isUndefined(line)) { - scrollTo(line * 16 + 8 - self.$container.height() / 2, true); + scrollTo((line + 1) * 16 - self.$container.height() / 2, true); } }; function panToSelected() { // fixme: '0' should zoom to selected if selected is already centered // (both horizontally and vertically, the latter is a bit more work) + var event = getSelectedEvent(); self.options.selected !== '' && panTo( - getEventCenter(getSelectedEvent()), - getSelectedEventElement().data('line') + getEventCenter(event), + getEventLine(event.id) ); } @@ -900,7 +910,7 @@ Ox.Calendar = function(options, self) { event.id == self.options.selected || overlaps(event, calendarEvent) ) { - getEventElement(event).data({line: line}).appendTo(self.$lines[line]); + getEventElement(event).appendTo(self.$lines[line]); } }); }); @@ -978,7 +988,12 @@ Ox.Calendar = function(options, self) { self.$content.find('.OxSelected').removeClass('OxSelected'); if (id) { self.options.selected = id; - ($element || getEventElementById(id)).addClass('OxSelected'); + $element = $element || getEventElementById(id); + if ($element) { + $element.addClass('OxSelected'); + } else { + panToSelected(); + } // fixme: map event should also be 'select', not 'selectplace' that.triggerEvent('select', Ox.getObjectById(self.options.events, id)); } else {