Skip to content

Commit

Permalink
new callback: eventDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Aug 7, 2013
1 parent 3b96f90 commit fb1dbd6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function Calendar(element, options, eventSources) {

if (currentView) {
trigger('viewDestroy', currentView, currentView, currentView.element);
currentView.triggerEventDestroy(); // trigger 'eventDestroy' for each event
freezeContentHeight();
currentView.element.remove();
header.deactivateButton(currentView.name);
Expand Down Expand Up @@ -304,6 +305,7 @@ function Calendar(element, options, eventSources) {


function clearEvents() {
currentView.triggerEventDestroy(); // trigger 'eventDestroy' for each event
currentView.clearEvents(); // actually remove the DOM elements
currentView.clearEventData(); // for View.js, TODO: unify with clearEvents
}
Expand Down
21 changes: 16 additions & 5 deletions src/common/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function View(element, calendar, viewName) {
t.clearEventData = clearEventData;
t.eventEnd = eventEnd;
t.reportEventElement = reportEventElement;
t.triggerEventDestroy = triggerEventDestroy;
t.eventElementHandlers = eventElementHandlers;
t.showEvents = showEvents;
t.hideEvents = hideEvents;
Expand All @@ -33,9 +34,9 @@ function View(element, calendar, viewName) {


// locals
var eventsByID = {};
var eventElements = [];
var eventElementsByID = {};
var eventsByID = {}; // eventID mapped to array of events (there can be multiple b/c of repeating events)
var eventElementsByID = {}; // eventID mapped to array of jQuery elements
var eventElementCouples = []; // array of objects, { event, element } // TODO: unify with segment system
var options = calendar.options;


Expand Down Expand Up @@ -110,8 +111,9 @@ function View(element, calendar, viewName) {


function clearEventData() {
eventElements = [];
eventsByID = {};
eventElementsByID = {};
eventElementCouples = [];
}


Expand All @@ -128,13 +130,20 @@ function View(element, calendar, viewName) {

// report when view creates an element for an event
function reportEventElement(event, element) {
eventElements.push(element);
eventElementCouples.push({ event: event, element: element });
if (eventElementsByID[event._id]) {
eventElementsByID[event._id].push(element);
}else{
eventElementsByID[event._id] = [element];
}
}


function triggerEventDestroy() {
$.each(eventElementCouples, function(i, couple) {
t.trigger('eventDestroy', couple.event, couple.event, couple.element);
});
}


// attaches eventClick, eventMouseover, eventMouseout
Expand Down Expand Up @@ -170,6 +179,8 @@ function View(element, calendar, viewName) {


function eachEventElement(event, exceptElement, funcName) {
// NOTE: there may be multiple events per ID (repeating events)
// and multiple segments per event
var elements = eventElementsByID[event._id],
i, len = elements.length;
for (i=0; i<len; i++) {
Expand Down

0 comments on commit fb1dbd6

Please sign in to comment.