From 027ae0d5e1f314f4bb3098c685d11bfa964b9bbc Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 2 Nov 2015 09:56:47 -0500 Subject: [PATCH] show user card on click instead of hover --- lib/persona.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/persona.js b/lib/persona.js index f59a807..76c9cee 100644 --- a/lib/persona.js +++ b/lib/persona.js @@ -166,7 +166,7 @@ $(document).ready(function() { function setupHoverCards() { require(['components'], function(components) { components.get('topic') - .on('mouseover', '[component="user/picture"]', generateUserCard); + .on('click', '[component="user/picture"],[component="user/status"]', generateUserCard); }); $(window).on('action:posts.loading', function(ev, data) { @@ -176,7 +176,7 @@ $(document).ready(function() { }); } - function generateUserCard() { + function generateUserCard(ev) { var avatar = $(this), index = avatar.parents('[data-index]').attr('data-index'), data = (ajaxify.data.topics || ajaxify.data.posts)[index].user; @@ -223,15 +223,26 @@ $(document).ready(function() { } utils.makeNumbersHumanReadable(card.find('.human-readable-number')); - - card.on('mouseleave', function() { - card.fadeOut(function() { - card.remove(); - }); - }); - + setupCardRemoval(card); card.fadeIn(); }); }); + + ev.preventDefault(); + return false; + } + + function setupCardRemoval(card) { + function removeCard(ev) { + if ($(ev.target).closest('.persona-usercard').length === 0) { + card.fadeOut(function() { + card.remove(); + }); + + $(document).off('click', removeCard); + } + } + + $(document).on('click', removeCard); } }); \ No newline at end of file