Simplify sidebar/resize

Float sidebars left/right and use overflow: hidden.
Fixes a bug on Opera where mouse events propagate to
the map.
This commit is contained in:
John Firebaugh 2013-07-12 12:17:51 -07:00
parent d9f3ceed95
commit aff23d4b4b
11 changed files with 27 additions and 120 deletions

View file

@ -16,7 +16,6 @@
//= require menu //= require menu
//= require sidebar //= require sidebar
//= require richtext //= require richtext
//= require resize
//= require geocoder //= require geocoder
//= require querystring //= require querystring

View file

@ -8,10 +8,6 @@ $(document).ready(function () {
L.OSM.zoom() L.OSM.zoom()
.addTo(map); .addTo(map);
$("#small_map").on("resized", function () {
map.invalidateSize();
});
var params = $("#small_map").data(); var params = $("#small_map").data();
var object, bbox; var object, bbox;
if (params.type == "changeset") { if (params.type == "changeset") {

View file

@ -9,10 +9,6 @@ $(document).ready(function () {
L.OSM.zoom() L.OSM.zoom()
.addTo(map); .addTo(map);
$("#changeset_list_map").on("resized", function () {
map.invalidateSize();
});
var group = L.featureGroup().addTo(map); var group = L.featureGroup().addTo(map);
$("[data-changeset]").each(function () { $("[data-changeset]").each(function () {

View file

@ -30,10 +30,6 @@ $(document).ready(function () {
L.OSM.zoom() L.OSM.zoom()
.addTo(map); .addTo(map);
$("#map").on("resized", function () {
map.invalidateSize();
});
map.setView(centre, params.zoom); map.setView(centre, params.zoom);
if ($("#latitude").val() && $("#longitude").val()) { if ($("#latitude").val() && $("#longitude").val()) {

View file

@ -1,19 +1,12 @@
function maximiseMap() { function maximiseMap() {
$("#content").addClass("maximised"); $("#content").addClass("maximised");
handleResize();
} }
function minimiseMap() { function minimiseMap() {
$("#content").removeClass("maximised"); $("#content").removeClass("maximised");
handleResize();
} }
$(document).ready(function () { $(document).ready(function () {
$(window).resize(handleResize);
handleResize();
$("#search_form").submit(function () { $("#search_form").submit(function () {
$("#sidebar_title").html(I18n.t('site.sidebar.search_results')); $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
$("#sidebar_content").load($(this).attr("action"), { $("#sidebar_content").load($(this).attr("action"), {

View file

@ -51,7 +51,7 @@ $(document).ready(function () {
map.noteLayer = new L.LayerGroup({code: 'N'}); map.noteLayer = new L.LayerGroup({code: 'N'});
map.dataLayer = new L.OSM.DataLayer(null); map.dataLayer = new L.OSM.DataLayer(null);
$("#map").on("resized", function () { $("#sidebar").on("opened closed", function () {
map.invalidateSize(); map.invalidateSize();
}); });
@ -61,7 +61,8 @@ $(document).ready(function () {
L.control.locate({position: 'topright'}) L.control.locate({position: 'topright'})
.addTo(map); .addTo(map);
var sidebar = L.OSM.sidebar('#map-ui'); var sidebar = L.OSM.sidebar('#map-ui')
.addTo(map);
L.OSM.layers({ L.OSM.layers({
position: 'topright', position: 'topright',
@ -135,8 +136,6 @@ $(document).ready(function () {
addObjectToMap(params.object, map, { zoom: params.object_zoom }); addObjectToMap(params.object, map, { zoom: params.object_zoom });
} }
handleResize();
$("body").on("click", "a.set_position", setPositionLink(map)); $("body").on("click", "a.set_position", setPositionLink(map));
$("a[data-editor=remote]").click(function(e) { $("a[data-editor=remote]").click(function(e) {
@ -148,8 +147,6 @@ $(document).ready(function () {
remoteEditHandler(map.getBounds()); remoteEditHandler(map.getBounds());
} }
$(window).resize(handleResize);
$("#search_form").submit(submitSearch(map)); $("#search_form").submit(submitSearch(map));

View file

@ -1,7 +1,13 @@
L.OSM.sidebar = function(selector) { L.OSM.sidebar = function(selector) {
var control = {}, var control = {},
sidebar = $(selector), sidebar = $(selector),
current = $(); current = $(),
map;
control.addTo = function (_) {
map = _;
return control;
};
control.addPane = function(pane) { control.addPane = function(pane) {
pane pane
@ -10,25 +16,23 @@ L.OSM.sidebar = function(selector) {
}; };
control.togglePane = function(pane) { control.togglePane = function(pane) {
var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
current current
.hide() .hide()
.trigger('hide'); .trigger('hide');
if (current === pane) { if (current === pane) {
$(sidebar).hide(); $(sidebar).hide();
controlContainer.css({paddingRight: '0'});
current = $(); current = $();
} else { } else {
$(sidebar).show(); $(sidebar).show();
controlContainer.css({paddingRight: '250px'});
current = pane; current = pane;
} }
current current
.show() .show()
.trigger('show'); .trigger('show');
map.invalidateSize({pan: false, animate: false});
}; };
return control; return control;

View file

@ -1,53 +0,0 @@
function resizeContent() {
var content = $("#content");
var leftMargin = parseInt(content.css("left"));
var rightMargin = parseInt(content.css("right"));
var bottomMargin = parseInt(content.css("bottom"));
if ($("html").attr("dir") == "ltr") {
content.width($(window).width() - content.prop("offsetLeft") - rightMargin);
} else {
content.width($(window).width() - content.prop("offsetRight") - leftMargin);
}
content.height($(window).height() - content.prop("offsetTop") - bottomMargin);
}
function resizeMap() {
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"));
$("#sidebar:visible").each(function () {
sidebar_width = sidebar_width + $(this).outerWidth(true);
});
if ($("html").attr("dir") == "ltr") {
$("#map").css("left", (sidebar_width) + "px");
} else {
$("#map").css("right", (sidebar_width) + "px");
}
$("#map").width(content_width - sidebar_width - left_border - right_border);
$("#map").height(content_height - top_border - bottom_border);
$("#map").trigger("resized");
}
function handleResize() {
var brokenContentSize = $("#content").prop("offsetWidth") == 0;
if (brokenContentSize) {
resizeContent();
}
resizeMap();
}
$(document).ready(function () {
$("#sidebar").on("opened", resizeMap);
$("#sidebar").on("closed", resizeMap);
});

View file

@ -7,10 +7,6 @@ $(document).ready(function () {
L.OSM.zoom() L.OSM.zoom()
.addTo(map); .addTo(map);
$("#map").on("resized", function () {
map.invalidateSize();
});
if (OSM.home) { if (OSM.home) {
map.setView([OSM.home.lat, OSM.home.lon], 12); map.setView([OSM.home.lat, OSM.home.lon], 12);
} else { } else {

View file

@ -568,18 +568,25 @@ a.donate {
margin: 10px; margin: 10px;
} }
/* Rules for the home page */
.site-export #map,
.site-index #map,
.site-edit #map {
height: 100%;
overflow: hidden;
}
#map-ui { #map-ui {
position: absolute;
display: none; display: none;
right: 0; position: relative;
float: right;
width: 250px; width: 250px;
height: 100%; height: 100%;
background: white; background: white;
border-left: 1px solid #CCC; border-left: 1px solid #CCC;
overflow: auto; overflow: auto;
}
#map-ui {
section { section {
border-bottom: 1px solid #DDD; border-bottom: 1px solid #DDD;
padding: 15px; padding: 15px;
@ -699,11 +706,9 @@ a.donate {
#sidebar { #sidebar {
display: none; display: none;
position: absolute; position: relative;
float: left;
overflow: auto; overflow: auto;
top: 0px;
bottom: 0px;
left: 0px;
border-right: 1px solid $keyline; border-right: 1px solid $keyline;
width: 33.3333%; width: 33.3333%;
ul { ul {
@ -961,28 +966,6 @@ ul.results-list li { border-bottom: 1px solid #ccc; }
margin-bottom: $lineheight; margin-bottom: $lineheight;
} }
/* Rules for the home page */
.site-export #map,
.site-index #map {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
/* Rules for the edit page */
.site-edit #map {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
overflow: hidden;
}
/* Rules for the changeset list shown by the history tab etc */ /* Rules for the changeset list shown by the history tab etc */
#changeset_list { #changeset_list {

View file

@ -13,10 +13,10 @@
</div> </div>
</noscript> </noscript>
<div id="map"> <div id="map-ui">
</div> </div>
<div id="map-ui"> <div id="map">
</div> </div>
<iframe id="linkloader" style="display: none"> <iframe id="linkloader" style="display: none">