1/** 2 * Calendar Utilities 3 * 4 * Provides calendar-specific functionality for event synchronization. 5 * Depends on DeviceUtils for device detection. 6 * 7 * @requires DeviceUtils 8 * @version 1.0 9 */ 10 11(function(window) { 12 'use strict'; 13 14 // Ensure DeviceUtils is loaded 15 if (typeof window.DeviceUtils === 'undefined') { 16 console.error('CalendarUtils requires DeviceUtils to be loaded first!'); 17 return; 18 } 19 20 /** 21 * Determines the appropriate calendar type for the current browser/device 22 * This matches the server-side logic in Calendar.php addToMyCalendar() 23 * 24 * Returns: 25 * - 'inline' for Apple devices (opens directly in Calendar app) 26 * - 'attachment' for Android, Outlook, Windows (downloads then opens) 27 * - 'attachment' as default 28 * 29 * @returns {string} 'inline' or 'attachment' 30 */ 31 function getCalendarType() { 32 if (DeviceUtils.isDeviceApple()) { 33 return 'inline'; 34 } 35 if (DeviceUtils.isOutlook()) { 36 return 'attachment'; 37 } 38 if (DeviceUtils.isDeviceAndroid()) { 39 return 'attachment'; 40 } 41 if (DeviceUtils.isWindows()) { 42 return 'attachment'; 43 } 44 return 'attachment'; // safe default 45 } 46 47 /** 48 * Legacy function: Returns 'android' or 'undefined' 49 * Kept for backward compatibility with existing code 50 * @returns {string} 'android' or 'undefined' 51 * @deprecated Use getCalendarType() instead 52 */ 53 function getCalendarTypeLegacy() { 54 return DeviceUtils.isDeviceAndroid() ? 'android' : 'undefined'; 55 } 56 57 /** 58 * Builds a calendar URL with the appropriate cal_type parameter 59 * @param {string} baseUrl - The base URL without cal_type 60 * @param {string|null} calType - Optional cal_type override. If not provided, will auto-detect 61 * @returns {string} Complete URL with cal_type parameter 62 */ 63 function buildCalendarUrl(baseUrl, calType) { 64 calType = calType || getCalendarType(); 65 var separator = baseUrl.indexOf('?') !== -1 ? '&' : '?'; 66 return baseUrl + separator + 'cal_type=' + encodeURIComponent(calType); 67 } 68 69 /** 70 * Opens a calendar URL in a new window with auto-detected calendar type 71 * @param {string} baseUrl - The base URL without cal_type 72 * @param {string|null} calType - Optional cal_type override 73 * @param {boolean} useWebcal - Whether to use webcals:// protocol (default: false) 74 */ 75 function openCalendarUrl(baseUrl, calType, useWebcal) { 76 calType = calType || getCalendarType(); 77 var url = buildCalendarUrl(baseUrl, calType); 78 79 if (useWebcal) { 80 url = url.replace(/^https?:\/\//, 'webcals://'); 81 } 82 83 window.open(url, '_blank'); 84 } 85 86 // Expose functions to global scope 87 window.CalendarUtils = { 88 // Delegate device detection to DeviceUtils for backward compatibility 89 isDeviceAndroid: DeviceUtils.isDeviceAndroid, 90 isDeviceApple: DeviceUtils.isDeviceApple, 91 isOutlook: DeviceUtils.isOutlook, 92 isWindows: DeviceUtils.isWindows, 93 isMobile: DeviceUtils.isMobile, 94 isTablet: DeviceUtils.isTablet, 95 // Calendar-specific functions 96 getCalendarType: getCalendarType, 97 getCalendarTypeLegacy: getCalendarTypeLegacy, 98 buildCalendarUrl: buildCalendarUrl, 99 openCalendarUrl: openCalendarUrl 100 }; 101 102 // Log successful load for debugging 103 console.log('CalendarUtils loaded successfully'); 104 105})(window); 106
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.