- // Unselect previously selected feature
- if (selectedLayer) {
- selectedLayer.setStyle(selectedLayer.originalStyle);
- }
-
- // Redraw in selected style
- layer.originalStyle = layer.options;
- layer.setStyle({color: '#0000ff', weight: 8});
-
- // If the current object is the list, don't innerHTML="", since that could clear it.
- if ($("#browse_content").firstChild == browseObjectList) {
- $("#browse_content").removeChild(browseObjectList);
- } else {
- $("#browse_content").empty();
- }
-
- var feature = layer.feature;
-
- $("#browse_content").html(JST["templates/browse/feature"]({
- name: featureNameSelect(feature),
- url: "/browse/" + feature.type + "/" + feature.id,
- attributes: feature.tags
- }));
-
- $("#browse_content").find("a.browse_show_list").click(loadObjectList);
- $("#browse_content").find("a.browse_show_history").click(loadHistory);
-
- // Stash the currently drawn feature
- selectedLayer = layer;
- }
-
- function loadHistory() {
- $(this).attr("href", "").text(I18n.t('browse.start_rjs.wait'));
-
- var feature = selectedLayer.feature;
-
- $.ajax({
- url: "/api/" + OSM.API_VERSION + "/" + feature.type + "/" + feature.id + "/history",
- success: function (xml) {
- if (selectedLayer.feature != feature || $("#browse_content").firstChild == browseObjectList) {
- return;
- }
-
- $(this).remove();
-
- var history = [];
- var nodes = xml.getElementsByTagName(feature.type);
- for (var i = nodes.length - 1; i >= 0; i--) {
- history.push({
- user: nodes[i].getAttribute("user") || I18n.t('browse.start_rjs.private_user'),
- timestamp: nodes[i].getAttribute("timestamp")
- });
- }
-
- $("#browse_content").append(JST["templates/browse/feature_history"]({
- name: featureNameHistory(feature),
- url: "/browse/" + feature.type + "/" + feature.id,
- history: history
- }));
- }.bind(this)
- });
-
- return false;
- }
-
- function featureTypeName(feature) {
- return I18n.t('browse.start_rjs.object_list.type.' + feature.type);
- }
-
- function featureName(feature) {
- return feature.tags['name:' + $('html').attr('lang')] ||
- feature.tags.name ||
- feature.id;
- }
-
- function featureNameSelect(feature) {
- return feature.tags['name:' + $('html').attr('lang')] ||
- feature.tags.name ||
- I18n.t("browse.start_rjs.object_list.selected.type." + feature.type, { id: feature.id });
- }
-
- function featureNameHistory(feature) {
- return feature.tags['name:' + $('html').attr('lang')] ||
- feature.tags.name ||
- I18n.t("browse.start_rjs.object_list.history.type." + feature.type, { id: feature.id });
- }
-
- function setStatus(status) {
- $("#browse_status").html(status);
- $("#browse_status").show();
- }
-
- function clearStatus() {
- $("#browse_status").html("");
- $("#browse_status").hide();