Is keymap currently broken in ext1 a2? - Ext JS

Hi,

I have the following very simple test case, but I can't get the keymap working when I press a or b or c in the document.

Is it currently broken or I did something stupid?

Thanks.



<html>
<head>
<script type="text/javascript" src="lib/ext/yui-utilities.js"></script>
<script type="text/javascript" src="lib/ext/ext-yui-adapter.js"></script>
<script type="text/javascript" src="lib/ext/ext-all.js"></script>
<script type="text/javascript">
Ext.EventManager.onDocumentReady(function() {
    var map = new Ext.KeyMap('container',[{
        key : "abc",
        fn : function() {alert('a, b or c was pressed');}
    }]);
}, null, true);
</script>
</head>
<body>
<div id="container">
    

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna. Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa. Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit. Quisque dolor magna, ornare sed, elementum porta, luctus in, leo.</p>
</div>
</body>
</html>
  # 2  
03-06-2007, 06:02 AM

I am assuming keys are not being routed to "container" because it doesn't have any element in it which can have the focus to receive keystrokes.
  # 3  
03-06-2007, 05:11 PM

Hi Jack,

Thanks for your reply. You're absolutely right.

Somehow the way EXT mimic traditional GUI framework makes me think that I can attach keymap to any objects :-) My bad.

What I was trying to do is to create some "global" shortcut key that will trigger some javascript callback. So it looks like the user must focus on some html elements that can generate key events for it to work.

My workaround is to use the accesskey attributes and bind them to some offscreen <a> tags. It restricts the global hotkey to have a alt modifier but I can live with that.

I'm using this shortcut to toggle the expand / collapse of the side panels.

I notice that currently LayoutRegion does not export the
collapsed
field which I use to for the toggle function.

It's not a big deal because I usually go directly to the source code for info, but for someone that mainly lookup the online doc they might miss this.

Anyway, thanks for your great work!


            function toggleRegionShowCollapse() {
                if (this.collapsed) {
                    this.expand();
                } else {
                    this.collapse();
                }
            }
  # 4  
03-06-2007, 07:26 PM

Any chance we can alternately bind the keynav to the document so we can have app-wide keynav handlers?
  # 5  
03-07-2007, 07:59 AM

I did this and everything seems to work fine.
            var documentKeyMap = new Ext.KeyMap(document, [
			    {
			        key: "q",
			        ctrl: true,
			        fn: this.showSearchDialog
			    }
			]);

你可能感兴趣的:(JavaScript,C++,c,ext,yui)