X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/762d615859b47d4c25e1c529a04fb08aed665d9c..33aa0a6e454fb2d43b8ccc07395abf0864d47b66:/app/assets/javascripts/application.js?ds=sidebyside diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index c52c072a7..ee9b16ff1 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,11 +1,13 @@ //= require jquery //= require jquery_ujs -//= require jquery.autogrowtextarea //= require jquery.timers //= require jquery.cookie //= require augment -//= require openlayers +//= require leaflet +//= require leaflet.osm +//= require leaflet.locationfilter //= require i18n/translations +//= require oauth //= require osm //= require piwik //= require map @@ -13,6 +15,7 @@ //= require sidebar //= require richtext //= require resize +//= require geocoder function zoomPrecision(zoom) { var decimals = Math.pow(10, Math.floor(zoom/3)); @@ -21,33 +24,48 @@ function zoomPrecision(zoom) { }; } +function normalBounds(bounds) { + if (bounds instanceof L.LatLngBounds) return bounds; + return new L.LatLngBounds( + new L.LatLng(bounds[0][0], bounds[0][1]), + new L.LatLng(bounds[1][0], bounds[1][1])); +} + /* - * Called as the user scrolls/zooms around to aniplate hrefs of the + * Called as the user scrolls/zooms around to maniplate hrefs of the * view tab and various other links */ -function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) { +function updatelinks(loc, zoom, layers, bounds, object) { var toPrecision = zoomPrecision(zoom); + bounds = normalBounds(bounds); var node; - lat = toPrecision(lat); - lon = toPrecision(lon); + var lat = toPrecision(loc.lat), + lon = toPrecision(loc.lon || loc.lng); - if (minlon) { - minlon = toPrecision(minlon); - minlat = toPrecision(minlat); - maxlon = toPrecision(maxlon); - maxlat = toPrecision(maxlat); + if (bounds) { + var minlon = toPrecision(bounds.getWest()), + minlat = toPrecision(bounds.getSouth()), + maxlon = toPrecision(bounds.getEast()), + maxlat = toPrecision(bounds.getNorth()); } - $(".geolink").each(function (index, link) { + $(".geolink").each(setGeolink); + $("#shortlinkanchor").each(setShortlink); + + function setGeolink(index, link) { var args = getArgs(link.href); if ($(link).hasClass("llz")) { - args.lat = lat; - args.lon = lon; - args.zoom = zoom; + $.extend(args, { + lat: lat, + lon: lon, + zoom: zoom + }); } else if (minlon && $(link).hasClass("bbox")) { - args.bbox = minlon + "," + minlat + "," + maxlon + "," + maxlat; + $.extend(args, { + bbox: minlon + "," + minlat + "," + maxlon + "," + maxlat + }); } if (layers && $(link).hasClass("layers")) { @@ -65,19 +83,20 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) { $(link).off("click.minzoom"); if (zoom >= minzoom) { - $(link).attr("title", I18n.t("javascripts.site." + name + "_tooltip")); - $(link).removeClass("disabled"); + $(link).attr("title", I18n.t("javascripts.site." + name + "_tooltip")) + .removeClass("disabled"); } else { - $(link).on("click.minzoom", function () { alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false; }); - $(link).attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip")); - $(link).addClass("disabled"); + $(link).on("click.minzoom", minZoomAlert) + .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip")) + .addClass("disabled"); } } link.href = setArgs(link.href, args); - }); + } - $("#shortlinkanchor").each(function () { + + function setShortlink() { var args = getArgs(this.href); var code = makeShortCode(lat, lon, zoom); var prefix = shortlinkPrefix(); @@ -90,8 +109,7 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) { // This is a hack to omit the default mapnik layer from the shortlink. if (layers && layers != "M") { args.layers = layers; - } - else { + } else { delete args.layers; } @@ -104,7 +122,11 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) { } else { this.href = prefix + "/go/" + code; } - }); + } +} + +function minZoomAlert() { + alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false; } /* @@ -210,10 +232,3 @@ $(document).ready(function () { var auth_token = $("meta[name=csrf-token]").attr("content"); $("form input[name=authenticity_token]").val(auth_token); }); - -/* - * Enable auto expansion for all text areas - */ -$(document).ready(function () { - $("textarea").autoGrow(); -});