1// events -> 7021 2// occurrences -> 45784 3 4var months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]; 5 6var Events = { 7 eventsFull: null, 8 occurrenceCount: 0, 9 locations: [], 10 types: [], 11 12 eventsFiltered: [], 13 filters: { 14 startDate: null, 15 endDate: null, 16 locations: [], 17 types: [] 18 }, 19 20 resultsPerPage: 12, 21 page: 0, 22 filtersUpdated: false, 23 24 locationId: null, 25 26 initialize: function(){ 27 28 if( $('.location-information-hidden').length > 0 ){ 29 var id = $('.location-information-hidden').attr("data-cwid"); 30 31 if( id ){ 32 this.locationId = id; 33 this.resultsPerPage = 4; 34 } 35 } 36 37 $.ajax({ 38 url: "/wp-json/gng-events/events", 39 type: "get", 40 cache: false, 41 success: function (data) { 42 var apiResults = JSON.parse(data); 43 Events.eventsFull = apiResults; 44 Events.setLocationList(); 45 Events.setTypeList(); 46 Events.filter(); 47 } 48 }); 49 }, 50 51 52 filter: function(){ 53 this.eventsFiltered = []; 54 55 if( this.filters.startDate || this.filters.locations.length > 0 || this.filters.types.length > 0 || this.locationId ){ 56 for( var i = 0; i < this.eventsFull.length; i++ ){ 57 var errors = 0; 58 59 // if were on a location page... match location ids 60 if( this.locationId ){ 61 if( !(this.eventsFull[i].locId == this.locationId) ){ 62 errors++; 63 } 64 } 65 66 // filter by date range 67 if( this.filters.startDate ){ 68 var eStart = new Date(this.eventsFull[i].start).getTime(); 69 if( eStart < this.filters.startDate || eStart > this.filters.endDate ){ 70 errors++; 71 } 72 } 73 74 // LOCATION CONDITIONS 75 // =========================================== 76 // if there are locations in filter list THEN 77 78 // if event location is NOT equal to "All Locations" 79 80 // if event location is NOT in filter list throw an error 81 82 //filter by location 83 if( this.filters.locations.length > 0 && this.filters.locations.indexOf(this.eventsFull[i].loc) === -1 ){ 84 if( this.eventsFull[i].loc !== "All Locations" && this.eventsFull[i].loc !== "Virtual" ){ 85 errors++; 86 } 87 } 88 89 // filter by type 90 if( this.filters.types.length > 0 ){ 91 var typesMatched = 0; 92 for( var k = 0; k < this.filters.types.length; k++ ){ 93 if( this.eventsFull[i].type.indexOf(this.filters.types[k]) !== -1 ){ 94 typesMatched++; 95 } 96 } 97 98 if( typesMatched === 0 ){ 99 errors++; 100 } 101 } 102 103 104 if( errors === 0 ){ 105 this.eventsFiltered.push(this.eventsFull[i]); 106 } 107 108 } 109 } else { 110 this.eventsFiltered = this.eventsFull; 111 } 112 113 this.setActiveFilters(); 114 this.build(); 115 }, 116 117 118 build: function(){ 119 120 if( this.filtersUpdated ){ 121 this.page = 0; 122 } 123 124 var start = this.page * this.resultsPerPage; 125 var end = (this.page * this.resultsPerPage) + this.resultsPerPage; 126 127 if( end >= this.eventsFiltered.length ){ 128 end = this.eventsFiltered.length; 129 $('.events-button-bar').removeClass('active'); 130 } else { 131 $('.events-button-bar').addClass('active'); 132 } 133 134 var html = ""; 135 if( this.eventsFiltered.length > 0 ){ 136 137 for( var i = start; i < end; i++ ){ 138 var cEvent = this.eventsFiltered[i]; 139 140 141 var cDate = new Date(cEvent.start); 142 var h = formatAMPM(cDate); 143 144 html += '<div class="event-item"><div class="date"><p class="month">' + months[cDate.getMonth()] + '</p><p class="day">' + cDate.getDate() + '</p><p class="start-time">' + h + '</p></div>'; 145 146 html += '<div class="event-info"><div class="event-tags"><a href="#">
146' + cEvent.loc + '</a></div>'; 147 148 html += '<p class="event-name">' + cEvent.name + '</p>'; 149 150 if( cEvent.desc ){ 151 html += '<p class="event-description">' + cEvent.desc + '</p>'; 152 } 153 154 if( cEvent.link ){ 155 html += '<a class="link-main" href="' + cEvent.link + '" target="_blank">Learn More<i class="fa-solid fa-arrow-right"></i></a>'; 156 } 157 158 html += '</div></div>'; 159 } 160 } else { 161 html ="<p>No events found.</p>"; 162 } 163 164 if( !this.locationId ){ 165 if( this.filtersUpdated ){ 166 $('.events-search-grid').empty().append(html).removeClass('loading'); 167 this.filtersUpdated = false; 168 } else { 169 $('.events-search-grid').append(html).removeClass('loading'); 170 } 171 } else { 172 $('.location-events-grid').empty().append(html).removeClass('loading'); 173 } 174 175 }, 176 177 setLocationList: function(){ 178 this.locations = []; 179 180 for(var i = 0; i < this.eventsFull.length; i++ ){ 181 if( this.locations.indexOf(this.eventsFull[i].loc) === -1 && this.eventsFull[i].loc !== "All Locations" && this.eventsFull[i].loc !== "Virtual" ){ 182 this.locations.push(this.eventsFull[i].loc); 183 } 184 } 185 186 this.locations.sort(); 187 188 var html = ""; 189 190 for( var i = 0; i < this.locations.length; i++ ){ 191 html += '<input id="loc' + i + '" type="checkbox" data-loc="' + normalizeLocationName(this.locations[i]) + '"><label for="loc' + i + '" data-loc="' + normalizeLocationName(this.locations[i]) + '">' + this.locations[i] + '</label>'; 192 } 193 194 $('.event-locations .accordion-item-content').removeClass('loading'); 195 $('.event-locations .accordion-item-content').append(html); 196 197 $('.event-locations input[type=checkbox]').on('change', function(){ 198 var loc = $(this).next().text(); 199 200 if( this.checked ){ 201 Events.filters.locations.push(loc); 202 Events.filtersUpdated = true; 203 Events.filter(); 204 } else { 205 Events.filters.locations.splice(Events.filters.locations.indexOf(loc), 1); 206 Events.filtersUpdated = true; 207 Events.filter(); 208 } 209 }); 210 }, 211 212 setTypeList: function(){ 213 this.types = [ 214 "In-person", 215 "Virtual", 216 "Skills Training", 217 "Info Session", 218 "Resource Event", 219 "Job Fair", 220 "Financial Workshop", 221 "Career Development Workshop", 222 "Digital Skills Technology Workshop" 223 ]; 224 225 this.types.sort(); 226 227 var html = ""; 228 229 for( var i = 0; i < this.types.length; i++ ){ 230 html += '<input id="type' + i + '" type="checkbox" data-loc="' + normalizeLocationName(this.types[i]) + '"><label for="type' + i + '" data-loc="' + normalizeLocationName(this.types[i]) + '">' + this.types[i] + '</label>'; 231 } 232 233 $('.event-types .accordion-item-content').removeClass('loading'); 234 $('.event-types .accordion-item-content').append(html); 235 236 237 $('.event-types input[type=checkbox]').on('change', function(){ 238 var typ = $(this).next().text(); 239 240 if( this.checked ){ 241 Events.filters.types.push(typ); 242 Events.filtersUpdated = true; 243 Events.filter(); 244 } else { 245 Events.filters.types.splice(Events.filters.types.indexOf(typ), 1); 246 Events.filtersUpdated = true; 247 Events.filter(); 248 } 249 }); 250 }, 251 252 setActiveFilters: function(){ 253 var html = ""; 254 255 if( !this.filters.startDate && this.filters.locations.length === 0 && this.filters.types.length === 0 ){ 256 html = "<span>All Resources</span>"; 257 } 258 259 if( this.filters.locations.length > 0 || this.filters.types.length > 0 ){ 260 for( var i = 0; i < this.filters.locations.length; i++ ){ 261 html += "<span>" + this.filters.locations[i] + "</span>"; 262 } 263 264 for( var i = 0; i < this.filters.types.length; i++ ){ 265 html += "<span>" + this.filters.types[i] + "</span>"; 266 } 267 } 268 269 if( this.filters.startDate ){ 270 html += "<span>" + ($('#datepicker').val()).replace(" ", "") + "</span>"; 271 } 272 273 $('.active-filter-box').empty().append(html); 274 } 275} 276 277$(document).ready(function(){ 278 var now = new Date(); 279 now.setHours(0,0,0,0); 280 281 if( $('input[name=date-range]').length > 0 ){ 282 var datePicker = new Litepicker({ 283 element: document.getElementById('datepicker'),
284 minDate: now, 285 singleMode: false, 286 startDate: now, 287 format: "YYYY/MM/DD", 288 setup: function(picker){ 289 picker.on('selected', function(date1, date2){ 290 Events.filters.startDate = new Date(date1.dateInstance).getTime(); 291 292 var endTemp = new Date(date2.dateInstance); 293 // adjust end date to 11:59pm 294 endTemp.setHours(23,59,59,999); 295 Events.filters.endDate = endTemp.getTime(); 296 297 Events.filtersUpdated = true; 298 Events.filter(); 299 }); 300 } 301 }); 302 } 303 304 Events.initialize(); 305 306 $('.clear-date-range').on('click', function(e){ 307 e.preventDefault(); 308 $('#datepicker').val(""); 309 Events.filters.startDate = null; 310 Events.filters.endDate = null; 311 Events.filtersUpdated = true; 312 Events.filter(); 313 datePicker.clearSelection(); 314 }) 315 316 $('.load-more-events').on('click', function(e){ 317 e.preventDefault(); 318 Events.page++; 319 Events.build(); 320 }); 321}); 322 323function normalizeLocationName(l){ 324 return l.toLowerCase().replace(" ", "-"); 325} 326 327function testCacheUpdate(){ 328 $.ajax({
329 url: "/wp-json/gng-events/update", 330 type: "get", 331 success: function (data) { 332 console.log(data); 333 } 334 }); 335} 336 337function formatAMPM(date) { 338 var hours = date.getHours(); 339 var minutes = date.getMinutes(); 340 var ampm = hours >= 12 ? 'pm' : 'am'; 341 hours = hours % 12; 342 hours = hours ? hours : 12; // the hour '0' should be '12' 343 minutes = minutes < 10 ? '0'+minutes : minutes; 344 var strTime = hours + ':' + minutes + ampm; 345 return strTime; 346}
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.