]> git.openstreetmap.org Git - rails.git/blob - app/views/site/_resize.html.erb
Eliminate interpolation in key JS
[rails.git] / app / views / site / _resize.html.erb
1 <script type="text/javascript">
2   var brokenContentSize = $("#content").prop("offsetWidth") == 0;
3
4   function resizeContent() {
5     var content = $("#content");
6     var leftMargin = parseInt(content.css("left"));
7     var rightMargin = parseInt(content.css("right"));
8     var bottomMargin = parseInt(content.css("bottom"));
9
10     <% if t('html.dir') == "ltr" -%>
11     content.width($(window).width() - content.prop("offsetLeft") - rightMargin);
12     <% else -%>
13     content.width($(window).width() - content.prop("offsetRight") - leftMargin);
14     <% end -%>
15     content.height($(window).height() - content.prop("offsetTop") - bottomMargin);
16   }
17
18   function resizeMap() {
19     var content_width = $("#content").width();
20     var content_height = $("#content").height();
21     var sidebar_width = 0;
22     var left_border = parseFloat($("#map").css("border-left-width"));
23     var right_border = parseFloat($("#map").css("border-right-width"));
24     var top_border = parseFloat($("#map").css("border-top-width"));
25     var bottom_border = parseFloat($("#map").css("border-bottom-width"));
26
27     $("#sidebar:visible").each(function () {
28       sidebar_width = sidebar_width + $(this).outerWidth(true);
29     });
30
31     <% if t('html.dir') == "ltr" -%>
32     $("#map").css("left", (sidebar_width) + "px");
33     <% else -%>
34     $("#map").css("right", (sidebar_width) + "px");
35     <% end -%>
36     $("#map").width(content_width - sidebar_width - left_border - right_border);
37     $("#map").height(content_height - top_border - bottom_border);
38
39     <% if params[:controller] == "site" and params[:action] == "index" -%>
40     map.updateSize();
41     <% end -%>
42   }
43
44   function handleResize() {
45     if (brokenContentSize) {
46       resizeContent();
47     }
48
49     resizeMap();
50   }
51
52   $(document).ready(function () {
53     $("#sidebar").on("opened", resizeMap);
54     $("#sidebar").on("closed", resizeMap);
55   });
56 </script>