X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/352f2a167151e080b871e113d0f1ff9f88dca5a6..e316f0e425cc934295c8e64cdcf03f00899f287c:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 27a2d5ee8..85f5dab0d 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -1,9 +1,14 @@ -var marker; -var map; -var params = OSM.mapParams(); +//= require index/browse +//= require index/export +//= require index/key -function mapInit(){ - map = createMap("map"); +$(document).ready(function () { + var marker; + var params = OSM.mapParams(); + var map = createMap("map"); + + map.events.register("moveend", map, updateLocation); + map.events.register("changelayer", map, updateLocation); if (!params.object_zoom) { if (params.bbox) { @@ -12,7 +17,7 @@ function mapInit(){ map.zoomToExtent(proj(bbox)); if (params.box) { - $(window).load(function() { addBoxToMap(bbox) }); + addBoxToMap(bbox); } } else { setMapCenter(new OpenLayers.LonLat(params.lon, params.lat), params.zoom); @@ -28,29 +33,10 @@ function mapInit(){ } if (params.object) { - var url = "/api/" + OSM.API_VERSION + "/" + params.object_type + "/" + params.object_id; - - if (params.object_type != "node") { - url += "/full"; - } - - $(window).load(function() { addObjectToMap(url, params.object_zoom) }); + addObjectToMap(params.object, params.object_zoom); } - map.events.register("moveend", map, updateLocation); - map.events.register("changelayer", map, updateLocation); - - updateLocation(); handleResize(); -} - -$(document).ready(function () { - $("#show_data").click(function (e) { - $.ajax({ url: $(this).attr('href'), success: function (sidebarHtml) { - startBrowse(sidebarHtml); - }}); - e.preventDefault(); - }); $("body").on("click", "a.set_position", function () { var data = $(this).data(); @@ -72,70 +58,65 @@ $(document).ready(function () { return false; }); -}); -function updateLocation() { - var lonlat = unproj(map.getCenter()); - var zoom = map.getZoom(); - var layers = getMapLayers(); - var extents = unproj(map.getExtent()); - var expiry = new Date(); + function updateLocation() { + var lonlat = unproj(map.getCenter()); + var zoom = map.getZoom(); + var layers = getMapLayers(); + var extents = unproj(map.getExtent()); + var expiry = new Date(); - updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, params.object_type, params.object_id); + updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, params.object); - expiry.setYear(expiry.getFullYear() + 10); - $.cookie("_osm_location", [lonlat.lon, lonlat.lat, zoom, layers].join("|"), {expires: expiry}); -} + expiry.setYear(expiry.getFullYear() + 10); + $.cookie("_osm_location", [lonlat.lon, lonlat.lat, zoom, layers].join("|"), {expires: expiry}); + } -function remoteEditHandler(event) { - var extent = unproj(map.getExtent()); - var loaded = false; + function remoteEditHandler(event) { + var extent = unproj(map.getExtent()); + var loaded = false; - $("#linkloader").load(function () { loaded = true; }); - $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom); + $("#linkloader").load(function () { loaded = true; }); + $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom); - setTimeout(function () { - if (!loaded) alert(I18n.t('site.index.remote_failed')); - }, 1000); + setTimeout(function () { + if (!loaded) alert(I18n.t('site.index.remote_failed')); + }, 1000); - return false; -} + return false; + } -function installEditHandler() { $("a[data-editor=remote]").click(remoteEditHandler); if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) { remoteEditHandler(); } -} -$(document).ready(mapInit); -$(document).ready(installEditHandler); -$(document).ready(handleResize); + $(window).resize(function() { + var centre = map.getCenter(); + var zoom = map.getZoom(); -$(window).resize(function() { - var centre = map.getCenter(); - var zoom = map.getZoom(); + handleResize(); - handleResize(); + map.setCenter(centre, zoom); + }); - map.setCenter(centre, zoom); -}); + $("#search_form").submit(function () { + var extent = unproj(map.getExtent()); -$(document).ready(function () { - $("#exportanchor").click(function (e) { - $.ajax({ url: $(this).data('url'), success: function (sidebarHtml) { - startExport(sidebarHtml); - }}); - e.preventDefault(); - }); + $("#sidebar_title").html(I18n.t('site.sidebar.search_results')); + $("#sidebar_content").load($(this).attr("action"), { + query: $("#query").val(), + minlon: extent.left, + minlat: extent.bottom, + maxlon: extent.right, + maxlat: extent.top + }, openSidebar); - if (window.location.pathname == "/export") { - $("#exportanchor").click(); - } + return false; + }); - var query; - if (query = getArgs(window.location.toString()).query) { - doSearch(query); + if ($("#query").val()) { + $("#search_form").submit(); } });