Skip to content

Commit

Permalink
make tooltip on click instead of hover for watson-developer-cloud#59
Browse files Browse the repository at this point in the history
  • Loading branch information
JAMES ZHANG committed May 13, 2016
1 parent 653f082 commit 496c08c
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions public/js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ function allReady(thresholds, sampleText) {
originalText_template = originalTextTemplate.innerHTML,
sentenceRank_template = sentenceRankTemplate.innerHTML,
originalTextTooltip_template = originalTextTooltipTemplate.innerHTML,
originalTextLegend_template = originalTextLegendTemplate.innerHTML;
originalTextLegend_template = originalTextLegendTemplate.innerHTML,
lastSentenceID = 0;

/**
* Callback function for AJAX post to get tone analyzer data
Expand Down Expand Up @@ -253,31 +254,36 @@ function allReady(thresholds, sampleText) {
* interactions
*/
function bindOriginalTextHoverEvents() {
$('.original-text--sentence-container').hover(function(e) {
$('.original-text--sentence-container').click(function(e) {
e.stopPropagation();
var id = $(this).data('index');
app.currentHoveredOriginalSentence(this);
updateOriginalTextTooltip(id);
$originalTextTooltipContainer.removeClass('original-text--tooltip-container_hidden');
app.isHoveringOriginalText(true);
$('.original-text--sentence-container').not('[data-index="'+id+'"]').addClass('original-text--sentence-container_grayed');
}, function(e) {
$originalTextTooltipContainer.addClass('original-text--tooltip-container_hidden');
app.isHoveringOriginalText(false);
$('.original-text--sentence-container').removeClass('original-text--sentence-container_grayed');
});

$(document).scroll(function(e) {
positionOriginalTextTooltip(e);
// if we clicked on same sentence last time, then hide tooltip
if (lastSentenceID === id) {
$originalTextTooltipContainer.toggleClass('original-text--tooltip-container_hidden');
} else {
app.currentHoveredOriginalSentence(this);
updateOriginalTextTooltip(id);
$originalTextTooltipContainer.removeClass('original-text--tooltip-container_hidden');
app.isHoveringOriginalText(true);
$('.original-text--sentence-container').not('[data-index="'+id+'"]');

positionOriginalTextTooltip(e);
}
lastSentenceID = id;
});

$originalText.scroll(function(e) {
positionOriginalTextTooltip(e);
if (app.isHoveringOriginalText())
$('body').click(function(e) {
if (!$(e.target).hasClass('original-text--sentence-container')) {
$originalTextTooltipContainer.addClass('original-text--tooltip-container_hidden');
}
});

$originalText.mousemove(function(e) {
positionOriginalTextTooltip(e);
$(document).scroll(function(e) {
$originalTextTooltipContainer.addClass('original-text--tooltip-container_hidden');
});
//
$('.original-text--texts-container').scroll(function(e) {
$originalTextTooltipContainer.addClass('original-text--tooltip-container_hidden');
});
}

Expand Down

0 comments on commit 496c08c

Please sign in to comment.