Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions taxes-and-the-ultra-wealthy/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,25 +389,41 @@ let tooltip = d3.select('body').append('div')
.attr('class', 'tooltip')
.style('opacity', 0);

let tooltipContent = tooltip.append('div')
.attr('class', 'tooltip-content');

tooltip.append('div')
.attr('class', 'tooltip-close')
.html('x');

tooltip.on('click', function() {
tooltip.transition()
.duration(200)
.style('opacity', 0);
});

function showTooltip(selection, curText){
selection
.on('mouseover', function(event) {
tooltip.transition()
.duration(200)
.style('opacity', 1);
tooltip.html(curText);
tooltip.classed('active', true);
tooltipContent.html(curText);
})
.on('mousemove', function(event) {
let rect = d3.select('.tooltip').node().getBoundingClientRect();
let leftPos = event.pageX - rect.width/2;

if ((leftPos + rect.width) > window.innerWidth) { //make sure tooltip doesnt go off right side of screen
leftPos -= (leftPos + rect.width) - window.innerWidth;
}
tooltip
.style('left', `${event.pageX - rect.width/2}px`)
.style('top', `${event.pageY - rect.height - 10}px`);
})
.on('mouseout', function(d) {
tooltip.transition()
.duration(200)
.style('opacity', 0);
.style('left', `${leftPos<0 ? 0 : leftPos}px`)
.style('top', `${event.pageY - rect.height - 20}px`);
tooltip.classed('active', true);
})
.on('mouseout', closeTooltip)
.on('keydown', function(event) {
tooltip.html(curText);
let rect = d3.select('.tooltip').node().getBoundingClientRect();
Expand All @@ -417,13 +433,16 @@ function showTooltip(selection, curText){
.style('left', `${document.body.scrollLeft + boundingRect.x + boundingRect.width/2 -rect.width/2}px`)
.style('top', `${document.body.scrollTop + (boundingRect.y - boundingRect.height/2) - rect.height}px`)
.transition().duration(200).style('opacity',1);
tooltip.classed('active', true);
} else if (event.keyCode == 27) { // escape key
tooltip.transition().duration(200).style('opacity',0);
closeTooltip();
}
})
.on('focusout', function() {
tooltip.transition().duration(200).style('opacity',0);
})
.on('focusout', closeTooltip)
}
function closeTooltip() {
tooltip.transition().duration(200).style('opacity',0);
tooltip.classed('active', false);
}
function removeTooltip(selection){
selection
Expand Down
44 changes: 43 additions & 1 deletion taxes-and-the-ultra-wealthy/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ span.hint {
pointer-events: none;
text-align: center;
width: 300px;
z-index: 2;
z-index: 200;
}
.tooltip.active {
pointer-events: auto;
}
.tooltip::after, .slider-tooltip::after {
background: #FFFAF4;
Expand All @@ -159,6 +162,13 @@ span.hint {
color: var(--blue-darkest);
}

.tooltip-close {
display: none;
position: absolute;
right: 10px;
top: 5px;
}

/******************************/
/******** RANGE INPUTS ********/
/******************************/
Expand Down Expand Up @@ -1573,6 +1583,10 @@ section[game='break-the-cycle'] #cta {
width: 115%; /* goes into the margin-right */
}

section.game-body[game="file-taxes"] .controls label {
font-size: 1rem;
}

section[game='break-the-cycle'] h2 {
font-size: 1.7rem;
}
Expand Down Expand Up @@ -1616,7 +1630,35 @@ section[game='break-the-cycle'] #cta {
margin-bottom: .2rem;
}

section.overlay#share .share-block {
padding: 0 40px;
}
section.overlay#share .share-block .btn-group {
justify-content: center;
}
.share-buttons {
gap: 10px;
}
.share-block .copy-url-wrapper .share_item__btn__wrapper {
min-width: 115px;
width: auto;
}
.share_item__btn__wrapper {
width: 100%;
}
.share_item__btn__wrapper svg {
margin-right: 0.5rem;
}

.tooltip {
font-size: 1rem;
line-height: 1.4rem;
padding-top: 25px;
}
.tooltip-close {
color: #999;
font-family: sans-serif;
font-weight: bold;
display: block;
}
}