3 //= require jquery.throttle-debounce
 
   4 //= require js-cookie/dist/js.cookie
 
   6 //= require bootstrap-sprockets
 
   8 //= require leaflet/dist/leaflet-src
 
   9 //= require leaflet.osm
 
  10 //= require leaflet.shortbread
 
  11 //= require leaflet.maptiler
 
  12 //= require leaflet.map
 
  13 //= require leaflet.zoom
 
  14 //= require leaflet.locationfilter
 
  16 //= require make-plural/cardinals
 
  19 //= require language_selector
 
  22   const application_data = $("head").data();
 
  23   const locale = application_data.locale;
 
  25   OSM.i18n.defaultLocale = OSM.DEFAULT_LOCALE;
 
  26   OSM.i18n.locale = application_data.locale;
 
  28   // '-' are replaced with '_' in https://github.com/eemeli/make-plural/tree/main/packages/plurals
 
  29   const pluralizer = plurals[locale.replace(/\W+/g, "_")] || plurals[locale.split("-")[0]];
 
  31     OSM.i18n.pluralization.register(locale, (_, count) => [pluralizer(count), "other"]);
 
  34   OSM.preferred_editor = application_data.preferredEditor;
 
  35   OSM.preferred_languages = application_data.preferredLanguages;
 
  37   if (application_data.user) {
 
  38     OSM.user = application_data.user;
 
  40     if (application_data.userHome) {
 
  41       OSM.home = application_data.userHome;
 
  45   if (application_data.location) {
 
  46     OSM.location = application_data.location;
 
  51  * Called as the user scrolls/zooms around to manipulate hrefs of the
 
  52  * view tab and various other links
 
  54 window.updateLinks = function (loc, zoom, layers, object) {
 
  55   $(".geolink").each(function (index, link) {
 
  56     let href = link.href.split(/[?#]/)[0];
 
  57     const queryArgs = new URLSearchParams(link.search),
 
  58           editlink = $(link).hasClass("editlink");
 
  60     for (const arg of ["node", "way", "relation", "changeset", "note"]) {
 
  61       queryArgs.delete(arg);
 
  64     if (object && editlink) {
 
  65       queryArgs.set(object.type, object.id);
 
  68     const query = queryArgs.toString();
 
  69     if (query) href += "?" + query;
 
  73       lon: "lon" in loc ? loc.lon : loc.lng,
 
  77     if (layers && !editlink) {
 
  78       hashArgs.layers = layers;
 
  81     href += OSM.formatHash(hashArgs);
 
  86   // Disable the button group and also the buttons to avoid
 
  87   // inconsistent behaviour when zooming
 
  88   const editDisabled = zoom < 13;
 
  90     .tooltip({ placement: "bottom" })
 
  91     .tooltip(editDisabled ? "enable" : "disable")
 
  92     .toggleClass("disabled", editDisabled)
 
  94     .toggleClass("disabled", editDisabled);
 
  98   // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis
 
  99   // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
 
 100   Turbo.session.drive = false;
 
 102   const $expandedSecondaryMenu = $("header nav.secondary > ul"),
 
 103         $collapsedSecondaryMenu = $("#compact-secondary-nav > ul"),
 
 104         secondaryMenuItems = [],
 
 105         breakpointWidth = 768;
 
 106   let moreItemWidth = 0;
 
 109   OSM.csrf[($("meta[name=csrf-param]").attr("content"))] = $("meta[name=csrf-token]").attr("content");
 
 111   function updateHeader() {
 
 112     const windowWidth = $(window).width();
 
 114     if (windowWidth < breakpointWidth) {
 
 115       $("body").addClass("small-nav");
 
 116       expandAllSecondaryMenuItems();
 
 118       $("body").removeClass("small-nav");
 
 119       const availableWidth = $expandedSecondaryMenu.width();
 
 120       secondaryMenuItems.forEach(function (item) {
 
 123       let runningWidth = 0,
 
 126       for (; i < secondaryMenuItems.length; i++) {
 
 127         runningWidth += secondaryMenuItems[i][1];
 
 128         if (i < secondaryMenuItems.length - 1) {
 
 129           requiredWidth = runningWidth + moreItemWidth;
 
 131           requiredWidth = runningWidth;
 
 133         if (requiredWidth > availableWidth) {
 
 136         expandSecondaryMenuItem($(secondaryMenuItems[i][0]));
 
 138       for (; i < secondaryMenuItems.length; i++) {
 
 139         collapseSecondaryMenuItem($(secondaryMenuItems[i][0]));
 
 144   function expandAllSecondaryMenuItems() {
 
 145     secondaryMenuItems.forEach(function (item) {
 
 146       expandSecondaryMenuItem($(item[0]));
 
 150   function expandSecondaryMenuItem($item) {
 
 152       .removeClass("dropdown-item")
 
 153       .addClass("nav-link")
 
 154       .addClass(function () {
 
 155         return $(this).hasClass("active") ? "text-secondary-emphasis" : "text-secondary";
 
 157     $item.addClass("nav-item").insertBefore("#compact-secondary-nav");
 
 158     toggleCompactSecondaryNav();
 
 161   function collapseSecondaryMenuItem($item) {
 
 163       .addClass("dropdown-item")
 
 164       .removeClass("nav-link text-secondary text-secondary-emphasis");
 
 165     $item.removeClass("nav-item").appendTo($collapsedSecondaryMenu);
 
 166     toggleCompactSecondaryNav();
 
 169   function toggleCompactSecondaryNav() {
 
 170     $("#compact-secondary-nav").toggle(
 
 171       $collapsedSecondaryMenu.find("li").length > 0
 
 176    * Chrome 60 and later seem to fire the "ready" callback
 
 177    * before the DOM is fully ready causing us to measure the
 
 178    * wrong sizes for the header elements - use a 0ms timeout
 
 179    * to defer the measurement slightly as a workaround.
 
 181   setTimeout(function () {
 
 182     $expandedSecondaryMenu.find("li:not(#compact-secondary-nav)").each(function () {
 
 183       secondaryMenuItems.push([this, $(this).width()]);
 
 185     moreItemWidth = $("#compact-secondary-nav").width();
 
 189     $(window).resize(updateHeader);
 
 190     $(document).on("turbo:render", updateHeader);
 
 193   $("#menu-icon").on("click", function (e) {
 
 195     $("header").toggleClass("closed");
 
 198   $("nav.primary li a").on("click", function () {
 
 199     $("header").toggleClass("closed");
 
 203     .attr("title", OSM.i18n.t("javascripts.site.edit_disabled_tooltip"));
 
 205   document.addEventListener("turbo:frame-load", function (event) {
 
 206     if (event.target.id === "select_language_list") {
 
 207       const $search = $("#language_search");
 
 208       if ($search.length) {
 
 209         $search.off("input");
 
 210         $search.on("input", function () {
 
 211           const query = $(this).val().toLowerCase();
 
 212           $(".language-item").each(function () {
 
 213             const text = $(this).text().toLowerCase();
 
 214             $(this).toggle(text.indexOf(query) > -1);
 
 225   $("#select_language_dialog").on("shown.bs.modal", function () {
 
 226     $("#language_search")
 
 230     const $frame = $("#select_language_list");
 
 231     const originalSrc = new URL($frame.attr("src"), window.location.origin);
 
 233     // Set `source` query param to current page path + query string
 
 234     originalSrc.searchParams.set("source", window.location.pathname + window.location.search);
 
 236     if ($frame.attr("src") !== originalSrc.toString()) {
 
 237       $frame.attr("src", originalSrc.toString());