Browse Source

Fixed another bug related to overflowing contents (#459)

v3_develop
jos 10 years ago
parent
commit
60e0525187
3 changed files with 15 additions and 7 deletions
  1. +1
    -1
      lib/timeline/component/css/item.css
  2. +13
    -5
      lib/timeline/component/item/RangeItem.js
  3. +1
    -1
      test/timeline.html

+ 1
- 1
lib/timeline/component/css/item.css View File

@ -47,7 +47,6 @@
border-style: solid; border-style: solid;
border-radius: 2px; border-radius: 2px;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden;
} }
.vis.timeline .item.background { .vis.timeline .item.background {
@ -62,6 +61,7 @@
.vis.timeline .item.range .content { .vis.timeline .item.range .content {
position: relative; position: relative;
display: inline-block; display: inline-block;
max-width: 100%;
overflow: hidden; overflow: hidden;
} }

+ 13
- 5
lib/timeline/component/item/RangeItem.js View File

@ -103,8 +103,12 @@ RangeItem.prototype.redraw = function() {
this.overflow = window.getComputedStyle(dom.content).overflow !== 'hidden'; this.overflow = window.getComputedStyle(dom.content).overflow !== 'hidden';
// recalculate size // recalculate size
// turn off max-width to be able to calculate the real width
// this causes an extra browser repaint/reflow, but so be it
this.dom.content.style.maxWidth = 'none';
this.props.content.width = this.dom.content.offsetWidth; this.props.content.width = this.dom.content.offsetWidth;
this.height = this.dom.box.offsetHeight; this.height = this.dom.box.offsetHeight;
this.dom.content.style.maxWidth = '';
this.dirty = false; this.dirty = false;
} }
@ -175,7 +179,7 @@ RangeItem.prototype.repositionX = function() {
else { else {
this.left = start; this.left = start;
this.width = boxWidth; this.width = boxWidth;
contentWidth = Math.min(end - start, this.props.content.width);
contentWidth = Math.min(end - start - 2 * this.options.padding, this.props.content.width);
} }
this.dom.box.style.left = this.left + 'px'; this.dom.box.style.left = this.left + 'px';
@ -195,15 +199,19 @@ RangeItem.prototype.repositionX = function() {
break; break;
default: // 'auto' default: // 'auto'
// when range exceeds left of the window, position the contents at the left of the visible area
if (this.overflow) { if (this.overflow) {
// when range exceeds left of the window, position the contents at the left of the visible area
contentLeft = Math.max(-start, 0);
if (end > 0) {
contentLeft = Math.max(-start, 0);
}
else {
contentLeft = -contentWidth; // ensure it's not visible anymore
}
} }
else { else {
// when range exceeds left of the window, position the contents at the left of the visible area
if (start < 0) { if (start < 0) {
contentLeft = Math.min(-start, contentLeft = Math.min(-start,
(end - start - this.props.content.width - 2 * this.options.padding));
(end - start - contentWidth - 2 * this.options.padding));
// TODO: remove the need for options.padding. it's terrible. // TODO: remove the need for options.padding. it's terrible.
} }
else { else {

+ 1
- 1
test/timeline.html View File

@ -75,7 +75,7 @@
'<div onclick="alert(\'you clicked a div\'); ">Click here! (div)</div>', start: now.clone().add(-2, 'days').toDate() }, '<div onclick="alert(\'you clicked a div\'); ">Click here! (div)</div>', start: now.clone().add(-2, 'days').toDate() },
{_id: 3, content: 'item 3', start: now.clone().add(2, 'days').toDate(), style: 'color: red;'}, {_id: 3, content: 'item 3', start: now.clone().add(2, 'days').toDate(), style: 'color: red;'},
{ {
_id: 4, content: 'item 4 ',
_id: 4, content: 'item 4 foo bar foo bar foo bar foo bar foo bar',
start: now.clone().add(0, 'days').toDate(), start: now.clone().add(0, 'days').toDate(),
end: now.clone().add(7, 'days').toDate(), end: now.clone().add(7, 'days').toDate(),
title: 'hello title!' title: 'hello title!'

Loading…
Cancel
Save