Skip to content

Commit

Permalink
[2204] Add hover intent to description toggle
Browse files Browse the repository at this point in the history
This prevents unwanted expansion of description text when mousing over
the page.
  • Loading branch information
aron committed Apr 30, 2012
1 parent abcf0cf commit dcb2432
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions ckan/public/scripts/application.js
Expand Up @@ -1196,17 +1196,34 @@ CKAN.Utils = function($, my) {
});

relatedItems.on('mouseenter mouseleave', '.description.truncated', function (event) {
var isEnter = event.type === 'mouseenter',
description = $(this),
parent = description.parents('li:first'),
difference = description.data('height') - description.height();
var isEnter = event.type === 'mouseenter'
description = $(this)
timer = description.data('hover-intent');

description.truncate(isEnter ? 'expand' : 'collapse');
parent.toggleClass('expanded-description', isEnter);
function update() {
var parent = description.parents('li:first'),
difference = description.data('height') - description.height();

// Adjust the bottom margin of the item relative to it's current value
// to allow the description to expand without breaking the grid.
parent.css('margin-bottom', isEnter ? '-=' + difference + 'px' : '');
description.truncate(isEnter ? 'expand' : 'collapse');
parent.toggleClass('expanded-description', isEnter);

// Adjust the bottom margin of the item relative to it's current value
// to allow the description to expand without breaking the grid.
parent.css('margin-bottom', isEnter ? '-=' + difference + 'px' : '');
description.removeData('hover-intent');
}

if (!isEnter && timer) {
// User has moused out in the time set so cancel the action.
description.removeData('hover-intent');
return clearTimeout(timer);
} else if (!isEnter && !timer) {
update();
} else {
// Delay the hover action slightly to wait to see if the user mouses
// out again. This prevents unwanted actions.
description.data('hover-intent', setTimeout(update, 200));
}
});

// Add a handler for the delete buttons.
Expand Down

0 comments on commit dcb2432

Please sign in to comment.