Class toolbars with narrow if we detect overflow happening

Also add css rules to drop labels from toolbar buttons if needed
This commit is contained in:
Bryan Housel
2018-11-05 17:16:50 -05:00
parent 136e4556a7
commit b4119ae1ad
3 changed files with 47 additions and 7 deletions
+13 -2
View File
@@ -16,7 +16,6 @@ body {
sans-serif;
margin: 0;
padding: 0;
min-width: 768px;
color: #333;
overflow: hidden;
-ms-user-select: none;
@@ -32,7 +31,6 @@ body {
.id-container {
height: 100%;
width: 100%;
min-width: 768px;
}
#content {
@@ -609,6 +607,19 @@ button.add-note svg.icon {
}
#bar.narrow .tool-group {
width: unset;
}
#bar.narrow .spinner,
#bar.narrow button .label {
display: none;
}
#bar.narrow button .count {
border-left-width: 0;
border-right-width: 0;
}
/* Header for modals / panes
------------------------------------------------------- */
.header {
+29 -5
View File
@@ -45,13 +45,9 @@ import { uiCmd } from './cmd';
export function uiInit(context) {
// Selectors for elements that can be collapsed if they overflow
// (can't use a media query for this because it depends on sidebar width, not screen width)
var headerCollapsable = 'button > span.label';
var footerCollapsable = '';
var _initCounter = 0;
var _initCallback;
var _needWidth = {};
function render(container) {
@@ -400,7 +396,35 @@ export function uiInit(context) {
map.dimensions(mapDimensions);
ui.photoviewer.onMapResize();
// check if header or footer have overflowed
ui.checkOverflow('#bar');
ui.checkOverflow('#footer');
};
// Call checkOverflow when resizing or whenever the contents change.
ui.checkOverflow = function(selector, reset) {
if (reset) {
delete _needWidth[selector];
}
var element = d3_select(selector);
var scrollWidth = element.property('scrollWidth');
var clientWidth = element.property('clientWidth');
var needed = _needWidth[selector] || scrollWidth;
if (scrollWidth > clientWidth) { // overflow happening
element.classed('narrow', true);
if (!_needWidth[selector]) {
_needWidth[selector] = scrollWidth;
}
} else if (scrollWidth >= needed) {
element.classed('narrow', false);
}
};
return ui;
}
+5
View File
@@ -133,6 +133,11 @@ export function uiModes(context) {
.attr('class', 'label')
.text(function(mode) { return mode.title; });
// if we are adding/removing the buttons, check if toolbar has overflowed
if (buttons.enter().size() || buttons.exit().size()) {
context.ui().checkOverflow('#bar', true);
}
// update
buttons = buttons
.merge(buttonsEnter)