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