2 //= require leaflet.sidebar
 
   3 //= require leaflet.locate
 
   4 //= require leaflet.layers
 
   5 //= require leaflet.key
 
   6 //= require leaflet.note
 
   7 //= require leaflet.share
 
   8 //= require leaflet.polyline
 
   9 //= require leaflet.query
 
  10 //= require leaflet.contextmenu
 
  11 //= require index/contextmenu
 
  12 //= require index/search
 
  13 //= require index/browse
 
  14 //= require index/export
 
  15 //= require index/notes
 
  16 //= require index/history
 
  17 //= require index/note
 
  18 //= require index/new_note
 
  19 //= require index/directions
 
  20 //= require index/changeset
 
  21 //= require index/query
 
  24 //= require querystring
 
  26 $(document).ready(function () {
 
  27   var querystring = require("querystring-component");
 
  31   var map = new L.OSM.Map("map", {
 
  37   OSM.loadSidebarContent = function (path, callback) {
 
  38     var content_path = path;
 
  40     map.setSidebarOverlaid(false);
 
  42     clearTimeout(loaderTimeout);
 
  44     loaderTimeout = setTimeout(function () {
 
  45       $("#sidebar_loader").show();
 
  48     // IE<10 doesn't respect Vary: X-Requested-With header, so
 
  49     // prevent caching the XHR response as a full-page URL.
 
  50     if (content_path.indexOf("?") >= 0) {
 
  51       content_path += "&xhr=1";
 
  53       content_path += "?xhr=1";
 
  62       complete: function (xhr) {
 
  63         clearTimeout(loaderTimeout);
 
  65         $("#sidebar_loader").hide();
 
  67         var content = $(xhr.responseText);
 
  69         if (xhr.getResponseHeader("X-Page-Title")) {
 
  70           var title = xhr.getResponseHeader("X-Page-Title");
 
  71           document.title = decodeURIComponent(title);
 
  75           .find("link[type=\"application/atom+xml\"]")
 
  79           .append(content.filter("link[type=\"application/atom+xml\"]"));
 
  81         $("#sidebar_content").html(content.not("link[type=\"application/atom+xml\"]"));
 
  90   var params = OSM.mapParams();
 
  92   map.attributionControl.setPrefix("");
 
  94   map.updateLayers(params.layers);
 
  96   map.on("baselayerchange", function (e) {
 
  97     if (map.getZoom() > e.layer.options.maxZoom) {
 
  98       map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
 
 102   var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
 
 104   L.OSM.zoom({ position: position })
 
 107   var locate = L.control.locate({
 
 109     icon: "icon geolocate",
 
 110     iconLoading: "icon geolocate",
 
 112       title: I18n.t("javascripts.map.locate.title"),
 
 113       popup: I18n.t("javascripts.map.locate.popup")
 
 117   var locateContainer = locate.getContainer();
 
 120     .removeClass("leaflet-control-locate leaflet-bar")
 
 121     .addClass("control-locate")
 
 124     .removeClass("leaflet-bar-part leaflet-bar-part-single")
 
 125     .addClass("control-button");
 
 127   var sidebar = L.OSM.sidebar("#map-ui")
 
 132     layers: map.baseLayers,
 
 142     "position": position,
 
 160   OSM.initializeContextMenu(map);
 
 162   if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") {
 
 163     OSM.initializeNotes(map);
 
 164     if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
 
 165       map.addLayer(map.noteLayer);
 
 168     OSM.initializeBrowse(map);
 
 169     if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
 
 170       map.addLayer(map.dataLayer);
 
 173     if (params.layers.indexOf(map.gpsLayer.options.code) >= 0) {
 
 174       map.addLayer(map.gpsLayer);
 
 178   var placement = $("html").attr("dir") === "rtl" ? "right" : "left";
 
 179   $(".leaflet-control .control-button").tooltip({ placement: placement, container: "body" });
 
 181   var expiry = new Date();
 
 182   expiry.setYear(expiry.getFullYear() + 10);
 
 184   map.on("moveend layeradd layerremove", function () {
 
 186       map.getCenter().wrap(),
 
 191     $.removeCookie("_osm_location");
 
 192     $.cookie("_osm_location", OSM.locationCookie(map), { expires: expiry, path: "/" });
 
 195   if ($.cookie("_osm_welcome") !== "hide") {
 
 196     $(".welcome").addClass("visible");
 
 199   $(".welcome .close-wrap").on("click", function () {
 
 200     $(".welcome").removeClass("visible");
 
 201     $.cookie("_osm_welcome", "hide", { expires: expiry, path: "/" });
 
 204   var bannerExpiry = new Date();
 
 205   bannerExpiry.setYear(bannerExpiry.getFullYear() + 1);
 
 207   $("#banner .close-wrap").on("click", function (e) {
 
 208     var cookieId = e.target.id;
 
 212       $.cookie(cookieId, "hide", { expires: bannerExpiry, path: "/" });
 
 217     map.on("layeradd", function (e) {
 
 218       if (e.layer.options) {
 
 219         var goal = OSM.PIWIK.goals[e.layer.options.keyid];
 
 222           $("body").trigger("piwikgoal", goal);
 
 229     map.fitBounds(params.bounds);
 
 231     map.setView([params.lat, params.lon], params.zoom);
 
 235     L.marker([params.mlat, params.mlon]).addTo(map);
 
 238   $("#homeanchor").on("click", function (e) {
 
 241     var data = $(this).data(),
 
 242         center = L.latLng(data.lat, data.lon);
 
 244     map.setView(center, data.zoom);
 
 245     L.marker(center, { icon: OSM.getUserIcon() }).addTo(map);
 
 248   function remoteEditHandler(bbox, object) {
 
 252           left: bbox.getWest() - 0.0001,
 
 253           top: bbox.getNorth() + 0.0001,
 
 254           right: bbox.getEast() + 0.0001,
 
 255           bottom: bbox.getSouth() - 0.0001
 
 258     if (location.protocol === "http" ||
 
 259         bowser.check({ chrome: "53", firefox: "55" })) {
 
 260       url = "http://127.0.0.1:8111/load_and_zoom?";
 
 262       url = "https://127.0.0.1:8112/load_and_zoom?";
 
 265     if (object) query.select = object.type + object.id;
 
 267     var iframe = $("<iframe>")
 
 270       .attr("src", url + querystring.stringify(query))
 
 271       .on("load", function () {
 
 276     setTimeout(function () {
 
 278         alert(I18n.t("site.index.remote_failed"));
 
 286   $("a[data-editor=remote]").click(function (e) {
 
 287     var params = OSM.mapParams(this.search);
 
 288     remoteEditHandler(map.getBounds(), params.object);
 
 292   if (OSM.params().edit_help) {
 
 297         title: I18n.t("javascripts.edit_help")
 
 301     $("body").one("click", function () {
 
 302       $("#editanchor").tooltip("hide");
 
 306   OSM.Index = function (map) {
 
 309     page.pushstate = page.popstate = function () {
 
 310       map.setSidebarOverlaid(true);
 
 311       document.title = I18n.t("layouts.project_name.title");
 
 314     page.load = function () {
 
 315       var params = querystring.parse(location.search.substring(1));
 
 317         $("#sidebar .search_form input[name=query]").value(params.query);
 
 319       if (!("autofocus" in document.createElement("input"))) {
 
 320         $("#sidebar .search_form input[name=query]").focus();
 
 322       return map.getState();
 
 328   OSM.Browse = function (map, type) {
 
 331     page.pushstate = page.popstate = function (path, id) {
 
 332       OSM.loadSidebarContent(path, function () {
 
 337     page.load = function (path, id) {
 
 338       addObject(type, id, true);
 
 341     function addObject(type, id, center) {
 
 342       map.addObject({ type: type, id: parseInt(id, 10) }, function (bounds) {
 
 343         if (!window.location.hash && bounds.isValid() &&
 
 344             (center || !map.getBounds().contains(bounds))) {
 
 345           OSM.router.withoutMoveListener(function () {
 
 346             map.fitBounds(bounds);
 
 352     page.unload = function () {
 
 359   var history = OSM.History(map);
 
 361   OSM.router = OSM.Router(map, {
 
 363     "/search": OSM.Search(map),
 
 364     "/directions": OSM.Directions(map),
 
 365     "/export": OSM.Export(map),
 
 366     "/note/new": OSM.NewNote(map),
 
 367     "/history/friends": history,
 
 368     "/history/nearby": history,
 
 370     "/user/:display_name/history": history,
 
 371     "/note/:id": OSM.Note(map),
 
 372     "/node/:id(/history)": OSM.Browse(map, "node"),
 
 373     "/way/:id(/history)": OSM.Browse(map, "way"),
 
 374     "/relation/:id(/history)": OSM.Browse(map, "relation"),
 
 375     "/changeset/:id": OSM.Changeset(map),
 
 376     "/query": OSM.Query(map)
 
 379   if (OSM.preferred_editor === "remote" && document.location.pathname === "/edit") {
 
 380     remoteEditHandler(map.getBounds(), params.object);
 
 381     OSM.router.setCurrentPath("/");
 
 386   $(document).on("click", "a", function (e) {
 
 387     if (e.isDefaultPrevented() || e.isPropagationStopped()) {
 
 391     // Open links in a new tab as normal.
 
 392     if (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
 
 396     // Ignore cross-protocol and cross-origin links.
 
 397     if (location.protocol !== this.protocol || location.host !== this.host) {
 
 401     if (OSM.router.route(this.pathname + this.search + this.hash)) {