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