Update focus rules to failback in safari
authorEric Price <ecprice@mit.edu>
Fri, 21 Aug 2009 16:13:45 +0000 (12:13 -0400)
committerEric Price <ecprice@mit.edu>
Fri, 21 Aug 2009 16:13:45 +0000 (12:13 -0400)
svn path=/package_branches/invirt-web/ajaxterm-rebased/; revision=2760

code/static/ajaxterm/ajaxterm.js
code/templates/terminal.mako

index f1703b3..c4501b4 100644 (file)
@@ -253,8 +253,15 @@ ajaxterm.Terminal_ctor=function(id,machine_id) {
                        opt_color.attachEvent("onclick", do_color);
                        opt_paste.attachEvent("onclick", do_paste);
                }
-               $('term').onkeypress=keypress;
-               $('term').onkeydown=keydown;
+                // If tabIndex works, only grab keyboard events when terminal is focused
+                // Otherwise, grab from whole document (e.g. in Safari).
+                var focus_element = document;
+                if(typeof $('term').tabIndex != "undefined") {
+                    focus_element = $('term');
+                    focus_element.focus();
+                }
+               focus_element.onkeypress=keypress;
+               focus_element.onkeydown=keydown;
                force=true;
                timeout=window.setTimeout(update,100);
        }
index 9f1854f..320fc93 100644 (file)
@@ -21,7 +21,6 @@ ${parent.header_extra()}
 <script type="text/javascript">
 window.onload=function() {
        t=ajaxterm.Terminal("term", ${machine.machine_id});
-        $('term').focus();
 }
 </script>
 </%def>