]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/application.js
Stop browse routes matching user URLs
[rails.git] / app / assets / javascripts / application.js
1 //= require jquery
2 //= require jquery_ujs
3 //= require jquery.timers
4 //= require jquery.cookie
5 //= require jquery.throttle-debounce
6 //= require bootstrap.tooltip
7 //= require bootstrap.dropdown
8 //= require augment
9 //= require osm
10 //= require leaflet
11 //= require leaflet.osm
12 //= require leaflet.map
13 //= require leaflet.zoom
14 //= require leaflet.locationfilter
15 //= require i18n/translations
16 //= require oauth
17 //= require piwik
18 //= require richtext
19 //= require querystring
20
21 var querystring = require('querystring-component');
22
23 function zoomPrecision(zoom) {
24     return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
25 }
26
27 function remoteEditHandler(bbox, select) {
28   var loaded = false,
29       query = {
30           left: bbox.getWest() - 0.0001,
31           top: bbox.getNorth() + 0.0001,
32           right: bbox.getEast() + 0.0001,
33           bottom: bbox.getSouth() - 0.0001
34       };
35
36   if (select) query.select = select;
37
38   var iframe = $('<iframe>')
39     .hide()
40     .appendTo('body')
41     .attr("src", "http://127.0.0.1:8111/load_and_zoom?" + querystring.stringify(query))
42     .on('load', function() {
43       $(this).remove();
44       loaded = true;
45     });
46
47   setTimeout(function () {
48     if (!loaded) {
49       alert(I18n.t('site.index.remote_failed'));
50       iframe.remove();
51     }
52   }, 1000);
53
54   return false;
55 }
56
57 /*
58  * Called as the user scrolls/zooms around to maniplate hrefs of the
59  * view tab and various other links
60  */
61 function updatelinks(loc, zoom, layers, object) {
62   $(".geolink").each(function(index, link) {
63     var href = link.href.split(/[?#]/)[0],
64       editlink = $(link).hasClass("editlink");
65
66     if (object && editlink) {
67       href += '?' + object.type + '=' + object.id;
68     }
69
70     var args = {
71       lat: loc.lat,
72       lon: loc.lon || loc.lng,
73       zoom: zoom
74     };
75
76     if (layers && !editlink) {
77       args.layers = layers;
78     }
79
80     href += OSM.formatHash(args);
81
82     link.href = href;
83   });
84
85   var editDisabled = zoom < 13;
86   $('#edit_tab')
87     .tooltip({placement: 'bottom'})
88     .off('click.minzoom')
89     .on('click.minzoom', function() { return !editDisabled; })
90     .toggleClass('disabled', editDisabled)
91     .attr('data-original-title', editDisabled ?
92       I18n.t('javascripts.site.edit_disabled_tooltip') : '');
93 }
94
95 // generate a cookie-safe string of map state
96 function cookieContent(map) {
97   var center = map.getCenter().wrap();
98   return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
99 }
100
101 function escapeHTML(string) {
102   var htmlEscapes = {
103     '&': '&amp;',
104     '<': '&lt;',
105     '>': '&gt;',
106     '"': '&quot;',
107     "'": '&#x27;'
108   };
109   return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
110       return htmlEscapes[match];
111   });
112 }
113
114 function maximiseMap() {
115   $("#content").addClass("maximised");
116 }
117
118 function minimiseMap() {
119   $("#content").removeClass("maximised");
120 }
121
122 $(document).ready(function () {
123   $("#menu-icon").on("click", function(e) {
124     e.preventDefault();
125     $("header").toggleClass("closed");
126   });
127
128   $("nav.primary li a").on("click", function() {
129     $("header").toggleClass("closed");
130   });
131 });