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.map
 
  11 //= require leaflet.zoom
 
  12 //= require leaflet.locationfilter
 
  14 //= require make-plural/cardinals
 
  19   const application_data = $("head").data();
 
  20   const locale = application_data.locale;
 
  22   OSM.i18n.defaultLocale = OSM.DEFAULT_LOCALE;
 
  23   OSM.i18n.locale = application_data.locale;
 
  25   // '-' are replaced with '_' in https://github.com/eemeli/make-plural/tree/main/packages/plurals
 
  26   const pluralizer = plurals[locale.replace(/\W+/g, "_")] || plurals[locale.split("-")[0]];
 
  28     OSM.i18n.pluralization.register(locale, (_, count) => [pluralizer(count), "other"]);
 
  31   OSM.preferred_editor = application_data.preferredEditor;
 
  32   OSM.preferred_languages = application_data.preferredLanguages;
 
  34   if (application_data.user) {
 
  35     OSM.user = application_data.user;
 
  37     if (application_data.userHome) {
 
  38       OSM.home = application_data.userHome;
 
  42   if (application_data.location) {
 
  43     OSM.location = application_data.location;
 
  48  * Called as the user scrolls/zooms around to manipulate hrefs of the
 
  49  * view tab and various other links
 
  51 window.updateLinks = function (loc, zoom, layers, object) {
 
  52   $(".geolink").each(function (index, link) {
 
  53     let href = link.href.split(/[?#]/)[0];
 
  54     const queryArgs = new URLSearchParams(link.search),
 
  55           editlink = $(link).hasClass("editlink");
 
  57     for (const arg of ["node", "way", "relation", "changeset", "note"]) {
 
  58       queryArgs.delete(arg);
 
  61     if (object && editlink) {
 
  62       queryArgs.set(object.type, object.id);
 
  65     const query = queryArgs.toString();
 
  66     if (query) href += "?" + query;
 
  70       lon: "lon" in loc ? loc.lon : loc.lng,
 
  74     if (layers && !editlink) {
 
  75       hashArgs.layers = layers;
 
  78     href += OSM.formatHash(hashArgs);
 
  83   // Disable the button group and also the buttons to avoid
 
  84   // inconsistent behaviour when zooming
 
  85   const editDisabled = zoom < 13;
 
  87     .tooltip({ placement: "bottom" })
 
  88     .tooltip(editDisabled ? "enable" : "disable")
 
  89     .toggleClass("disabled", editDisabled)
 
  91     .toggleClass("disabled", editDisabled);
 
  95   // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis
 
  96   // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
 
  97   Turbo.session.drive = false;
 
  99   const $expandedSecondaryMenu = $("header nav.secondary > ul"),
 
 100         $collapsedSecondaryMenu = $("#compact-secondary-nav > ul"),
 
 101         secondaryMenuItems = [],
 
 102         breakpointWidth = 768;
 
 103   let moreItemWidth = 0;
 
 106   OSM.csrf[($("meta[name=csrf-param]").attr("content"))] = $("meta[name=csrf-token]").attr("content");
 
 108   function updateHeader() {
 
 109     const windowWidth = $(window).width();
 
 111     if (windowWidth < breakpointWidth) {
 
 112       $("body").addClass("small-nav");
 
 113       expandAllSecondaryMenuItems();
 
 115       $("body").removeClass("small-nav");
 
 116       const availableWidth = $expandedSecondaryMenu.width();
 
 117       secondaryMenuItems.forEach(function (item) {
 
 120       let runningWidth = 0,
 
 123       for (; i < secondaryMenuItems.length; i++) {
 
 124         runningWidth += secondaryMenuItems[i][1];
 
 125         if (i < secondaryMenuItems.length - 1) {
 
 126           requiredWidth = runningWidth + moreItemWidth;
 
 128           requiredWidth = runningWidth;
 
 130         if (requiredWidth > availableWidth) {
 
 133         expandSecondaryMenuItem($(secondaryMenuItems[i][0]));
 
 135       for (; i < secondaryMenuItems.length; i++) {
 
 136         collapseSecondaryMenuItem($(secondaryMenuItems[i][0]));
 
 141   function expandAllSecondaryMenuItems() {
 
 142     secondaryMenuItems.forEach(function (item) {
 
 143       expandSecondaryMenuItem($(item[0]));
 
 147   function expandSecondaryMenuItem($item) {
 
 149       .removeClass("dropdown-item")
 
 150       .addClass("nav-link")
 
 151       .addClass(function () {
 
 152         return $(this).hasClass("active") ? "text-secondary-emphasis" : "text-secondary";
 
 154     $item.addClass("nav-item").insertBefore("#compact-secondary-nav");
 
 155     toggleCompactSecondaryNav();
 
 158   function collapseSecondaryMenuItem($item) {
 
 160       .addClass("dropdown-item")
 
 161       .removeClass("nav-link text-secondary text-secondary-emphasis");
 
 162     $item.removeClass("nav-item").appendTo($collapsedSecondaryMenu);
 
 163     toggleCompactSecondaryNav();
 
 166   function toggleCompactSecondaryNav() {
 
 167     $("#compact-secondary-nav").toggle(
 
 168       $collapsedSecondaryMenu.find("li").length > 0
 
 173    * Chrome 60 and later seem to fire the "ready" callback
 
 174    * before the DOM is fully ready causing us to measure the
 
 175    * wrong sizes for the header elements - use a 0ms timeout
 
 176    * to defer the measurement slightly as a workaround.
 
 178   setTimeout(function () {
 
 179     $expandedSecondaryMenu.find("li:not(#compact-secondary-nav)").each(function () {
 
 180       secondaryMenuItems.push([this, $(this).width()]);
 
 182     moreItemWidth = $("#compact-secondary-nav").width();
 
 186     $(window).resize(updateHeader);
 
 187     $(document).on("turbo:render", updateHeader);
 
 190   $("#menu-icon").on("click", function (e) {
 
 192     $("header").toggleClass("closed");
 
 195   $("nav.primary li a").on("click", function () {
 
 196     $("header").toggleClass("closed");
 
 200     .attr("title", OSM.i18n.t("javascripts.site.edit_disabled_tooltip"));