// PAGE HELPERS
// *********************************************************
-function fetch_from_api(endpoint_name, params, callback) {
+function generate_full_api_url(endpoint_name, params) {
//
// `&a=&b=&c=1` => '&c=1'
var param_names = Object.keys(params);
var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?'
+ $.param(params);
- if (endpoint_name !== 'status') {
- $('#api-request-link').attr('href', api_url);
+ return api_url;
+}
+
+function update_last_updated(endpoint_name, params) {
+ if (endpoint_name === 'status') return;
+
+ var api_url = generate_full_api_url(endpoint_name, params);
+ $('#last-updated').show();
+
+ $('#api-request a').attr('href', api_url);
+ $('#api-request').show();
+
+ if (endpoint_name === 'search' || endpoint_name === 'reverse') {
+ $('#api-request-debug a').attr('href', api_url + '&debug=1');
+ $('#api-request-debug').show();
+ } else {
+ $('#api-request-debug').hide();
}
+}
+
+function fetch_from_api(endpoint_name, params, callback) {
+ var api_url = generate_full_api_url(endpoint_name, params);
$.get(api_url, function (data) {
+ if (endpoint_name !== 'status') {
+ update_last_updated(endpoint_name, params);
+ }
callback(data);
});
}
function update_data_date() {
fetch_from_api('status', { format: 'json' }, function (data) {
+ $('#last-updated').show();
$('#data-date').text(data.data_updated);
});
}
jQuery(document).ready(function () {
hide_error();
+ $('#last-updated').hide();
+
$(document).ajaxStart(function () {
$('#loading').fadeIn('fast');
}).ajaxComplete(function () {
function parse_url_and_load_page() {
// 'search', 'reverse', 'details'
- var pagename = window.location.pathname.replace('.html', '').replace(/.+\//, '');
+ var pagename = window.location.pathname.replace('.html', '').replace(/^.*\//, '');
if (pagename === '') pagename = 'search';
$(document).on('click', 'a', function (e) {
var target_url = $(this).attr('href');
if (!is_relative_url(target_url)) return;
+ if ($(this).parents('#last-updated').length !== 0) return;
e.preventDefault();
e.stopPropagation();