mirror of
https://github.com/wassname/fullcalendar.git
synced 2026-06-26 16:00:09 +08:00
Fix for Issue #35 - from origin
This commit is contained in:
Vendored
+7
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
BIN
Binary file not shown.
Vendored
+7
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
+7
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user