/js/jquery.slideshow.autoplay.js

http://github.com/geraldb/s6 · JavaScript · 91 lines · 60 code · 21 blank · 10 comment · 8 complexity · ca26a49333aad69fc9d11a7d308476a2 MD5 · raw file

  1. /***********
  2. *
  3. * autoplay addon:
  4. *
  5. * - use key-a/p/s to toggle autoplay (in projection mode)
  6. */
  7. Slideshow.playInit = function()
  8. {
  9. this.debug( 'calling playInit()' );
  10. this.playInterval = null;
  11. }
  12. Slideshow.playStart = function()
  13. {
  14. this.debug( 'calling playStart()' );
  15. if( this.settings.mode == 'autoplay' )
  16. this.playToggle();
  17. }
  18. Slideshow.playKeys = function( event, key )
  19. {
  20. this.debug( 'calling playKeys()' );
  21. switch( key.which ) {
  22. case 65: //a
  23. case 80: //p
  24. case 83: //s
  25. this.playToggle();
  26. break;
  27. }
  28. }
  29. // ------------------------------------------------
  30. Slideshow.playWorker = function()
  31. {
  32. this.debug( 'calling playWorker()' );
  33. // suspend autoplay in outline view (just slideshow view)
  34. if( !this.isProjection )
  35. return;
  36. // next slide/step, please
  37. var csteps = this.steps[this.snum-1]; // current slide steps array
  38. if( !csteps || this.incpos >= csteps.length ) {
  39. if( this.snum >= this.smax )
  40. this.goTo( 1 ); // reached end of show? start with 1st slide again (for endless cycle)
  41. else
  42. this.go(1);
  43. }
  44. else {
  45. this.subgo(1);
  46. }
  47. }
  48. Slideshow.playToggle = function()
  49. {
  50. this.debug( 'calling playToggle()' );
  51. if( this.playInterval )
  52. {
  53. this.debug( 'stopping autoplay' );
  54. clearInterval( this.playInterval );
  55. this.playInterval = null;
  56. }
  57. else
  58. {
  59. this.debug( 'starting autoplay' );
  60. this.playInterval = setInterval( $.proxy( Slideshow.playWorker, this), 2000 );
  61. }
  62. }
  63. // ------------------------------------------------
  64. Slideshow.playAddEvents = function()
  65. {
  66. $( document ).on( 'slideshow.init', $.proxy( Slideshow.playInit, this ));
  67. $( document ).on( 'slideshow.start', $.proxy( Slideshow.playStart, this ));
  68. $( document ).on( 'slideshow.keys', $.proxy( Slideshow.playKeys, this ));
  69. }
  70. Slideshow.playAddEvents();