]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/application.js
Build and show partial geometries for relatons
[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 function escapeHTML(string) {
101   var htmlEscapes = {
102     '&': '&amp;',
103     '<': '&lt;',
104     '>': '&gt;',
105     '"': '&quot;',
106     "'": '&#x27;'
107   };
108   return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
109       return htmlEscapes[match];
110   });
111 }
112
113 function maximiseMap() {
114   $("#content").addClass("maximised");
115 }
116
117 function minimiseMap() {
118   $("#content").removeClass("maximised");
119 }
120
121 $(document).ready(function () {
122   $("#menu-icon").on("click", function(e) {
123     e.preventDefault();
124     $("header").toggleClass("closed");
125   });
126
127   $("nav.primary li a").on("click", function() {
128     $("header").toggleClass("closed");
129   });
130 });