Fix for Issue #35 - from origin

This commit is contained in:
Sean Kenny
2014-09-30 19:13:44 +01:00
parent 7f478eb1b2
commit ab6c26145f
7 changed files with 136 additions and 7 deletions
+7 -1
View File
@@ -1526,6 +1526,7 @@ function EventManager(options) { // assumed to be a calendar
// for array sources, we convert to standard Event Objects up front
if ($.isArray(source.events)) {
source.origArray = source.events; // for removeEventSource
source.events = $.map(source.events, function(eventInput) {
return buildEvent(eventInput, source);
});
@@ -1558,7 +1559,12 @@ function EventManager(options) { // assumed to be a calendar
function getSourcePrimitive(source) {
return ((typeof source == 'object') ? (source.events || source.url) : '') || source;
return (
(typeof source === 'object') ? // a normalized event source?
(source.origArray || source.url || source.events) : // get the primitive
null
) ||
source; // the given argument *is* the primitive
}
File diff suppressed because one or more lines are too long
BIN
View File
Binary file not shown.
+7 -1
View File
@@ -1526,6 +1526,7 @@ function EventManager(options) { // assumed to be a calendar
// for array sources, we convert to standard Event Objects up front
if ($.isArray(source.events)) {
source.origArray = source.events; // for removeEventSource
source.events = $.map(source.events, function(eventInput) {
return buildEvent(eventInput, source);
});
@@ -1558,7 +1559,12 @@ function EventManager(options) { // assumed to be a calendar
function getSourcePrimitive(source) {
return ((typeof source == 'object') ? (source.events || source.url) : '') || source;
return (
(typeof source === 'object') ? // a normalized event source?
(source.origArray || source.url || source.events) : // get the primitive
null
) ||
source; // the given argument *is* the primitive
}
+2 -2
View File
File diff suppressed because one or more lines are too long
+7 -1
View File
@@ -261,6 +261,7 @@ function EventManager(options) { // assumed to be a calendar
// for array sources, we convert to standard Event Objects up front
if ($.isArray(source.events)) {
source.origArray = source.events; // for removeEventSource
source.events = $.map(source.events, function(eventInput) {
return buildEvent(eventInput, source);
});
@@ -293,7 +294,12 @@ function EventManager(options) { // assumed to be a calendar
function getSourcePrimitive(source) {
return ((typeof source == 'object') ? (source.events || source.url) : '') || source;
return (
(typeof source === 'object') ? // a normalized event source?
(source.origArray || source.url || source.events) : // get the primitive
null
) ||
source; // the given argument *is* the primitive
}
+111
View File
@@ -0,0 +1,111 @@
describe('removeEventSource', function() {
var options;
beforeEach(function() {
affix('#cal');
options = {
defaultDate: '2014-08-01'
};
$.mockjax({
url: '*',
contentType: 'text/json',
responseText: buildEventArray()
});
$.mockjaxSettings.log = function() { }; // don't console.log
});
afterEach(function() {
$.mockjaxClear();
});
describe('with a URL', function() {
testInput('/myscript.php'); // will go to mockjax
});
describe('with an array', function() {
testInput(buildEventArray());
});
describe('with a function', function() {
testInput(function(start, end, timezone, callback) {
callback(buildEventArray());
});
});
describe('with an object+url', function() {
testInput({
url: '/myscript.php' // will go to mockjax
});
});
describe('with an object+array', function() {
testInput({
events: buildEventArray()
});
});
describe('with an object+function', function() {
testInput({
events: function(start, end, timezone, callback) {
callback(buildEventArray());
}
});
});
function testInput(eventInput) {
it('correctly removes events provided via `events` at initialization', function(done) {
var callCnt = 0;
options.eventAfterAllRender = function() {
if (!(callCnt++)) { // only the first time
expectEventCnt(2);
$('#cal').fullCalendar('removeEventSource', eventInput);
expectEventCnt(0);
done();
}
};
options.events = eventInput;
$('#cal').fullCalendar(options);
});
it('correctly removes events provided via `eventSources` at initialization', function(done) {
var callCnt = 0;
options.eventAfterAllRender = function() {
if (!(callCnt++)) { // only the first time
expectEventCnt(2);
$('#cal').fullCalendar('removeEventSource', eventInput);
expectEventCnt(0);
done();
}
};
options.eventSources = [ eventInput ];
$('#cal').fullCalendar(options);
});
it('correctly removes events provided via `addEventSource` method', function(done) {
var callCnt = 0;
options.eventAfterAllRender = function() {
if ((callCnt++) === 1) { // the second time (the first time is upon initial render)
expectEventCnt(2);
$('#cal').fullCalendar('removeEventSource', eventInput);
expectEventCnt(0);
done();
}
};
$('#cal').fullCalendar(options);
$('#cal').fullCalendar('addEventSource', eventInput);
});
}
function buildEventArray() {
return [
{ title: 'event1', start: '2014-08-01' },
{ title: 'event2', start: '2014-08-02' }
];
}
function expectEventCnt(cnt) {
expect($('.fc-event').length).toBe(cnt);
expect($('#cal').fullCalendar('clientEvents').length).toBe(cnt);
}
});