X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/cdd156137b746491b1b529300c9e76f7882057f3..248b5fa1aefb8c7b4ece818ad3720992f2487fe2:/app/assets/javascripts/application.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index bb6f46590..c8f188a2e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,17 +11,24 @@ //= require leaflet.zoom //= require leaflet.locationfilter //= require i18n -//= require oauth +//= require make-plural/cardinals //= require matomo //= require richtext { const application_data = $("head").data(); + const locale = application_data.locale; I18n.default_locale = OSM.DEFAULT_LOCALE; - I18n.locale = application_data.locale; + I18n.locale = locale; I18n.fallbacks = true; + // '-' are replaced with '_' in https://github.com/eemeli/make-plural/tree/main/packages/plurals + const pluralizer = plurals[locale.replace(/\W+/g, "_")] || plurals[locale.split("-")[0]]; + if (pluralizer) { + I18n.pluralization[locale] = (count) => [pluralizer(count), "other"]; + } + OSM.preferred_editor = application_data.preferredEditor; OSM.preferred_languages = application_data.preferredLanguages; @@ -76,7 +83,7 @@ window.updateLinks = function (loc, zoom, layers, object) { // Disable the button group and also the buttons to avoid // inconsistent behaviour when zooming - var editDisabled = zoom < 13; + const editDisabled = zoom < 13; $("#edit_tab") .tooltip({ placement: "bottom" }) .tooltip(editDisabled ? "enable" : "disable") @@ -85,7 +92,7 @@ window.updateLinks = function (loc, zoom, layers, object) { .toggleClass("disabled", editDisabled); }; -$(document).ready(function () { +$(function () { // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive Turbo.session.drive = false; @@ -96,8 +103,11 @@ $(document).ready(function () { breakpointWidth = 768; let moreItemWidth = 0; + OSM.csrf = {}; + OSM.csrf[($("meta[name=csrf-param]").attr("content"))] = $("meta[name=csrf-token]").attr("content"); + function updateHeader() { - var windowWidth = $(window).width(); + const windowWidth = $(window).width(); if (windowWidth < breakpointWidth) { $("body").addClass("small-nav"); @@ -172,9 +182,6 @@ $(document).ready(function () { }); moreItemWidth = $("#compact-secondary-nav").width(); - $("header").removeClass("text-nowrap"); - $("header nav.secondary > ul").removeClass("flex-nowrap"); - updateHeader(); $(window).resize(updateHeader);