Skip to content

Commit

Permalink
Listen to row hovers on table instead of body
Browse files Browse the repository at this point in the history
This won't work for tables dynamically added to the page, but at the
moment we don't have any of those.

From the jquery docs:

  Attaching many delegated event handlers near the top of the document
  tree can degrade performance. Each time the event occurs, jQuery must
  compare all selectors of all attached events of that type to every
  element in the path from the event target up to the top of the
  document.  For best performance, attach delegated events at a document
  location as close as possible to the target elements. Avoid excessive
  use of document or document.body for delegated events on large
  documents.
  • Loading branch information
jhawthorn committed Mar 9, 2016
1 parent 289c395 commit f4b788a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/app/assets/javascripts/spree/backend/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jQuery(function($) {
});

// Highlight hovered table column
$('body').on("mouseenter", 'td.actions a, td.actions button', function(){
$('table').on("mouseenter", 'td.actions a, td.actions button', function(){
var tr = $(this).closest('tr');
var klass = 'highlight action-' + $(this).data('action')
tr.addClass(klass)
tr.prev().addClass('before-' + klass);
});
$('body').on("mouseleave", 'td.actions a, td.actions button', function(){
$('table').on("mouseleave", 'td.actions a, td.actions button', function(){
var tr = $(this).closest('tr');
var klass = 'highlight action-' + $(this).data('action')
tr.removeClass(klass)
Expand Down

0 comments on commit f4b788a

Please sign in to comment.