Need menu to dropdown using keyboard

Need menu to dropdown using keyboard

First let me say, I'm new to jQuery and its been a while since I've done anything with Javascript.  Second, this isn't my code, I came into the project a couple of months ago and trying to figure out what goes with what.

What do I need to do so that when someone tabs into the menu it will drop down just like it does when you mouseover it?  Is this even possible?

  1. if(ie === "1") {
  2. if($(window).width() > 949) {
  3. $.fn.pause = function (a) {
  4. $(this).stop().animate({
  5. dummy: 1
  6. }, a);
  7. return this
  8. };

  9. function mouseleft() {
  10. $("#buttonbar").triggerHandler("mouseleave")
  11. }
  12. $(document).ready(function () {
  13. $("#buttonbar").mouseenter(function () {
  14. $(this).stop().pause(160).animate({
  15. height: "12.7em"
  16. }, 400, "easeOutQuart")
  17. }).mouseleave(function () {
  18. $(this).stop().pause(160).animate({
  19. height: "2.2em"
  20. }, 400, "easeOutQuart")
  21. });
  22. });
  23. $(function () {
  24. $("#accordion").accordion({
  25. fillSpace: !0,
  26. icons: {
  27. header: "accordion-header",
  28. headerSelected: "accordion-headerselected"
  29. }
  30. })
  31. });
  32. if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
  33. $("#buttonbar li").bind('touchstart', function () {
  34. console.log("touch started");
  35. });
  36. $("#buttonbar li").bind('touchend', function () {
  37. console.log("touch ended");
  38. });
  39. } else {
  40. $("#accordion").accordion({
  41. active: false
  42. });
  43. }
  44. }

  45. function showElement(d) {
  46. var s = document.getElementById(d).style;
  47. if($(window).width() < 950) {
  48. if(s.display != "block") {
  49. s.display = "block";
  50. } else {
  51. s.display = "none";
  52. }
  53. if($(window).width() > 949) {
  54. if(s.display != "block") {
  55. s.display = "block";
  56. }
  57. }
  58. }
  59. }

  60. function showHide() {
  61. var s = document.getElementById("buttonbar").style;
  62. if($(window).width() > 949) {
  63. s.display = "block";
  64. document.getElementById("prospective-links").style.display = "block";
  65. document.getElementById("current-links").style.display = "block";
  66. document.getElementById("academic-links").style.display = "block";
  67. document.getElementById("facstaff-links").style.display = "block";
  68. document.getElementById("parent-links").style.display = "block";
  69. document.getElementById("alumni-links").style.display = "block";
  70. document.getElementById("visitor-links").style.display = "block";
  71. $("#accordion").accordion('destroy');
  72. $("#buttonbar").unbind('mouseenter');
  73. $("#buttonbar").unbind('mouseleave');
  74. $.fn.pause = function (a) {
  75. $(this).stop().animate({
  76. dummy: 1
  77. }, a);
  78. return this
  79. };

  80. function mouseleft() {
  81. $("#buttonbar").triggerHandler("mouseleave")
  82. }
  83. $(document).ready(function () {
  84. $("#buttonbar").mouseenter(function () {
  85. $(this).stop().pause(160).animate({
  86. height: "12.7em"
  87. }, 400, "easeOutQuart")
  88. }).mouseleave(function () {
  89. $(this).stop().pause(160).animate({
  90. height: "2.2em"
  91. }, 400, "easeOutQuart")
  92. });
  93. });
  94. $(function () {
  95. $("#accordion").accordion({
  96. fillSpace: !0,
  97. icons: {
  98. header: "accordion-header",
  99. headerSelected: "accordion-headerselected"
  100. }
  101. })
  102. });
  103. if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
  104. $("#buttonbar li").bind('touchstart', function () {
  105. console.log("touch started");
  106. });
  107. $("#buttonbar li").bind('touchend', function () {
  108. console.log("touch ended");
  109. });
  110. }
  111. } else { /*$("#accordion").accordion({active:false});*/
  112. $("#accordion").accordion('destroy');
  113. $("#buttonbar").unbind('mouseenter');
  114. $("#buttonbar").unbind('mouseleave');
  115. $("#buttonbar li").unbind('touchstart');
  116. $("#buttonbar li").unbind('touchend');
  117. s.display = "none";
  118. document.getElementById("prospective-links").style.display = "none";
  119. document.getElementById("current-links").style.display = "none";
  120. document.getElementById("academic-links").style.display = "none";
  121. document.getElementById("facstaff-links").style.display = "none";
  122. document.getElementById("parent-links").style.display = "none";
  123. document.getElementById("alumni-links").style.display = "none";
  124. document.getElementById("visitor-links").style.display = "none"; /*$("#buttonbar").accordion('destroy');*/
  125. }
  126. }
  127. $(window).resize(showHide);
  128. //Run when resized 
  129. jQuery(function ($) {
  130. var path = location.pathname.substring(1);
  131. $('#nav a[href$="' + path + '"]').addClass('active');
  132. }); // This section makes the skip to anchor links such as the skip to content link work in webkit browsers like Chrome and Safari 
  133. (function (linkList, i, URI) {
  134. if( !! (URI = document.documentURI)) {
  135. URI = URI.split('#')[0];
  136. document.addEventListener("DOMContentLoaded", function () {
  137. document.removeEventListener("DOMContentLoaded", arguments.callee, false);
  138. linkList = document.links;
  139. for(i in linkList) {
  140. if( !! linkList[i].hash) {
  141. if(linkList[i].hash.match(/^#./)) {
  142. if((URI + linkList[i].hash) == linkList[i].href) {
  143. linkList[i].addEventListener("click", function (e, f, g) {
  144. f = document.getElementById(this.hash.slice(1));
  145. if(!(g = f.getAttribute('tabIndex'))) f.setAttribute('tabIndex', - 1);
  146. f.focus();
  147. if(!g) f.removeAttribute('tabIndex');
  148. }, false);
  149. }
  150. }
  151. }
  152. }
  153. }, false);
  154. }
  155. return true;
  156. })();
  157. } else {
  158. function showElement(d) {
  159. var s = document.getElementById(d).style;
  160. if(s.display != "block") {
  161. s.display = "block";
  162. } else {
  163. s.display = "none";
  164. }
  165. };
  166. }; 

  1. <div id="buttonbar">
    <ul id="bar">
      <li id="prospective" class="rightborder"><a href="#">Top Menu Item 1</a>
        <ul id="prospective-links">
          <li><a href="#">Sub Menu Item 1</a></li>
          <li><a href="#">Sub Menu Item 2</a></li>
       </ul>
      </li>
      <li id="students" class="rightborder"><a href="#">Top Menu Item 2</a>
         <ul id="current-links" id="prospective-links">
            <li><a href="#">Sub Menu Item 1</a></li>
            <li><a href="#">Sub Menu Item 2</a></li>
         </ul>
       </li>
    ............
    </ul>
    </div>















I can provide the css if needed.



[moderator reformatted]