3 //= require jquery.timers
 
   4 //= require jquery.throttle-debounce
 
   5 //= require js-cookie/dist/js.cookie
 
   7 //= require bootstrap-sprockets
 
   9 //= require leaflet/dist/leaflet-src
 
  10 //= require leaflet.osm
 
  11 //= require leaflet.map
 
  12 //= require leaflet.zoom
 
  13 //= require leaflet.locationfilter
 
  18 //= require qs/dist/qs
 
  19 //= require bs-custom-file-input
 
  20 //= require bs-custom-file-input-init
 
  23  * Called as the user scrolls/zooms around to manipulate hrefs of the
 
  24  * view tab and various other links
 
  26 window.updateLinks = function (loc, zoom, layers, object) {
 
  27   $(".geolink").each(function (index, link) {
 
  28     var href = link.href.split(/[?#]/)[0],
 
  29         args = Qs.parse(link.search.substring(1)),
 
  30         editlink = $(link).hasClass("editlink");
 
  35     delete args.changeset;
 
  38     if (object && editlink) {
 
  39       args[object.type] = object.id;
 
  42     var query = Qs.stringify(args);
 
  43     if (query) href += "?" + query;
 
  47       lon: "lon" in loc ? loc.lon : loc.lng,
 
  51     if (layers && !editlink) {
 
  55     href += OSM.formatHash(args);
 
  60   // Disable the button group and also the buttons to avoid
 
  61   // inconsistent behaviour when zooming
 
  62   var editDisabled = zoom < 13;
 
  64     .tooltip({ placement: "bottom" })
 
  65     .tooltip(editDisabled ? "enable" : "disable")
 
  66     .toggleClass("disabled", editDisabled)
 
  68     .toggleClass("disabled", editDisabled);
 
  71 $(document).ready(function () {
 
  72   // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis
 
  73   // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
 
  74   Turbo.session.drive = false;
 
  79   function updateHeader() {
 
  80     var windowWidth = $(window).width();
 
  82     if (windowWidth < compactWidth) {
 
  83       $("body").removeClass("compact-nav").addClass("small-nav");
 
  84     } else if (windowWidth < headerWidth) {
 
  85       $("body").addClass("compact-nav").removeClass("small-nav");
 
  87       $("body").removeClass("compact-nav").removeClass("small-nav");
 
  92    * Chrome 60 and later seem to fire the "ready" callback
 
  93    * before the DOM is fully ready causing us to measure the
 
  94    * wrong sizes for the header elements - use a 0ms timeout
 
  95    * to defer the measurement slightly as a workaround.
 
  97   setTimeout(function () {
 
  98     $("header").children(":visible").each(function (i, e) {
 
  99       headerWidth = headerWidth + $(e).outerWidth();
 
 102     $("body").addClass("compact-nav");
 
 104     $("header").children(":visible").each(function (i, e) {
 
 105       compactWidth = compactWidth + $(e).outerWidth();
 
 108     $("body").removeClass("compact-nav");
 
 110     $("header").removeClass("text-nowrap");
 
 114     $(window).resize(updateHeader);
 
 115     $(document).on("turbo:render", updateHeader);
 
 118   $("#menu-icon").on("click", function (e) {
 
 120     $("header").toggleClass("closed");
 
 123   $("nav.primary li a").on("click", function () {
 
 124     $("header").toggleClass("closed");
 
 127   var application_data = $("head").data();
 
 129   I18n.default_locale = OSM.DEFAULT_LOCALE;
 
 130   I18n.locale = application_data.locale;
 
 131   I18n.fallbacks = true;
 
 133   OSM.preferred_editor = application_data.preferredEditor;
 
 134   OSM.preferred_languages = application_data.preferredLanguages;
 
 136   if (application_data.user) {
 
 137     OSM.user = application_data.user;
 
 139     if (application_data.userHome) {
 
 140       OSM.home = application_data.userHome;
 
 144   if (application_data.location) {
 
 145     OSM.location = application_data.location;
 
 149     .attr("title", I18n.t("javascripts.site.edit_disabled_tooltip"));