]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/application.js
Update to rails 4.0.3
[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, object) {
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 (object) query.select = object.type + object.id;
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       args = querystring.parse(link.search.substring(1)),
65       editlink = $(link).hasClass("editlink");
66
67     delete args['node'];
68     delete args['way'];
69     delete args['relation'];
70     delete args['changeset'];
71
72     if (object && editlink) {
73       args[object.type] = object.id;
74     }
75
76     var query = querystring.stringify(args);
77     if (query) href += '?' + query;
78
79     args = {
80       lat: loc.lat,
81       lon: loc.lon || loc.lng,
82       zoom: zoom
83     };
84
85     if (layers && !editlink) {
86       args.layers = layers;
87     }
88
89     href += OSM.formatHash(args);
90
91     link.href = href;
92   });
93
94   var editDisabled = zoom < 13;
95   $('#edit_tab')
96     .tooltip({placement: 'bottom'})
97     .off('click.minzoom')
98     .on('click.minzoom', function() { return !editDisabled; })
99     .toggleClass('disabled', editDisabled)
100     .attr('data-original-title', editDisabled ?
101       I18n.t('javascripts.site.edit_disabled_tooltip') : '');
102 }
103
104 // generate a cookie-safe string of map state
105 function cookieContent(map) {
106   var center = map.getCenter().wrap();
107   return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
108 }
109
110 function escapeHTML(string) {
111   var htmlEscapes = {
112     '&': '&amp;',
113     '<': '&lt;',
114     '>': '&gt;',
115     '"': '&quot;',
116     "'": '&#x27;'
117   };
118   return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
119       return htmlEscapes[match];
120   });
121 }
122
123 function maximiseMap() {
124   $("#content").addClass("maximised");
125 }
126
127 function minimiseMap() {
128   $("#content").removeClass("maximised");
129 }
130
131 $(document).ready(function () {
132   $("#menu-icon").on("click", function(e) {
133     e.preventDefault();
134     $("header").toggleClass("closed");
135   });
136
137   $("nav.primary li a").on("click", function() {
138     $("header").toggleClass("closed");
139   });
140 });