Skip to content

Commit

Permalink
flip tooltip when at vertical bounds
Browse files Browse the repository at this point in the history
fixes slab#851
  • Loading branch information
jhchen committed Jan 2, 2017
1 parent e6d7c3d commit 8ca2486
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
3 changes: 3 additions & 0 deletions assets/base.styl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ colorItemsPerRow = 7

.ql-tooltip
position: absolute
transform: translateY(10px)
a
cursor: pointer
text-decoration: none
.ql-tooltip.ql-flip
transform: translateY(-10px)

.ql-formats
&:after
Expand Down
7 changes: 5 additions & 2 deletions assets/bubble/tooltip.styl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ arrowWidth = 6px
background-color: backgroundColor
border-radius: 25px
color: textColor
margin-top: 10px
.ql-tooltip-arrow
border-bottom: arrowWidth solid backgroundColor
border-left: arrowWidth solid transparent
border-right: arrowWidth solid transparent
content: " "
display: block
left: 50%
margin-left: -1 * arrowWidth
position: absolute
.ql-tooltip:not(.ql-flip) .ql-tooltip-arrow
border-bottom: arrowWidth solid backgroundColor
top: -1 * arrowWidth
.ql-tooltip.ql-flip .ql-tooltip-arrow
border-top: arrowWidth solid backgroundColor
bottom: -1 * arrowWidth

.ql-tooltip.ql-editing
.ql-tooltip-editor
Expand Down
1 change: 0 additions & 1 deletion assets/snow/tooltip.styl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ tooltipMargin = 8px
border: 1px solid borderColor
box-shadow: 0px 0px 5px shadowColor
color: textColor
margin-top: 10px
padding: 5px 12px
white-space: nowrap
&::before
Expand Down
5 changes: 0 additions & 5 deletions docs/assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,6 @@ body.home .arrow .shaft {
border-top-color: #f4f5f5;
}

a.home .ql-snow .ql-tooltip.ql-out-bottom {
visibility: visible;
}

#above-container {
background-color: #f4f5f5;
position: relative;
Expand Down Expand Up @@ -715,7 +711,6 @@ a.home .ql-snow .ql-tooltip.ql-out-bottom {
}
#above-container.demo-active #demo-container .ql-editor {
overflow-y: auto;
padding-bottom: 55px;
}
#above-container.demo-active #laptop-container {
transition: bottom 500ms ease-in-out 0s;
Expand Down
18 changes: 8 additions & 10 deletions ui/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ class Tooltip {
this.boundsContainer = boundsContainer || document.body;
this.root = quill.addContainer('ql-tooltip');
this.root.innerHTML = this.constructor.TEMPLATE;
let offset = parseInt(window.getComputedStyle(this.root).marginTop);
this.quill.root.addEventListener('scroll', () => {
this.root.style.marginTop = (-1*this.quill.root.scrollTop) + offset + 'px';
this.checkBounds();
this.root.style.marginTop = (-1*this.quill.root.scrollTop) + 'px';
});
this.hide();
}

checkBounds() {
this.root.classList.toggle('ql-out-top', this.root.offsetTop <= 0);
this.root.classList.remove('ql-out-bottom');
this.root.classList.toggle('ql-out-bottom', this.root.offsetTop + this.root.offsetHeight >= this.quill.root.offsetHeight);
}

hide() {
this.root.classList.add('ql-hidden');
}
Expand All @@ -27,6 +19,7 @@ class Tooltip {
let top = reference.bottom + this.quill.root.scrollTop;
this.root.style.left = left + 'px';
this.root.style.top = top + 'px';
this.root.classList.remove('ql-flip');
let containerBounds = this.boundsContainer.getBoundingClientRect();
let rootBounds = this.root.getBoundingClientRect();
let shift = 0;
Expand All @@ -38,7 +31,12 @@ class Tooltip {
shift = containerBounds.left - rootBounds.left;
this.root.style.left = (left + shift) + 'px';
}
this.checkBounds();
if (rootBounds.bottom > containerBounds.bottom) {
let height = rootBounds.bottom - rootBounds.top;
let verticalShift = containerBounds.bottom - rootBounds.bottom - height;
this.root.style.top = (top + verticalShift) + 'px';
this.root.classList.add('ql-flip');
}
return shift;
}

Expand Down

0 comments on commit 8ca2486

Please sign in to comment.