]> git.openstreetmap.org Git - rails.git/blobdiff - app/views/site/_resize.html.erb
Trigger map.updateSize() via a custom event
[rails.git] / app / views / site / _resize.html.erb
index 9ee05a7c83d04f713e24378c8ca524f2c29cc11d..4b312bf8c49927890a47d740a5f808df5800761b 100644 (file)
   }
 
   function resizeMap() {
-    var sidebar_width = 0 + $("#sidebar:visible").width();
+    var content_width = $("#content").width();
+    var content_height = $("#content").height();
+    var sidebar_width = 0;
+    var left_border = parseFloat($("#map").css("border-left-width"));
+    var right_border = parseFloat($("#map").css("border-right-width"));
+    var top_border = parseFloat($("#map").css("border-top-width"));
+    var bottom_border = parseFloat($("#map").css("border-bottom-width"));
 
-    if (sidebar_width > 0 && window.width > 641) {
-      sidebar_width = sidebar_width + 5
-    }
+    $("#sidebar:visible").each(function () {
+      sidebar_width = sidebar_width + $(this).outerWidth(true);
+    });
 
     <% if t('html.dir') == "ltr" -%>
     $("#map").css("left", (sidebar_width) + "px");
     <% else -%>
     $("#map").css("right", (sidebar_width) + "px");
     <% end -%>
-    $("#map").width($("#content").width() - sidebar_width);
-    if (window.width > 641) {
-      $("#map").height($("#content").height() - 2);
-    }
+    $("#map").width(content_width - sidebar_width - left_border - right_border);
+    $("#map").height(content_height - top_border - bottom_border);
+    $("#map").trigger("resized");
   }
 
   function handleResize() {
@@ -40,4 +45,9 @@
 
     resizeMap();
   }
+
+  $(document).ready(function () {
+    $("#sidebar").on("opened", resizeMap);
+    $("#sidebar").on("closed", resizeMap);
+  });
 </script>