Bug Tracker

Modify

Ticket #7852 (closed bug: wontfix)

Opened 2 years ago

Last modified 2 years ago

Problem of Adding same Event listener Hanlder

Reported by: anonymous Owned by:
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.2
Keywords: Cc:
Blocking: Blocked by:

Description

jQuery 1.4.2 line 1663-1664:

      // Add the function to the element's handler list
      handlers.push( handleObj );

to

      // Add the function to the element's handler list
      var handle_exists = false;
      for (var i = 0; i < handlers.length; ++i) {
        if (handlers[i].guid == handleObj.guid) {
          handle_exists = true;
        }
      }
      if (handle_exists == false) {
        handlers.push( handleObj );
      }

I guess, This jQuery(>=1.4.2)'s problem is caused by changing type of handlers object to array, line 1639.

Change History

comment:1 Changed 2 years ago by anonymous

The reason to post is I want to use jquery.hotkey.js with lastest jQuery. But I faced the problem with jQuery over 1.4.2 version.

sample problem code:

<!DOCTYPE html>
<html>
  <head>
    <script src="./jquery-1.4.2.js"></script>
    <script src="./jquery.hotkeys-0.7.9.js"></script>
    <script>
      $(function() {
        function output() { console.log(this); }
        $(document.body).bind('keydown', 'j', output);
        $(document.body).bind('keydown', 'k', output);
      });
    </script>
  </head>
  <body></body>
</html>

Opening this and pressing 'j' or 'k', JS console gets document.body three times. To suspend code to the last post one, JS console gets once.

comment:2 Changed 2 years ago by snover

  • Status changed from new to closed
  • Resolution set to wontfix

This is, unfortunately, intentional. The same handler can be bound multiple times with different eventData.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.