1String.prototype.toSlug = function () { 2 var str = this; 3 str = str.replace(/^\s+|\s+$/g, ""); // trim 4 str = str.toLowerCase(); 5 6 // remove accents, swap ñ for n, etc 7 var from = "à áäâèéëêìÃïîòóöôùúüûñçÄÅ¡ÄÅžýúůÄťŷ/_,:;"; 8 var to = "aaaaeeeeiiiioooouuuuncescrzyuudtn------"; 9 10 for (var i = 0, l = from.length; i < l; i++) { 11 str = str.replace(new RegExp(from.charAt(i), "g"), to.charAt(i)); 12 } 13 14 str = str 15 .replace(".", "-") // replace a dot by a dash 16 .replace(/[^a-z0-9 -]/g, "") // remove invalid chars 17 .replace(/\s+/g, "-") // collapse whitespace and replace by a dash 18 .replace(/-+/g, "-") // collapse dashes 19 .replace(/\//g, ""); // collapse all forward-slashes 20 21 return str; 22}; 23 24/* 25Usage: 26 27<div title="Add to Calendar" class="addeventatc"> 28 Add to Calendar 29 <span class="start">02/19/2024 08:00 AM</span> 30 <span class="end">02/19/2024 10:00 AM</span> 31 <span class="timezone">America/Los_Angeles</span> 32 <span class="title">Summary of the event</span> 33 <span class="description">Description of the event</span> 34 <span class="location">Location of the event</span> 35 <div class="calendar-links"> 36 <button class="add-to-calendar" data-service="google">Google</button> 37 <button class="add-to-calendar" data-service="apple">Apple</button> 38 <button class="add-to-calendar" data-service="office365">Office 365</button> 39 <button class="add-to-calendar" data-service="outlook">Outlook</button> 40 <button class="add-to-calendar" data-service="yahoo">Yahoo</button> 41 </div> 42 </div> 43 44 */ 45 46jQuery(document).ready(function ($) { 47 if ($(".fuelm-add-to-calendar").length === 0) { 48 return; 49 } 50 51 $(".add-to-calendar-button").click(function () { 52 // slide down .calendar-links 53 console.log("clicked"); 54 $(".calendar-links").slideToggle(); 55 }); 56 57 $(".add-to-calendar").click(function () { 58 let service = $(this).data("service"); 59 let start = $($(".fuelm-add-to-calendar .start")[0]).text(); 60 let end = $($(".fuelm-add-to-calendar .end")[0]).text(); 61 let timezone = $($(".fuelm-add-to-calendar .timezone")[0]).text(); 62 let title = $($(".fuelm-add-to-calendar .title")[0]).text(); 63 let description = $($(".fuelm-add-to-calendar .description")[0]).text(); 64 let location = $($(".fuelm-add-to-calendar .location")[0]).text(); 65 66 let url = ""; 67 68 switch (service) { 69 case "google": 70 url = `https://calendar.google.com/calendar/render?action=TEMPLATE&text=${encodeURIComponent( 71 title + " - Boston Arts Academy" 72 )}&dates=${formatDateTime(start, timezone)}/${formatDateTime( 73 end, 74 timezone 75 )}&details=${encodeURIComponent( 76 description 77 )}&location=${encodeURIComponent(location)}&sf=true&output=xml`; 78 break; 79 case "apple": 80 const cal = ics(); 81 cal.addEvent( 82 title + " - Boston Arts Academy", 83 description, 84 location, 85 start, 86 end 87 ); 88 cal.download(title.toSlug()); 89 break; 90 case "office365": 91 url = `https://outlook.office.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent&startdt=${formatDateTime( 92 start, 93 timezone 94 )}&enddt=${formatDateTime(end, timezone)}&subject=${encodeURIComponent( 95 title + " - Boston Arts Academy" 96 )}&body=${encodeURIComponent( 97 description 98 )}&location=${encodeURIComponent(location)}`; 99 break; 100 case "outlook": 101 url = `https://outlook.live.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent&startdt=${formatDateTime( 102 start, 103 timezone 104 )}&enddt=${formatDateTime(end, timezone)}&subject=${encodeURIComponent( 105 title + " - Boston Arts Academy" 106 )}&body=${encodeURIComponent( 107 description 108 )}&location=${encodeURIComponent(location)}`; 109 break; 110 case "yahoo": 111 url = `https://calendar.yahoo.com/?v=60&view=d&type=20&title=${encodeURIComponent( 112 title + " - Boston Arts Academy" 113 )}&st=${formatDateTime(start, timezone)}&et=${formatDateTime( 114 end, 115 timezone 116 )}&desc=${encodeURIComponent(description)}&in_loc=${encodeURIComponent( 117 location 118 )}`; 119 break; 120 } 121 122 if (service !== "apple") { 123 window.open(url, "_blank"); 124 } 125 }); 126 127 function formatDateTime(dateStr, timeZone, isApple = false) { 128 // // dateStr = 02/19/2024 08:00 AM 129 // let convertedDate = new Date(dateStr); 130 // console.log(convertedDate); 131 // let date = new Date(
132 // convertedDate.toLocaleString("en-US", { timeZone: timeZone }) 133 // ); 134 // console.log(date); 135 // let formattedDate = date.toISOString().replace(/-|:|\.\d\d\d/g, ""); 136 // if (isApple) { 137 // return formattedDate; 138 // } 139 // return formattedDate.slice(0, 15) + "Z"; 140 141 const dateParts = dateStr.match( 142 /(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2}) ([APap][Mm])/ 143 ); 144 145 if (!dateParts) { 146 return null; 147 } 148 149 const month = parseInt(dateParts[1], 10) - 1; 150 const day = parseInt(dateParts[2], 10); 151 const year = parseInt(dateParts[3], 10); 152 const hour = 153 dateParts[6].toUpperCase() === "PM" 154 ? parseInt(dateParts[4], 10) + 12 155 : parseInt(dateParts[4], 10); 156 const minute = parseInt(dateParts[5], 10); 157 158 const convertedDate = new Date(Date.UTC(year, month, day, hour, minute)); 159 convertedDate.toLocaleString("en-US", { timeZone }); 160 const formattedDate = convertedDate 161 .toISOString() 162 .replace(/-|:|\.\d\d\d/g, ""); 163 164 if (isApple) { 165 return formattedDate; 166 } 167 168 return formattedDate.slice(0, 15) + "Z"; 169 } 170});
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.