main.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var FC = $.fullCalendar = {
  2. version: "<%= version %>",
  3. // When introducing internal API incompatibilities (where fullcalendar plugins would break),
  4. // the minor version of the calendar should be upped (ex: 2.7.2 -> 2.8.0)
  5. // and the below integer should be incremented.
  6. internalApiVersion: 9
  7. };
  8. var fcViews = FC.views = {};
  9. $.fn.fullCalendar = function(options) {
  10. var args = Array.prototype.slice.call(arguments, 1); // for a possible method call
  11. var res = this; // what this function will return (this jQuery object by default)
  12. this.each(function(i, _element) { // loop each DOM element involved
  13. var element = $(_element);
  14. var calendar = element.data('fullCalendar'); // get the existing calendar object (if any)
  15. var singleRes; // the returned value of this single method call
  16. // a method call
  17. if (typeof options === 'string') {
  18. if (options === 'getCalendar') {
  19. if (!i) { // first element only
  20. res = calendar;
  21. }
  22. }
  23. else if (options === 'destroy') { // don't warn if no calendar object
  24. if (calendar) {
  25. calendar.destroy();
  26. element.removeData('fullCalendar');
  27. }
  28. }
  29. else if (!calendar) {
  30. FC.warn("Attempting to call a FullCalendar method on an element with no calendar.");
  31. }
  32. else if ($.isFunction(calendar[options])) {
  33. singleRes = calendar[options].apply(calendar, args);
  34. if (!i) {
  35. res = singleRes; // record the first method call result
  36. }
  37. if (options === 'destroy') { // for the destroy method, must remove Calendar object data
  38. element.removeData('fullCalendar');
  39. }
  40. }
  41. else {
  42. FC.warn("'" + options + "' is an unknown FullCalendar method.");
  43. }
  44. }
  45. // a new calendar initialization
  46. else if (!calendar) { // don't initialize twice
  47. calendar = new Calendar(element, options);
  48. element.data('fullCalendar', calendar);
  49. calendar.render();
  50. }
  51. });
  52. return res;
  53. };
  54. var complexOptions = [ // names of options that are objects whose properties should be combined
  55. 'header',
  56. 'footer',
  57. 'buttonText',
  58. 'buttonIcons',
  59. 'themeButtonIcons'
  60. ];
  61. // Merges an array of option objects into a single object
  62. function mergeOptions(optionObjs) {
  63. return mergeProps(optionObjs, complexOptions);
  64. }