您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test-state.html 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test State</title>
  6. <link rel="stylesheet" href="../dist/reveal.css">
  7. <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
  8. <script src="../node_modules/qunit/qunit/qunit.js"></script>
  9. </head>
  10. <body style="overflow: auto;">
  11. <div id="qunit"></div>
  12. <div id="qunit-fixture"></div>
  13. <div class="reveal" style="display: none;">
  14. <div class="slides">
  15. <section>No state</section>
  16. <section id="slide2" data-state="state1">State 1</section>
  17. <section data-state="state1">State 1</section>
  18. <section data-state="state2">State 2</section>
  19. <section>
  20. <section>No state</section>
  21. <section data-state="state1">State 1</section>
  22. <section data-state="state3">State 3</section>
  23. <section>No state</section>
  24. </section>
  25. <section>No state</section>
  26. </div>
  27. </div>
  28. <script src="../dist/reveal.js"></script>
  29. <script>
  30. Reveal.initialize();
  31. QUnit.module( 'State' );
  32. QUnit.test( 'Fire events when changing slide', function( assert ) {
  33. assert.expect( 2 );
  34. var state1 = assert.async();
  35. var state2 = assert.async();
  36. var _onState1 = function( event ) {
  37. assert.ok( true, 'state1 fired' );
  38. state1();
  39. }
  40. var _onState2 = function( event ) {
  41. assert.ok( true, 'state2 fired' );
  42. state2();
  43. }
  44. Reveal.on( 'state1', _onState1 );
  45. Reveal.on( 'state2', _onState2 );
  46. Reveal.slide( 1 );
  47. Reveal.slide( 3 );
  48. Reveal.off( 'state1', _onState1 );
  49. Reveal.off( 'state2', _onState2 );
  50. });
  51. QUnit.test( 'Fire state events for vertical slides', function( assert ) {
  52. assert.expect( 2 );
  53. var done = assert.async( 2 );
  54. var _onState1 = function( event ) {
  55. assert.ok( true, 'state1 fired' );
  56. done();
  57. }
  58. var _onState3 = function( event ) {
  59. assert.ok( true, 'state3 fired' );
  60. done();
  61. }
  62. Reveal.on( 'state1', _onState1 );
  63. Reveal.on( 'state3', _onState3 );
  64. Reveal.slide( 0 );
  65. Reveal.slide( 4, 1 );
  66. Reveal.slide( 4, 2 );
  67. Reveal.off( 'state1', _onState1 );
  68. Reveal.off( 'state3', _onState3 );
  69. });
  70. QUnit.test( 'No events if state remains unchanged', function( assert ) {
  71. var stateChanges = 0;
  72. var _onEvent = function( event ) {
  73. stateChanges += 1;
  74. }
  75. Reveal.on( 'state1', _onEvent );
  76. Reveal.slide( 0 ); // no state
  77. Reveal.slide( 1 ); // state1
  78. Reveal.slide( 2 ); // state1
  79. Reveal.prev(); // state1
  80. Reveal.next(); // state1
  81. Reveal.slide( 4, 1 ); // state1
  82. Reveal.slide( 0 ); // no state
  83. Reveal.off( 'state1', _onEvent );
  84. assert.strictEqual( stateChanges, 1, 'no event was fired when going to slide with same state' );
  85. });
  86. QUnit.test( 'Event order', function( assert ) {
  87. var _onEvent = function( event ) {
  88. assert.ok( Reveal.getCurrentSlide() == document.querySelector( '#slide2' ), 'correct current slide immediately after state event' );
  89. }
  90. Reveal.on( 'state1', _onEvent );
  91. Reveal.slide( 0 );
  92. Reveal.slide( 1 );
  93. Reveal.off( 'state1', _onEvent );
  94. });
  95. </script>
  96. </body>
  97. </html>