reload searchable locations regularly
This commit is contained in:
parent
cdfef25034
commit
d8f6e354af
1 changed files with 29 additions and 12 deletions
|
@ -29,19 +29,9 @@
|
||||||
}());
|
}());
|
||||||
|
|
||||||
c3nav = {
|
c3nav = {
|
||||||
|
init_completed: false,
|
||||||
init: function () {
|
init: function () {
|
||||||
$.getJSON('/api/locations/?searchable', function (data) {
|
c3nav.load_searchable_locations();
|
||||||
for (var i = 0; i < data.length; i++) {
|
|
||||||
var location = data[i];
|
|
||||||
location.elem = c3nav._build_location_html(location);
|
|
||||||
location.title_words = location.title.toLowerCase().split(/\s+/);
|
|
||||||
location.subtitle_words = location.subtitle.toLowerCase().split(/\s+/);
|
|
||||||
location.match = ' ' + location.title_words.join(' ') + ' ' + location.subtitle_words.join(' ') + ' ';
|
|
||||||
c3nav.locations.push(location);
|
|
||||||
c3nav.locations_by_id[location.id] = location;
|
|
||||||
}
|
|
||||||
c3nav.continue_init();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#messages').find('ul.messages li').each(function() {
|
$('#messages').find('ul.messages li').each(function() {
|
||||||
$(this).prepend(
|
$(this).prepend(
|
||||||
|
@ -57,6 +47,29 @@ c3nav = {
|
||||||
$('body').addClass('mobileclient');
|
$('body').addClass('mobileclient');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
load_searchable_locations: function() {
|
||||||
|
$.getJSON('/api/locations/?searchable', c3nav._searchable_locations_loaded).fail(function() {
|
||||||
|
window.setTimeout(c3nav.load_searchable_locations, 5000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
_searchable_locations_loaded: function(data) {
|
||||||
|
var locations = [],
|
||||||
|
locations_by_id = {};
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
var location = data[i];
|
||||||
|
location.elem = c3nav._build_location_html(location);
|
||||||
|
location.title_words = location.title.toLowerCase().split(/\s+/);
|
||||||
|
location.subtitle_words = location.subtitle.toLowerCase().split(/\s+/);
|
||||||
|
location.match = ' ' + location.title_words.join(' ') + ' ' + location.subtitle_words.join(' ') + ' ';
|
||||||
|
locations.push(location);
|
||||||
|
locations_by_id[location.id] = location;
|
||||||
|
}
|
||||||
|
c3nav.locations = locations;
|
||||||
|
c3nav.locations_by_id = locations_by_id;
|
||||||
|
if (!c3nav.init_completed) {
|
||||||
|
c3nav.continue_init();
|
||||||
|
}
|
||||||
|
},
|
||||||
continue_init: function() {
|
continue_init: function() {
|
||||||
c3nav.init_map();
|
c3nav.init_map();
|
||||||
|
|
||||||
|
@ -111,6 +124,10 @@ c3nav = {
|
||||||
$('header h1 a').removeAttr('href');
|
$('header h1 a').removeAttr('href');
|
||||||
|
|
||||||
window.onpopstate = c3nav._onpopstate;
|
window.onpopstate = c3nav._onpopstate;
|
||||||
|
|
||||||
|
window.setInterval(c3nav.load_searchable_locations, 42000);
|
||||||
|
|
||||||
|
c3nav.init_completed = true;
|
||||||
},
|
},
|
||||||
get_csrf_token: function() {
|
get_csrf_token: function() {
|
||||||
return document.cookie.match(new RegExp('c3nav_csrftoken=([^;]+)'))[1];
|
return document.cookie.match(new RegExp('c3nav_csrftoken=([^;]+)'))[1];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue