mirror of
https://github.com/wassname/fullcalendar.git
synced 2026-07-12 00:50:41 +08:00
79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
|
|
var fc = $.fullCalendar = { version: "<%= meta.version %>" };
|
|
var fcViews = fc.views = {};
|
|
|
|
|
|
$.fn.fullCalendar = function(options) {
|
|
var args = Array.prototype.slice.call(arguments, 1); // for a possible method call
|
|
var res = this; // what this function will return (this jQuery object by default)
|
|
|
|
this.each(function(i, _element) { // loop each DOM element involved
|
|
var element = $(_element);
|
|
var calendar = element.data('fullCalendar'); // get the existing calendar object (if any)
|
|
var singleRes; // the returned value of this single method call
|
|
|
|
// a method call
|
|
if (typeof options === 'string') {
|
|
if (calendar && $.isFunction(calendar[options])) {
|
|
singleRes = calendar[options].apply(calendar, args);
|
|
if (!i) {
|
|
res = singleRes; // record the first method call result
|
|
}
|
|
if (options === 'destroy') { // for the destroy method, must remove Calendar object data
|
|
element.removeData('fullCalendar');
|
|
}
|
|
}
|
|
}
|
|
// a new calendar initialization
|
|
else if (!calendar) { // don't initialize twice
|
|
calendar = new Calendar(element, options);
|
|
element.data('fullCalendar', calendar);
|
|
calendar.render();
|
|
}
|
|
});
|
|
|
|
return res;
|
|
};
|
|
|
|
|
|
// function for adding/overriding defaults
|
|
function setDefaults(d) {
|
|
mergeOptions(defaults, d);
|
|
}
|
|
|
|
|
|
// Recursively combines option hash-objects.
|
|
// Better than `$.extend(true, ...)` because arrays are not traversed/copied.
|
|
//
|
|
// called like:
|
|
// mergeOptions(target, obj1, obj2, ...)
|
|
//
|
|
function mergeOptions(target) {
|
|
|
|
function mergeIntoTarget(name, value) {
|
|
if ($.isPlainObject(value) && $.isPlainObject(target[name]) && !isForcedAtomicOption(name)) {
|
|
// merge into a new object to avoid destruction
|
|
target[name] = mergeOptions({}, target[name], value); // combine. `value` object takes precedence
|
|
}
|
|
else if (value !== undefined) { // only use values that are set and not undefined
|
|
target[name] = value;
|
|
}
|
|
}
|
|
|
|
for (var i=1; i<arguments.length; i++) {
|
|
$.each(arguments[i], mergeIntoTarget);
|
|
}
|
|
|
|
return target;
|
|
}
|
|
|
|
|
|
// overcome sucky view-option-hash and option-merging behavior messing with options it shouldn't
|
|
function isForcedAtomicOption(name) {
|
|
// Any option that ends in "Time" or "Duration" is probably a Duration,
|
|
// and these will commonly be specified as plain objects, which we don't want to mess up.
|
|
return /(Time|Duration)$/.test(name);
|
|
}
|
|
// FIX: find a different solution for view-option-hashes and have a whitelist
|
|
// for options that can be recursively merged.
|