3 //= require jquery.timers
4 //= require jquery.throttle-debounce
5 //= require js-cookie/dist/js.cookie
7 //= require bootstrap-sprockets
9 //= require leaflet/dist/leaflet-src
10 //= require leaflet.osm
11 //= require leaflet.map
12 //= require leaflet.zoom
13 //= require leaflet.locationfilter
18 //= require qs/dist/qs
21 * Called as the user scrolls/zooms around to manipulate hrefs of the
22 * view tab and various other links
24 window.updateLinks = function (loc, zoom, layers, object) {
25 $(".geolink").each(function (index, link) {
26 var href = link.href.split(/[?#]/)[0],
27 args = Qs.parse(link.search.substring(1)),
28 editlink = $(link).hasClass("editlink");
33 delete args.changeset;
36 if (object && editlink) {
37 args[object.type] = object.id;
40 var query = Qs.stringify(args);
41 if (query) href += "?" + query;
45 lon: "lon" in loc ? loc.lon : loc.lng,
49 if (layers && !editlink) {
53 href += OSM.formatHash(args);
58 // Disable the button group and also the buttons to avoid
59 // inconsistent behaviour when zooming
60 var editDisabled = zoom < 13;
62 .tooltip({ placement: "bottom" })
63 .tooltip(editDisabled ? "enable" : "disable")
64 .toggleClass("disabled", editDisabled)
66 .toggleClass("disabled", editDisabled);
69 $(document).ready(function () {
70 // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis
71 // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
72 Turbo.session.drive = false;
77 function updateHeader() {
78 var windowWidth = $(window).width();
80 if (windowWidth < compactWidth) {
81 $("body").removeClass("compact-nav").addClass("small-nav");
82 } else if (windowWidth < headerWidth) {
83 $("body").addClass("compact-nav").removeClass("small-nav");
85 $("body").removeClass("compact-nav").removeClass("small-nav");
90 * Chrome 60 and later seem to fire the "ready" callback
91 * before the DOM is fully ready causing us to measure the
92 * wrong sizes for the header elements - use a 0ms timeout
93 * to defer the measurement slightly as a workaround.
95 setTimeout(function () {
96 $("header").children(":visible").each(function (i, e) {
97 headerWidth = headerWidth + $(e).outerWidth();
100 $("body").addClass("compact-nav");
102 $("header").children(":visible").each(function (i, e) {
103 compactWidth = compactWidth + $(e).outerWidth();
106 $("body").removeClass("compact-nav");
108 $("header").removeClass("text-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"));