From: marc tobias Date: Fri, 21 Feb 2020 17:27:32 +0000 (+0100) Subject: Set HTML title for all pages X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/commitdiff_plain/ed27f5c1039a168fd68baa5b64054b060069593b?hp=53666d8f38225ad4000b92096a1eac7f38323b76 Set HTML title for all pages --- diff --git a/TODO.md b/TODO.md index dbb1a9f..5e2a295 100644 --- a/TODO.md +++ b/TODO.md @@ -7,14 +7,13 @@ * pagination. API returns an array without indication if more results exist * API returns category, type, but without admin_level we can't derive e.g. state,country -* seeting acceptlanguage whichout a server component https://github.com/dansingerman/jQuery-Browser-Language +* setting accept-language without a server component https://github.com/dansingerman/jQuery-Browser-Language ## Nice-to-have * support nearlat,nearlon parameters * should images/mapicons/ be served from API server or this repo? * different content for official OSM, e.g. github urls -* set HTML title * cache `update_data_date` result somehow? * a new search causes a new pageview * add tests with fixtures diff --git a/dist/assets/js/nominatim-ui.js b/dist/assets/js/nominatim-ui.js index f94bc75..1a7ee69 100644 --- a/dist/assets/js/nominatim-ui.js +++ b/dist/assets/js/nominatim-ui.js @@ -83,6 +83,14 @@ function render_template(el, template_name, page_context) { el.html(html); } +function update_html_title(title) { + var prefix = ''; + if (title && title.length > 1) { + prefix = title + ' | '; + } + $('head title').text(prefix + 'OpenStreetMap Nominatim'); +} + function show_error(html) { $('#error-overlay').html(html).show(); } @@ -172,6 +180,11 @@ jQuery(document).ready(function () { var context = { aPlace: aFeature, base_url: location.search }; render_template($('main'), 'detailspage-template', context); + if (api_request_params.place_id) { + update_html_title('Details for ' + api_request_params.place_id); + } else { + update_html_title('Details for ' + api_request_params.osmtype + api_request_params.osmid); + } update_data_date(); @@ -508,7 +521,7 @@ jQuery(document).ready(function () { iZoom: (search_params.get('zoom') > 1 ? api_request_params.zoom : get_config_value('Reverse_Default_Search_Zoom')) }; - + update_html_title(); if (api_request_params.lat && api_request_params.lon) { fetch_from_api('reverse', api_request_params, function (aPlace) { @@ -520,6 +533,7 @@ jQuery(document).ready(function () { context.aPlace = aPlace; render_template($('main'), 'reversepage-template', context); + update_html_title('Reverse result for ' + api_request_params.lat + ',' + api_request_params.lon); init_map_on_search_page( is_reverse_search, @@ -566,6 +580,7 @@ jQuery(document).ready(function () { context.aSearchResults = aResults; render_template($('main'), 'searchpage-template', context); + update_html_title('Result for ' + api_request_params.q); init_map_on_search_page(is_reverse_search, aResults, get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom')); diff --git a/src/assets/js/base.js b/src/assets/js/base.js index a56f40d..c9635fb 100644 --- a/src/assets/js/base.js +++ b/src/assets/js/base.js @@ -83,6 +83,14 @@ function render_template(el, template_name, page_context) { el.html(html); } +function update_html_title(title) { + var prefix = ''; + if (title && title.length > 1) { + prefix = title + ' | '; + } + $('head title').text(prefix + 'OpenStreetMap Nominatim'); +} + function show_error(html) { $('#error-overlay').html(html).show(); } diff --git a/src/assets/js/detailpage.js b/src/assets/js/detailpage.js index 09a8ce1..73591fe 100644 --- a/src/assets/js/detailpage.js +++ b/src/assets/js/detailpage.js @@ -68,6 +68,11 @@ jQuery(document).ready(function () { var context = { aPlace: aFeature, base_url: location.search }; render_template($('main'), 'detailspage-template', context); + if (api_request_params.place_id) { + update_html_title('Details for ' + api_request_params.place_id); + } else { + update_html_title('Details for ' + api_request_params.osmtype + api_request_params.osmid); + } update_data_date(); diff --git a/src/assets/js/searchpage.js b/src/assets/js/searchpage.js index b970afc..01b8fde 100755 --- a/src/assets/js/searchpage.js +++ b/src/assets/js/searchpage.js @@ -304,7 +304,7 @@ jQuery(document).ready(function () { iZoom: (search_params.get('zoom') > 1 ? api_request_params.zoom : get_config_value('Reverse_Default_Search_Zoom')) }; - + update_html_title(); if (api_request_params.lat && api_request_params.lon) { fetch_from_api('reverse', api_request_params, function (aPlace) { @@ -316,6 +316,7 @@ jQuery(document).ready(function () { context.aPlace = aPlace; render_template($('main'), 'reversepage-template', context); + update_html_title('Reverse result for ' + api_request_params.lat + ',' + api_request_params.lon); init_map_on_search_page( is_reverse_search, @@ -362,6 +363,7 @@ jQuery(document).ready(function () { context.aSearchResults = aResults; render_template($('main'), 'searchpage-template', context); + update_html_title('Result for ' + api_request_params.q); init_map_on_search_page(is_reverse_search, aResults, get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom'));