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