3 //= require jquery.timers
4 //= require jquery.cookie
5 //= require jquery.throttle-debounce
6 //= require bootstrap.tooltip
7 //= require bootstrap.dropdown
11 //= require leaflet.osm
12 //= require leaflet.map
13 //= require leaflet.zoom
14 //= require leaflet.locationfilter
15 //= require i18n/translations
19 //= require querystring
21 var querystring = require('querystring-component');
23 function zoomPrecision(zoom) {
24 return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
27 function remoteEditHandler(bbox, select) {
30 left: bbox.getWest() - 0.0001,
31 top: bbox.getNorth() + 0.0001,
32 right: bbox.getEast() + 0.0001,
33 bottom: bbox.getSouth() - 0.0001
36 if (select) query.select = select;
38 var iframe = $('<iframe>')
41 .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
42 .on('load', function() {
47 setTimeout(function () {
49 alert(I18n.t('site.index.remote_failed'));
58 * Called as the user scrolls/zooms around to maniplate hrefs of the
59 * view tab and various other links
61 function updatelinks(loc, zoom, layers, object) {
62 $(".geolink").each(function(index, link) {
63 var href = link.href.split(/[?#]/)[0],
64 args = querystring.parse(link.search.substring(1)),
65 editlink = $(link).hasClass("editlink");
67 if (object && editlink) args[object.type] = object.id;
69 var query = querystring.stringify(args);
70 if (query) href += '?' + query;
74 lon: loc.lon || loc.lng,
78 if (layers && !editlink) {
82 href += OSM.formatHash(args);
87 var editDisabled = zoom < 13;
89 .tooltip({placement: 'bottom'})
91 .on('click.minzoom', function() { return !editDisabled; })
92 .toggleClass('disabled', editDisabled)
93 .attr('data-original-title', editDisabled ?
94 I18n.t('javascripts.site.edit_disabled_tooltip') : '');
97 // generate a cookie-safe string of map state
98 function cookieContent(map) {
99 var center = map.getCenter().wrap();
100 return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
103 function escapeHTML(string) {
111 return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
112 return htmlEscapes[match];
116 function maximiseMap() {
117 $("#content").addClass("maximised");
120 function minimiseMap() {
121 $("#content").removeClass("maximised");
125 * Forms which have been cached by rails may have the wrong
126 * authenticity token, so patch up any forms with the correct
127 * token taken from the page header.
129 $(document).ready(function () {
130 var auth_token = $("meta[name=csrf-token]").attr("content");
131 $("form input[name=authenticity_token]").val(auth_token);
133 $("#menu-icon").on("click", function(e) {
135 $("header").toggleClass("closed");
138 $("nav.primary li a").on("click", function() {
139 $("header").toggleClass("closed");