[jQuery] Access keys again
<div>I found this idea on a blog somewhere: when the user holds down ctrl-alt, the
accesskey's on the page are displayed over their elements. Access keys are set
by adding an accesskey attribute to the element, and used with Ctrl-{key} or
Alt-{key} depending on the browser. Good for the disabled AND power users.
Only problem is, IE won't cooperate. I've had the code detecting Ctrl-Alt and
adding the div's, but some time after that it stopped working. And with no errors. I
hate that. Can anyone see what the problem is?
I'm a Firefox and IE guy, so if anyone has suggestions about support for other
browsers let me know.
Cheers
</div><span class="sg">Blair
<span style="font-family: courier new,monospace;">
$(document).ready(function() {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $(document).keydown(function(e) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if (((e.keyCode == 16) || e.ctrlKey) && ((e.keyCode == 18) || e.altKey)) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$("[@accesskey]").each(function(i) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if ($("#"+this.accessKey).size()==0) {
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> var thisparent=this;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
var x=thisparent.offsetLeft;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> var y=thisparent.offsetTop;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> while (thisparent=thisparent.offsetParent) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if (
thisparent.offsetParent) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> x+=thisparent.offsetLeft;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> y+=thisparent.offsetTop;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$(document.body).append($.DIV({class:"accesskey",id:this.accessKey},this.accessKey));</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $("#"+this.accessKey).css({position:"absolute",top:y+"px",left:x+"px"});
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
});</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return false;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> });</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$(document).keyup(function(e) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $("#ctrl").css("display","none");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $("#alt").css("display","none");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$(".accesskey").remove();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> });</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
});</span>
</span>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/