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
17 //= require qs/dist/qs
20 const application_data = $("head").data();
22 I18n.default_locale = OSM.DEFAULT_LOCALE;
23 I18n.locale = application_data.locale;
24 I18n.fallbacks = true;
26 OSM.preferred_editor = application_data.preferredEditor;
27 OSM.preferred_languages = application_data.preferredLanguages;
29 if (application_data.user) {
30 OSM.user = application_data.user;
32 if (application_data.userHome) {
33 OSM.home = application_data.userHome;
37 if (application_data.location) {
38 OSM.location = application_data.location;
43 * Called as the user scrolls/zooms around to manipulate hrefs of the
44 * view tab and various other links
46 window.updateLinks = function (loc, zoom, layers, object) {
47 $(".geolink").each(function (index, link) {
48 var href = link.href.split(/[?#]/)[0],
49 args = Qs.parse(link.search.substring(1)),
50 editlink = $(link).hasClass("editlink");
55 delete args.changeset;
58 if (object && editlink) {
59 args[object.type] = object.id;
62 var query = Qs.stringify(args);
63 if (query) href += "?" + query;
67 lon: "lon" in loc ? loc.lon : loc.lng,
71 if (layers && !editlink) {
75 href += OSM.formatHash(args);
80 // Disable the button group and also the buttons to avoid
81 // inconsistent behaviour when zooming
82 var editDisabled = zoom < 13;
84 .tooltip({ placement: "bottom" })
85 .tooltip(editDisabled ? "enable" : "disable")
86 .toggleClass("disabled", editDisabled)
88 .toggleClass("disabled", editDisabled);
91 $(document).ready(function () {
92 // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis
93 // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
94 Turbo.session.drive = false;
99 function updateHeader() {
100 var windowWidth = $(window).width();
102 if (windowWidth < compactWidth) {
103 $("body").removeClass("compact-nav").addClass("small-nav");
104 } else if (windowWidth < headerWidth) {
105 $("body").addClass("compact-nav").removeClass("small-nav");
107 $("body").removeClass("compact-nav").removeClass("small-nav");
112 * Chrome 60 and later seem to fire the "ready" callback
113 * before the DOM is fully ready causing us to measure the
114 * wrong sizes for the header elements - use a 0ms timeout
115 * to defer the measurement slightly as a workaround.
117 setTimeout(function () {
118 $("header").children(":visible").each(function (i, e) {
119 headerWidth = headerWidth + $(e).outerWidth();
122 $("body").addClass("compact-nav");
124 $("header").children(":visible").each(function (i, e) {
125 compactWidth = compactWidth + $(e).outerWidth();
128 $("body").removeClass("compact-nav");
130 $("header").removeClass("text-nowrap");
131 $("header nav.secondary > ul").removeClass("flex-nowrap");
135 $(window).resize(updateHeader);
136 $(document).on("turbo:render", updateHeader);
139 $("#menu-icon").on("click", function (e) {
141 $("header").toggleClass("closed");
144 $("nav.primary li a").on("click", function () {
145 $("header").toggleClass("closed");
149 .attr("title", I18n.t("javascripts.site.edit_disabled_tooltip"));