X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/3bea64f4ccf465fc755b81e7badc06d182a275b7..63aaf045ac868675155c76468c9286eaaa3acd83:/app/assets/javascripts/index/query.js diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index d1668f247..08da06d4c 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -39,17 +39,21 @@ OSM.Query = function (map) { } }); + function showResultGeometry() { + var geometry = $(this).data("geometry"); + if (geometry) map.addLayer(geometry); + $(this).addClass("selected"); + } + + function hideResultGeometry() { + var geometry = $(this).data("geometry"); + if (geometry) map.removeLayer(geometry); + $(this).removeClass("selected"); + } + $("#sidebar_content") - .on("mouseover", ".query-results li.query-result", function () { - var geometry = $(this).data("geometry"); - if (geometry) map.addLayer(geometry); - $(this).addClass("selected"); - }) - .on("mouseout", ".query-results li.query-result", function () { - var geometry = $(this).data("geometry"); - if (geometry) map.removeLayer(geometry); - $(this).removeClass("selected"); - }) + .on("mouseover", ".query-results li.query-result", showResultGeometry) + .on("mouseout", ".query-results li.query-result", hideResultGeometry) .on("mousedown", ".query-results li.query-result", function () { var moved = false; $(this).one("click", function (e) { @@ -121,7 +125,7 @@ OSM.Query = function (map) { function featureName(feature) { var tags = feature.tags, - locales = I18n.locales.get(); + locales = OSM.preferred_languages; for (var i = 0; i < locales.length; i++) { if (tags["name:" + locales[i]]) { @@ -168,10 +172,6 @@ OSM.Query = function (map) { $ul.empty(); $section.show(); - $section.find(".loader").oneTime(1000, "loading", function () { - $(this).show(); - }); - if ($section.data("ajax")) { $section.data("ajax").abort(); } @@ -188,7 +188,7 @@ OSM.Query = function (map) { success: function (results) { var elements; - $section.find(".loader").stopTime("loading").hide(); + $section.find(".loader").hide(); if (merge) { elements = results.elements.reduce(function (hash, element) { @@ -216,7 +216,7 @@ OSM.Query = function (map) { if (interestingFeature(element)) { var $li = $("
  • ") - .addClass("query-result list-group-item") + .addClass("query-result list-group-item list-group-item-action") .data("geometry", featureGeometry(element)) .text(featurePrefix(element) + " ") .appendTo($ul); @@ -230,23 +230,23 @@ OSM.Query = function (map) { if (results.remark) { $("
  • ") - .addClass("query-result list-group-item") + .addClass("list-group-item") .text(I18n.t("javascripts.query.error", { server: url, error: results.remark })) .appendTo($ul); } if ($ul.find("li").length === 0) { $("
  • ") - .addClass("query-result list-group-item") + .addClass("list-group-item") .text(I18n.t("javascripts.query.nothing_found")) .appendTo($ul); } }, error: function (xhr, status, error) { - $section.find(".loader").stopTime("loading").hide(); + $section.find(".loader").hide(); $("
  • ") - .addClass("query-result list-group-item") + .addClass("list-group-item") .text(I18n.t("javascripts.query." + status, { server: url, error: error })) .appendTo($ul); } @@ -367,6 +367,7 @@ OSM.Query = function (map) { page.unload = function (sameController) { if (!sameController) { disableQueryMode(); + $("#sidebar_content .query-results li.query-result.selected").each(hideResultGeometry); } };