- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 608
 
Prevent default behavior on hot key combination #701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| $(tree.$container).on(event, null, key, function(evt) { | ||
| var node = tree.getActiveNode(); | ||
| handler(node); | ||
| evt.preventDefault(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more flexible to let the handler decide whether he wants to prevent default handling, stop propagation or both?
What do you think about passing evt to the handler (which may be useful in itself), The handler can then inspect the event or call methods on it.
The main use case (stopping default handling) could be made easier to implement if we return the handler's response:
return handler(node, evt);This would allow handlers to simply return false.
If you feel that this is too much burden on the handlers, then I suggest that we make the 'prevent default' behavior configurable in the plugin options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're correct. Changing handler(node) to return handler(node, evt); + handler's return false is much simpler and flexible.
One more request, a single line of comment on jquery.fancytree.hotkeys.js or on your example browser for about how to write hotkey handler function will clear this issue and much appreciated. And yes being an explicit plugin option would be good too.
Reject this change please and your answer is much better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, if you update your PR (changing the line to return handler(node, evt); and remove evt.preventDefault()), I will merge :)
Feel free to add a comment to the example as well.
As discussion on mar10#701, plugin to give `evt` to handlers, and handler can work with the `evt` object.
Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin.
As discussion on mar10#701, plugin to give `evt` to handlers, and handler can work with the `evt` object.
| 
           Hi @mar10 , Done that updated for the plugin code and example. Thanks!  | 
    
| 
           Thanks!  | 
    
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
* Prevent default behavior on hot key combination Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and not for else because the event was already handled by fancytree's hotkey plugin. * Hot key handler now receives event object together As discussion on mar10/fancytree#701, plugin to give `evt` to handlers, and handler can work with the `evt` object. * Add Ctrl+D hotkey example
Key combination stroke (like ctrl+d, ctrl+s) will trigger browser's default behavior which is expected to be prevented and because the event was already handled by Fancytree's hotkey plugin.