From 26e4610ff9a5ea1a3e8a1a200b1cb78898c5616f Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Thu, 12 Jun 2014 19:33:37 -0700 Subject: [PATCH] dont modify passed-in eventSource items --- src/EventManager.js | 103 +++++++++++++++------------------ tests/automated/constructor.js | 3 - 2 files changed, 47 insertions(+), 59 deletions(-) diff --git a/src/EventManager.js b/src/EventManager.js index 470750b..14dfb80 100644 --- a/src/EventManager.js +++ b/src/EventManager.js @@ -43,17 +43,15 @@ function EventManager(options) { // assumed to be a calendar var cache = []; - - var _sources = options.eventSources || []; - // TODO: don't mutate eventSources (see issue 954 and automated tests for constructor.js) - - if (options.events) { - _sources.push(options.events); - } - - for (var i=0; i<_sources.length; i++) { - _addEventSource(_sources[i]); - } + $.each( + (options.events ? [ options.events ] : []).concat(options.eventSources || []), + function(i, sourceInput) { + var source = buildEventSource(sourceInput); + if (source) { + sources.push(source); + } + } + ); @@ -219,29 +217,44 @@ function EventManager(options) { // assumed to be a calendar -----------------------------------------------------------------------------*/ - function addEventSource(source) { - source = _addEventSource(source); + function addEventSource(sourceInput) { + var source = buildEventSource(sourceInput); if (source) { pendingSourceCnt++; fetchEventSource(source, currentFetchID); // will eventually call reportEvents } } - - - function _addEventSource(source) { - if ($.isFunction(source) || $.isArray(source)) { - source = { events: source }; + + + function buildEventSource(sourceInput) { // will return undefined if invalid source + var normalizers = fc.sourceNormalizers; + var source; + var i; + + if ($.isFunction(sourceInput) || $.isArray(sourceInput)) { + source = { events: sourceInput }; } - else if (typeof source == 'string') { - source = { url: source }; + else if (typeof sourceInput === 'string') { + source = { url: sourceInput }; } - if (typeof source == 'object') { - normalizeSource(source); - sources.push(source); + else if (typeof sourceInput === 'object') { + source = $.extend({}, sourceInput); // shallow copy + + if (typeof source.className === 'string') { + // TODO: repeat code, same code for event classNames + source.className = source.className.split(/\s+/); + } + } + + if (source) { + for (i=0; i