Guest User

Untitled

a guest
Feb 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. /*
  2. * js3 - javascript simple slideshow system
  3. *
  4. */
  5.  
  6.  
  7. js3 = {
  8.  
  9. "current": 0,
  10.  
  11. "init": function() {
  12. $('.slide').hide();
  13. $('#menu').hide();
  14. $('.incremental > *').hide();
  15. js3.slides = $('#slideshow > div.slide');
  16. slidecount = 0;
  17. js3.slides.each(function() {
  18. /* Append to menu */
  19. title = $(this).find('h1').html();
  20. ref = "javascript:js3.menuJumpTo("+slidecount+")";
  21. entry = "<li><a href=\""+ref+"\" title=\"Jump to slide\">"+title+"</li>"
  22. $('#menu ul').append(entry);
  23. /* Compute footnotes */
  24. fn_num = 1;
  25. $(this).find('.fn').each(function() {
  26. $(this).append('<sup>'+fn_num+'</sup>');
  27. fn_num++;
  28. });
  29. slidecount++;
  30. });
  31. js3.count = slidecount;
  32. js3.curri = 0;
  33. js3.main = $('#layout #contents');
  34. document.onkeypress = js3.keyNav;
  35. js3.showSlide();
  36. },
  37.  
  38. "currentSlide": function() {
  39. return js3.slides.eq(js3.current);
  40. },
  41.  
  42. "nthSlide": function(num) {
  43. return js3.slides.eq(num);
  44. },
  45.  
  46. "showSlide": function() {
  47. slide = js3.currentSlide();
  48. js3.main.html(slide.html());
  49. slide.find('.fn').each(function() {
  50. num = $(this).children('sup').text();
  51. title = $(this).attr('title');
  52. $('#footnotes').append("<p>"+num+": "+title+"</p>");
  53. });
  54. js3.main.addClass(slide.attr('class'));
  55. },
  56.  
  57. "flushLayout": function() {
  58. js3.main.html('').removeClass();
  59. $('#layout #footnotes').html('');
  60. },
  61.  
  62. "jumpTo": function(num) {
  63. js3.flushLayout();
  64. js3.current = num;
  65. js3.showSlide();
  66. },
  67.  
  68. "nextStep": function(force) {
  69. /* Show the next slide or the next item for incremental display */
  70. if(!force && js3.incLen() > 0) {
  71. if(js3.curri < js3.incLen()) {
  72. js3.main.find('.incremental').children().eq(js3.curri).show();
  73. js3.curri++;
  74. } else {
  75. js3.curri = 0;
  76. js3.nextStep(true);
  77. }
  78. } else if(js3.count > js3.current+1) {
  79. js3.flushLayout();
  80. js3.current += 1;
  81. js3.showSlide();
  82. }
  83. },
  84.  
  85. "prevStep": function() {
  86. if(js3.current > 0) {
  87. js3.flushLayout();
  88. js3.current -= 1;
  89. js3.curri = 0;
  90. js3.showSlide();
  91. }
  92. },
  93.  
  94. "toggleMenu": function() {
  95. $('#menu').toggle();
  96. },
  97.  
  98. "menuJumpTo": function(n) {
  99. js3.jumpTo(n);
  100. js3.toggleMenu();
  101. },
  102.  
  103. "slideTitle": function(num) {
  104. return js3.nthSlide(num).children('h1').eq(0).html();
  105. },
  106.  
  107. "incLen": function() {
  108. return js3.main.find('.incremental > *').length;
  109. },
  110.  
  111. "keyNav": function(key) {
  112. key = key || window.event;
  113. switch(key.which) {
  114. case 32: js3.nextStep(); break;
  115. case 8: js3.prevStep(); break;
  116. case 103: js3.toggleMenu(); break;
  117. }
  118. switch(key.keyCode) {
  119. case 39: js3.nextStep(); break;
  120. case 37: js3.prevStep(); break;
  121. }
  122. }
  123. };
  124.  
  125. $(function() { js3.init(); });
Add Comment
Please, Sign In to add comment