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 queryArgs.delete("node");
52 queryArgs.delete("way");
53 queryArgs.delete("relation");
54 queryArgs.delete("changeset");
55 queryArgs.delete("note");
57 if (object && editlink) {
58 queryArgs.set(object.type, object.id);
61 const query = queryArgs.toString();
62 if (query) href += "?" + query;
66 lon: "lon" in loc ? loc.lon : loc.lng,
70 if (layers && !editlink) {
71 hashArgs.layers = layers;
74 href += OSM.formatHash(hashArgs);
79 // Disable the button group and also the buttons to avoid
80 // inconsistent behaviour when zooming
81 var editDisabled = zoom < 13;
83 .tooltip({ placement: "bottom" })
84 .tooltip(editDisabled ? "enable" : "disable")
85 .toggleClass("disabled", editDisabled)
87 .toggleClass("disabled", editDisabled);
90 $(document).ready(function () {
91 // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis
92 // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
93 Turbo.session.drive = false;
98 function updateHeader() {
99 var windowWidth = $(window).width();
101 if (windowWidth < compactWidth) {
102 $("body").removeClass("compact-nav").addClass("small-nav");
103 } else if (windowWidth < headerWidth) {
104 $("body").addClass("compact-nav").removeClass("small-nav");
106 $("body").removeClass("compact-nav").removeClass("small-nav");
111 * Chrome 60 and later seem to fire the "ready" callback
112 * before the DOM is fully ready causing us to measure the
113 * wrong sizes for the header elements - use a 0ms timeout
114 * to defer the measurement slightly as a workaround.
116 setTimeout(function () {
117 $("header").children(":visible").each(function (i, e) {
118 headerWidth = headerWidth + $(e).outerWidth();
121 $("body").addClass("compact-nav");
123 $("header").children(":visible").each(function (i, e) {
124 compactWidth = compactWidth + $(e).outerWidth();
127 $("body").removeClass("compact-nav");
129 $("header").removeClass("text-nowrap");
130 $("header nav.secondary > ul").removeClass("flex-nowrap");
134 $(window).resize(updateHeader);
135 $(document).on("turbo:render", updateHeader);
138 $("#menu-icon").on("click", function (e) {
140 $("header").toggleClass("closed");
143 $("nav.primary li a").on("click", function () {
144 $("header").toggleClass("closed");
148 .attr("title", I18n.t("javascripts.site.edit_disabled_tooltip"));