agungprasetyosakti / js-hotkeys

Automatically exported from code.google.com/p/js-hotkeys
0 stars 0 forks source link

The "event.data.combi" is incorrect when I bind the same callback function with the same event type to the same element but with different keys. #55

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I binded hotkeys like this: 
  $().bind("keypress", {combi: "shift+x", disableInInput: true}, press)
    .bind("keypress", {combi: "shift+z", disableInInput: false}, press);
I wanted to get which keys-combination is pressed in the function "press", 
and then do something, tested like this: 
  alert(event.data.combi + " - " + event.data.disableInInput);
But the result was always "shift+z - false" whatever I pressed. 

After checking the code of jquery.js, I found that I have bind the same 
function with the same event type to the same element, thus the earlier 
one has been "overrided" by the later one although the parameters are 
different. That is logical. 

But, actually, events are binded like this: 
  this.__bind__(handle.join(' '), data, hotkeys.handler);
The only function "hotkeys.handler" will handle the different keys-
combinations and call back functions. But the parameter "data" is 
unnecessary and inaccurate sometimes, since datas are stored 
in "hotkeys.triggersMap". 

I have tried to change code like this: 
  this.__bind__(handle.join(' '), /*data, */hotkeys.handler);
and change "event.date" in "hotkeys.handler"(before "// call the 
registered callback function") like this: 
  event.data = {
    combi: code, // just for test
    disableInInput: trigger[x].disableInInput
  };
then "event.data" will be correct when I press different keys. 

I will attach my demo, anybody can test it, and you can compare 
the "jquery.hotkeys.js" to the original code to find what I have changed. 

By the way, hotkeys is really a useful pugin, I like it, and I hope this 
will be helpful. 

Original issue reported on code.google.com by jessige...@gmail.com on 24 Apr 2009 at 5:00

Attachments:

GoogleCodeExporter commented 8 years ago
that's great. 
The only problem with your solution is that 'combi' holds the keyCode (of 'x' 
instead
of the combination (e.g. 'ctrl+x').
I'll see how to merge this anyway.
thanks

Original comment by Afro.Sys...@gmail.com on 3 May 2009 at 7:59

GoogleCodeExporter commented 8 years ago
yeah, my code is for test only, I think you can perfect it. 
I like "hotkeys", thus I thank you very much! 

Original comment by jessige...@gmail.com on 3 May 2009 at 11:59

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Try This:

<html>
    <head>
        <script src="jquery-1.3.2.min.js"></script>
        <script src="jquery.hotkeys.js"></script>
    </head>

    <body>
        <script>            
            $(document).ready(function(){
                jQuery(document).bind('keydown', 'ctrl+s',function (evt){
                    alert(evt.data.combi);
                    return false;
                });
                jQuery(document).bind('keydown', 'ctrl+x',function (evt){
                    alert(evt.data.combi);
                    return false;
                });
            });

        </script>
    </body></html>

Original comment by Afro.Sys...@gmail.com on 3 May 2009 at 12:11

GoogleCodeExporter commented 8 years ago
? It alerts "ctrl+x" always. 

Original comment by jessige...@gmail.com on 3 May 2009 at 12:20

GoogleCodeExporter commented 8 years ago
you are right. my mistake ;-(

Original comment by Afro.Sys...@gmail.com on 3 May 2009 at 12:33

GoogleCodeExporter commented 8 years ago
hehe, come on~~

Original comment by jessige...@gmail.com on 3 May 2009 at 12:39

GoogleCodeExporter commented 8 years ago
Hi, I am waitting for the new version :)

Original comment by jessige...@gmail.com on 13 Jun 2009 at 5:19

GoogleCodeExporter commented 8 years ago
Anything new with this ? I'm in dire need for this to work =P
I cant do separate callbacks as a workaround as its being dynamically depending 
on
some other variables done =( 

Original comment by erik.ellis@gmail.com on 11 Jan 2010 at 1:35

GoogleCodeExporter commented 8 years ago
expecting ....

Original comment by jessige...@gmail.com on 14 Jan 2010 at 3:15

GoogleCodeExporter commented 8 years ago
I am getting the same error - is this fixed?

Original comment by rensohol...@gmail.com on 21 Dec 2010 at 6:00