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
19 const application_data = $("head").data();
21 I18n.default_locale = OSM.DEFAULT_LOCALE;
22 I18n.locale = application_data.locale;
23 I18n.fallbacks = true;
25 OSM.preferred_editor = application_data.preferredEditor;
26 OSM.preferred_languages = application_data.preferredLanguages;
28 if (application_data.user) {
29 OSM.user = application_data.user;
31 if (application_data.userHome) {
32 OSM.home = application_data.userHome;
36 if (application_data.location) {
37 OSM.location = application_data.location;
42 * Called as the user scrolls/zooms around to manipulate hrefs of the
43 * view tab and various other links
45 window.updateLinks = function (loc, zoom, layers, object) {
46 $(".geolink").each(function (index, link) {
47 let href = link.href.split(/[?#]/)[0];
48 const queryArgs = new URLSearchParams(link.search),
49 editlink = $(link).hasClass("editlink");
51 for (const arg of ["node", "way", "relation", "changeset", "note"]) {
52 queryArgs.delete(arg);
55 if (object && editlink) {
56 queryArgs.set(object.type, object.id);
59 const query = queryArgs.toString();
60 if (query) href += "?" + query;
64 lon: "lon" in loc ? loc.lon : loc.lng,
68 if (layers && !editlink) {
69 hashArgs.layers = layers;
72 href += OSM.formatHash(hashArgs);
77 // Disable the button group and also the buttons to avoid
78 // inconsistent behaviour when zooming
79 var editDisabled = zoom < 13;
81 .tooltip({ placement: "bottom" })
82 .tooltip(editDisabled ? "enable" : "disable")
83 .toggleClass("disabled", editDisabled)
85 .toggleClass("disabled", editDisabled);
88 $(document).ready(function () {
89 // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis
90 // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
91 Turbo.session.drive = false;
96 function updateHeader() {
97 var windowWidth = $(window).width();
99 if (windowWidth < compactWidth) {
100 $("body").removeClass("compact-nav").addClass("small-nav");
101 } else if (windowWidth < headerWidth) {
102 $("body").addClass("compact-nav").removeClass("small-nav");
104 $("body").removeClass("compact-nav").removeClass("small-nav");
109 * Chrome 60 and later seem to fire the "ready" callback
110 * before the DOM is fully ready causing us to measure the
111 * wrong sizes for the header elements - use a 0ms timeout
112 * to defer the measurement slightly as a workaround.
114 setTimeout(function () {
115 $("header").children(":visible").each(function (i, e) {
116 headerWidth = headerWidth + $(e).outerWidth();
119 $("body").addClass("compact-nav");
121 $("header").children(":visible").each(function (i, e) {
122 compactWidth = compactWidth + $(e).outerWidth();
125 $("body").removeClass("compact-nav");
127 $("header").removeClass("text-nowrap");
128 $("header nav.secondary > ul").removeClass("flex-nowrap");
132 $(window).resize(updateHeader);
133 $(document).on("turbo:render", updateHeader);
136 $("#menu-icon").on("click", function (e) {
138 $("header").toggleClass("closed");
141 $("nav.primary li a").on("click", function () {
142 $("header").toggleClass("closed");
146 .attr("title", I18n.t("javascripts.site.edit_disabled_tooltip"));