Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
Don’t fetch the events if no map is present on the page
Browse files Browse the repository at this point in the history
This avoids one potentially heavy Ajax request, especially if there are
a lot of events.
  • Loading branch information
mitio committed Oct 12, 2016
1 parent 5041a41 commit 2d68bb7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ var Codeweek = window.Codeweek || {};
$(function () {
// Initialize map on front page
google.maps.event.addDomListener(window, 'load', function () {
var map = $('#events-map');

if (!map.length) return;

var ajaxURL = "/api/event/list/?format=json";
if (past == "yes")
ajaxURL = ajaxURL + "&past=yes"
Expand All @@ -209,7 +213,7 @@ var Codeweek = window.Codeweek || {};
url: ajaxURL,
error: function(jqXHR, textStatus, errorThrown) {
// TODO: Add some error handling for real
$('#events-map').html('<div id="api-error"><img src="/static/img/blame-the-dog.jpg"><p><strong>A dog broke our API. Catz will fix it soon. Always blame the dog!</strong></p></div>');
map.html('<div id="api-error"><img src="/static/img/blame-the-dog.jpg"><p><strong>A dog broke our API. Catz will fix it soon. Always blame the dog!</strong></p></div>');
},
success: function(data, textStatus, jqXHR) {
initialize(data, lat, lng);
Expand Down

0 comments on commit 2d68bb7

Please sign in to comment.