keyboard.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * This file implements the keyboard shortcuts.
  3. *
  4. * Javascript
  5. *
  6. * LICENSE:
  7. *
  8. * This file is part of PhotoShow.
  9. *
  10. * PhotoShow is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * PhotoShow is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with PhotoShow. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @package PhotoShow
  24. * @category Website
  25. * @author Thibaud Rohmer <thibaud.rohmer@gmail.com>
  26. * @copyright 2011 Thibaud Rohmer
  27. * @license http://www.gnu.org/licenses/
  28. * @link http://github.com/thibaud-rohmer/PhotoShow
  29. */
  30. $("document").ready(function(){
  31. $("body").keyup(function(event){
  32. var keyCode = event.which;
  33. if ($(event.target).is("input") || $(event.target).is("textarea"))
  34. return;
  35. if (keyCode == 0 && event.keyCode != undefined)
  36. keyCode = event.keyCode;
  37. switch(keyCode)
  38. {
  39. case $.ui.keyCode.RIGHT :
  40. if($("#image_bar #next").is(":visible")){
  41. $("#image_bar #next a").click();
  42. }
  43. event.preventDefault();
  44. break;
  45. case $.ui.keyCode.LEFT :
  46. if($("#image_bar #prev").is(":visible")){
  47. $("#image_bar #prev a").click();
  48. }
  49. event.preventDefault();
  50. break;
  51. case $.ui.keyCode.UP :
  52. if ($("#image_bar #back").is(":visible")){
  53. $("#image_bar #back").click();
  54. }else if($("#image_bar #stop").is(":visible")){
  55. $("#image_bar #stop").click();
  56. }
  57. event.preventDefault();
  58. break;
  59. case $.ui.keyCode.SPACE :
  60. if($("#image_bar #pause").is(":visible")){
  61. $("#image_bar #pause").click();
  62. }else if($("#image_bar #play").is(":visible") || $("#image_bar #slideshow").is(":visible")){
  63. $("#image_bar #play").click();
  64. }
  65. event.preventDefault();
  66. break;
  67. case $.ui.keyCode.ESCAPE :
  68. if($("#image_bar #stop").is(":visible")){
  69. $("#image_bar #stop").click();
  70. }
  71. event.preventDefault();
  72. break;
  73. }
  74. });
  75. });