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;
94 const breakpointWidth = 768;
96 function updateHeader() {
97 var windowWidth = $(window).width();
99 if (windowWidth < breakpointWidth) {
100 $("body").addClass("small-nav");
101 expandSecondaryMenu();
102 } else if (windowWidth < headerWidth) {
103 $("body").removeClass("small-nav");
104 collapseSecondaryMenu();
106 $("body").removeClass("small-nav");
107 expandSecondaryMenu();
111 function expandSecondaryMenu() {
112 $("#compact-secondary-nav > ul").find("li").children("a")
113 .removeClass("dropdown-item")
114 .addClass("nav-link")
115 .addClass(function () {
116 return $(this).hasClass("active") ? "text-secondary-emphasis" : "text-secondary";
118 $("#compact-secondary-nav > ul").find("li")
119 .addClass("nav-item")
120 .prependTo("header nav.secondary > ul");
121 $("#compact-secondary-nav").hide();
124 function collapseSecondaryMenu() {
125 $("header nav.secondary > ul").find("li:not(#compact-secondary-nav)").children("a")
126 .addClass("dropdown-item")
127 .removeClass("nav-link text-secondary text-secondary-emphasis");
128 $("header nav.secondary > ul").find("li:not(#compact-secondary-nav)")
129 .removeClass("nav-item")
130 .prependTo("#compact-secondary-nav > ul");
131 $("#compact-secondary-nav").show();
135 * Chrome 60 and later seem to fire the "ready" callback
136 * before the DOM is fully ready causing us to measure the
137 * wrong sizes for the header elements - use a 0ms timeout
138 * to defer the measurement slightly as a workaround.
140 setTimeout(function () {
141 $("header").children(":visible").each(function (i, e) {
142 headerWidth += $(e).outerWidth();
145 $("header").removeClass("text-nowrap");
146 $("header nav.secondary > ul").removeClass("flex-nowrap");
150 $(window).resize(updateHeader);
151 $(document).on("turbo:render", updateHeader);
154 $("#menu-icon").on("click", function (e) {
156 $("header").toggleClass("closed");
159 $("nav.primary li a").on("click", function () {
160 $("header").toggleClass("closed");
164 .attr("title", I18n.t("javascripts.site.edit_disabled_tooltip"));