You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*!
  2. * FullCalendar v2.0.0-beta2 Google Calendar Plugin
  3. * Docs & License: http://arshaw.com/fullcalendar/
  4. * (c) 2013 Adam Shaw
  5. */
  6. (function(factory) {
  7. if (typeof define === 'function' && define.amd) {
  8. define([ 'jquery' ], factory);
  9. }
  10. else {
  11. factory(jQuery);
  12. }
  13. })(function($) {
  14. var fc = $.fullCalendar;
  15. var applyAll = fc.applyAll;
  16. fc.sourceNormalizers.push(function(sourceOptions) {
  17. if (sourceOptions.dataType == 'gcal' ||
  18. sourceOptions.dataType === undefined &&
  19. (sourceOptions.url || '').match(/^(http|https):\/\/www.google.com\/calendar\/feeds\//)) {
  20. sourceOptions.dataType = 'gcal';
  21. if (sourceOptions.editable === undefined) {
  22. sourceOptions.editable = false;
  23. }
  24. }
  25. });
  26. fc.sourceFetchers.push(function(sourceOptions, start, end, timezone) {
  27. if (sourceOptions.dataType == 'gcal') {
  28. return transformOptions(sourceOptions, start, end, timezone);
  29. }
  30. });
  31. function transformOptions(sourceOptions, start, end, timezone) {
  32. var success = sourceOptions.success;
  33. var data = $.extend({}, sourceOptions.data || {}, {
  34. singleevents: true,
  35. 'max-results': 9999
  36. });
  37. return $.extend({}, sourceOptions, {
  38. url: sourceOptions.url.replace(/\/basic$/, '/full') + '?alt=json-in-script&callback=?',
  39. dataType: 'jsonp',
  40. data: data,
  41. timezoneParam: 'ctz',
  42. startParam: 'start-min',
  43. endParam: 'start-max',
  44. success: function(data) {
  45. var events = [];
  46. if (data.feed.entry) {
  47. $.each(data.feed.entry, function(i, entry) {
  48. var url;
  49. $.each(entry.link, function(i, link) {
  50. if (link.type == 'text/html') {
  51. url = link.href;
  52. if (timezone && timezone != 'local') {
  53. url += (url.indexOf('?') == -1 ? '?' : '&') + 'ctz=' + encodeURIComponent(timezone);
  54. }
  55. }
  56. });
  57. events.push({
  58. id: entry.gCal$uid.value,
  59. title: entry.title.$t,
  60. start: entry.gd$when[0].startTime,
  61. end: entry.gd$when[0].endTime,
  62. url: url,
  63. location: entry.gd$where[0].valueString,
  64. description: entry.content.$t
  65. });
  66. });
  67. }
  68. var args = [events].concat(Array.prototype.slice.call(arguments, 1));
  69. var res = applyAll(success, this, args);
  70. if ($.isArray(res)) {
  71. return res;
  72. }
  73. return events;
  74. }
  75. });
  76. }
  77. // legacy
  78. fc.gcalFeed = function(url, sourceOptions) {
  79. return $.extend({}, sourceOptions, { url: url, dataType: 'gcal' });
  80. };
  81. });