seankenny / fullcalendar

Full-sized drag & drop event calendar (jQuery plugin)
http://arshaw.com/fullcalendar/
MIT License
60 stars 39 forks source link

Removes strict comparison #22

Closed zvictor closed 10 years ago

zvictor commented 10 years ago

Currently, the following example would not show any event.

$('#calendar').fullCalendar({
  defaultView: 'resourceDay',
  // Note that we are using Int values to define the ids.
  resources: [{'id':0,'name':'Resource 1'},{'id':1, 'name':'Resource 2'}], 
  events: [
  {
    title: 'R1-R2: Lunch 14.00-15.00',
    start: '2013-08-21T14:00:00.000Z',
    end: '2013-08-21T15:00:00.000Z',
    // Different type for the ids here: String.
    resources: ['0','1'] 
  }
});

This pull request allows the showed example to work by removing the strictness of types when associating resources and events.

zvictor commented 10 years ago

A reference to clarify this issue: jQuery inArray is always returning -1

seankenny commented 10 years ago

Nice catch.

Fails the Grunt lint tests though with http://jslinterrors.com/dont-make-functions-within-a-loop

This might be an alternative?

function eventsForResource(resource, events) {
    var resourceEvents = [];

    var hasResource = function(event) {
        if (!event.resources) {
            return false;
        }
        return $.grep(event.resources, function(id) { return id === resource.id; }).length > 0;
    }

    for (var i = 0; i < events.length; i++) {
      if (hasResource(events[i])) {
        resourceEvents.push(events[i]);
      }
    }
    return resourceEvents;
}
zvictor commented 10 years ago

You are right. I am fixing it right now = )

zvictor commented 10 years ago

Done.