Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
[#1050] Update popover script.
Browse files Browse the repository at this point in the history
It fell out of sync with the one used by the mock up.
  • Loading branch information
brew committed Apr 25, 2017
1 parent 9dde68a commit 39d5a39
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions census/static/scripts/site/table.js
Expand Up @@ -6,12 +6,7 @@ define(['jquery', 'bootstrap', 'chroma', 'tablesorter', 'stickykit'],
naString = 'n/a',
$dataTable = $('.data-table'),
$scoreDisplay = $('.score'),
popover = $('#popover'),
popoverProps = {
title: popover.find('.popover-title'),
content: popover.find('.popover-content'),
visible: null
},
popover_tmpl = '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
tablesorterPlaceOptions = {
sortList: [[1, 0]],
headers: {
Expand Down Expand Up @@ -136,42 +131,36 @@ define(['jquery', 'bootstrap', 'chroma', 'tablesorter', 'stickykit'],

function setInteractions() {

var popovers = $('[data-toggle="popover"]');
$("[data-toggle='tooltip']").tooltip({html: true});
$('[data-toggle="popover"]').popover({
trigger: 'click',
'placement': 'bottom',
'html': true,
'show': true,
'template': popover_tmpl
});

popovers.on('click', function(e) {

var target = $(e.target.parentNode),
offset;

// in case popover already visible, it will propagate event to body
// and hide this element
if (popoverProps.visible && popoverProps.visible.is(target)) {
return true;
}

e.preventDefault();
e.stopPropagation();
$('[data-toggle="popover"]').on('click', function() {
$('[data-toggle="popover"]').not(this).popover('hide');
});

popoverProps.visible = target;
$('body').on('click', 'td.showpopover', function() {
var $this = $(this);

offset = target.offset();
// check if the one clicked is now shown
if ($this.data('popover').tip().hasClass('in')) {

popoverProps.title.html(target.attr('title'));
popoverProps.content.html(target.data('content'));
// if another was showing, hide it
if ($visiblePopover) {
$visiblePopover.popover('hide');
}

popover.css({
top: offset.top + target.height(),
left: offset.left + target.width() / 2 - popover.width() / 2,
display: 'block'
});

return false;
});
// then store reference to current popover
$visiblePopover = $this;

$('body').on('click', function() {
popoverProps.visible = null;
popover.hide();
} else { // if it was hidden, then nothing must be showing
$visiblePopover = '';
}
});

$('.filter-table').on('keyup', function() {
Expand Down

0 comments on commit 39d5a39

Please sign in to comment.