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 * Called as the user scrolls/zooms around to manipulate hrefs of the
21 * view tab and various other links
23 window.updateLinks = function (loc, zoom, layers, object) {
24 $(".geolink").each(function (index, link) {
25 var href = link.href.split(/[?#]/)[0],
26 args = Qs.parse(link.search.substring(1)),
27 editlink = $(link).hasClass("editlink");
32 delete args.changeset;
35 if (object && editlink) {
36 args[object.type] = object.id;
39 var query = Qs.stringify(args);
40 if (query) href += "?" + query;
44 lon: "lon" in loc ? loc.lon : loc.lng,
48 if (layers && !editlink) {
52 href += OSM.formatHash(args);
57 // Disable the button group and also the buttons to avoid
58 // inconsistent behaviour when zooming
59 var editDisabled = zoom < 13;
61 .tooltip({ placement: "bottom" })
62 .tooltip(editDisabled ? "enable" : "disable")
63 .toggleClass("disabled", editDisabled)
65 .toggleClass("disabled", editDisabled);
68 $(document).ready(function () {
69 // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis
70 // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
71 Turbo.session.drive = false;
76 function updateHeader() {
77 var windowWidth = $(window).width();
79 if (windowWidth < compactWidth) {
80 $("body").removeClass("compact-nav").addClass("small-nav");
81 } else if (windowWidth < headerWidth) {
82 $("body").addClass("compact-nav").removeClass("small-nav");
84 $("body").removeClass("compact-nav").removeClass("small-nav");
89 * Chrome 60 and later seem to fire the "ready" callback
90 * before the DOM is fully ready causing us to measure the
91 * wrong sizes for the header elements - use a 0ms timeout
92 * to defer the measurement slightly as a workaround.
94 setTimeout(function () {
95 $("header").children(":visible").each(function (i, e) {
96 headerWidth = headerWidth + $(e).outerWidth();
99 $("body").addClass("compact-nav");
101 $("header").children(":visible").each(function (i, e) {
102 compactWidth = compactWidth + $(e).outerWidth();
105 $("body").removeClass("compact-nav");
107 $("header").removeClass("text-nowrap");
108 $("header nav.secondary > ul").removeClass("flex-nowrap");
112 $(window).resize(updateHeader);
113 $(document).on("turbo:render", updateHeader);
116 $("#menu-icon").on("click", function (e) {
118 $("header").toggleClass("closed");
121 $("nav.primary li a").on("click", function () {
122 $("header").toggleClass("closed");
125 var application_data = $("head").data();
127 I18n.default_locale = OSM.DEFAULT_LOCALE;
128 I18n.locale = application_data.locale;
129 I18n.fallbacks = true;
131 OSM.preferred_editor = application_data.preferredEditor;
132 OSM.preferred_languages = application_data.preferredLanguages;
134 if (application_data.user) {
135 OSM.user = application_data.user;
137 if (application_data.userHome) {
138 OSM.home = application_data.userHome;
142 if (application_data.location) {
143 OSM.location = application_data.location;
147 .attr("title", I18n.t("javascripts.site.edit_disabled_tooltip"));