I think what you're doing is interesting, however I dont think it has a place in jquery's core. Also, my advice would be to change the arg var type from a string with all that syntax-y cruft to an object.
var handler_rules_obj = { keypress: { set : ['ctrl','shift','z'] } }; $(...).bind(handler_rules_obj, function() { ... do redo ... }) On Tue, Jan 5, 2010 at 5:50 PM, Mark Gibson <jollyt...@gmail.com> wrote: > It may be easy enough for simple, single key presses. When modifiers > are involved it starts to complicate things. > Also a lot of people forget to check for modifiers. For example, you > may not want Ctrl+Up to act in the same way as Up on its own, but a > lot of key press handler code neglects to ensure Up and only Up has > been pressed... > > if ( event.keyCode === $.ui.keyCode.UP ) > ... should really have been ... > if ( event.keyCode === $.ui.keyCode.UP && !(event.metaKey || > event.shiftKey || event.altKey) ) > > > Imagine the standard redo key combo ( Ctrl+Shift+Z ), would you rather see > ... > > $(...).bind('keypress', function(event) { > if ( event.metaKey && event.shiftKey && !event.altKey && > event.keyCode === 90 ) { > ... do redo ... > } > }) > > or > > $(...).bind('keypress.key:ctrl-shift-z', function() { > ... do redo ... > }) > > Using namespace bindings like this also gives you the ability to > unbind individual key combos, with the above example I could do > this... > > $(...).unbind('keypress.key:ctrl-shift-z') > > > 2010/1/4 ajpiano <ajpi...@gmail.com>: > > This strikes me as almost a little bit too much sugar...to streamline > > this type of binding/filtering, I tend to think it might just be > > easier to perhaps use the jQuery.ui.keyCode object and move that into > > core, perhaps? I think the idea is to save people needing to do the > > keycode lookups, not necessarily complicate the event binding syntax. > > > > On Jan 2, 7:57 pm, Mark Gibson <jollyt...@gmail.com> wrote: > >> I guess it would be possible to initialize the codes array the first > >> time it was needed by the combo function, I've never tried profiling > >> the code so I don't know if it would really give us much advantage. > >> After a quick glance over the code (it's been a while since i've > >> looked at it), it may indeed make sense to do that as all that > >> initialization would then only happen if a key press occurred on an > >> element bound using the "key:..." namespace. > >> > >> I've pushed the idea to a new branch (completely untested): > http://github.com/jollytoad/jquery.keys/blob/ondemand/src/keys.core.js > >> > >> 2010/1/2 Jeremy Chone <jeremy.ch...@gmail.com>: > >> > >> > >> > >> > Thanks Mark, your plugin looks interesting. Do you think it would be > >> > possible to do kc(...) initialization on demand? > >> > >> > On Jan 2, 1:17 am, Mark Gibson <jollyt...@gmail.com> wrote: > >> >> Hi Jeremy, > >> >> I created a plugin a while ago, very similar to what you are > >> >> suggesting, it will only work with jQuery 1.4 though as it uses the > >> >> special event registration hooks. > >> > >> >>http://github.com/jollytoad/jquery.keys/blob/master/src/keys.core.js > >> > >> >> - Mark Gibson > >> > >> >> 2010/1/1 Jeremy Chone <jeremy.ch...@gmail.com>: > >> > >> >> > Hi, > >> > >> >> > Any thought has been given on adding filter on event. For example > >> > >> >> > a) Called when enter will be pressed. > >> > >> >> > $("#myTextInputField").bind("keypress:enter",function(e){...}); > >> > >> >> > b) Called when a digit is pressed. > >> > >> >> > $("#myTextInputField").bind("keypress:0-9",function(e){...}); > >> > >> >> > c) Called when mouseenter with the key shift is pressed > >> > >> >> > $("#myTextInputField").bind("mouseenter:shift",function(e){...}); > >> > >> >> > d) Called when mouseenter with the keys shift and ctrl are pressed > >> > >> >> > > $("#myTextInputField").bind("mouseenter:shift&ctrl",function(e){...}); > >> > >> >> > I am not sure this would be the right notation, but it will > definitely > >> >> > simplify some code and make it less error prone. > >> > >> >> > Jeremy, > >> > >> >> > -- > >> > >> >> > You received this message because you are subscribed to the Google > Groups "jQuery Development" group. > >> >> > To post to this group, send email to jquery-...@googlegroups.com. > >> >> > To unsubscribe from this group, send email to > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > . > >> >> > For more options, visit this group athttp:// > groups.google.com/group/jquery-dev?hl=en. > >> > >> > -- > >> > >> > You received this message because you are subscribed to the Google > Groups "jQuery Development" group. > >> > To post to this group, send email to jquery-...@googlegroups.com. > >> > To unsubscribe from this group, send email to > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > . > >> > For more options, visit this group athttp:// > groups.google.com/group/jquery-dev?hl=en. > > > > -- > > > > You received this message because you are subscribed to the Google Groups > "jQuery Development" group. > > To post to this group, send email to jquery-...@googlegroups.com. > > To unsubscribe from this group, send email to > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > . > > For more options, visit this group at > http://groups.google.com/group/jquery-dev?hl=en. > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "jQuery Development" group. > To post to this group, send email to jquery-...@googlegroups.com. > To unsubscribe from this group, send email to > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/jquery-dev?hl=en. > > > >--
You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.