Skip to content

Commit

Permalink
Don't try to use JQuery until it's loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Dec 22, 2017
1 parent 36ed591 commit 055abf7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ function initMap () {
: new google.maps.LatLng(48.9062802, 2.3598659) // eslint-disable-line no-undef
})

setInterval(function () {
// eslint-disable-next-line no-undef
$.getJSON({url: 'aircrafts', type: 'GET', success: plotAircrafts})
}, 2000)
onJQuery(function () {
setInterval(function () {
// eslint-disable-next-line no-undef
$.getJSON('aircrafts', plotAircrafts)
.fail(function (jqXHR, textStatus, err) {
throw err
})
}, 2000)
})
}

function plotAircrafts (aircrafts) {
Expand Down Expand Up @@ -91,6 +96,11 @@ function aircrafts () {
})
}

function onJQuery (cb) {
if (window.jQuery) cb()
else setTimeout(onJQuery.bind(null, cb), 50)
}

function Aircraft () {
this.flightPathCoords = []
// eslint-disable-next-line no-undef
Expand Down

0 comments on commit 055abf7

Please sign in to comment.