Przeglądaj źródła

additional auto-animate tests

Hakim El Hattab 5 lat temu
rodzic
commit
ac59dcb525
2 zmienionych plików z 23 dodań i 4 usunięć
  1. 5 4
      js/reveal.js
  2. 18 0
      test/test-auto-animate.html

+ 5 - 4
js/reveal.js

@@ -3866,7 +3866,6 @@
 			// Create a new auto-animate sheet
 			autoAnimateStyleSheet = autoAnimateStyleSheet || document.createElement( 'style' );
 			autoAnimateStyleSheet.type = 'text/css';
-			autoAnimateStyleSheet.className = 'auto-animate-styes';
 			document.head.appendChild( autoAnimateStyleSheet );
 
 			var slideOptions = getAutoAnimateOptions( toSlide, {
@@ -3904,10 +3903,12 @@
 
 			// Start the animation next cycle
 			requestAnimationFrame( function() {
-				// This forces our newly injected styles to be applied in Firefox
-				getComputedStyle( autoAnimateStyleSheet ).fontWeight;
+				if( autoAnimateStyleSheet ) {
+					// This forces our newly injected styles to be applied in Firefox
+					getComputedStyle( autoAnimateStyleSheet ).fontWeight;
 
-				toSlide.dataset.autoAnimate = 'running';
+					toSlide.dataset.autoAnimate = 'running';
+				}
 			} );
 
 		}

+ 18 - 0
test/test-auto-animate.html

@@ -52,6 +52,7 @@
 
 			const slides = Array.prototype.map.call( document.querySelectorAll( '.slides section' ), slide => {
 				return {
+					slide: slide,
 					h1: slide.querySelector( 'h1' ),
 					h2: slide.querySelector( 'h2' ),
 					h3: slide.querySelector( 'h3' )
@@ -102,6 +103,23 @@
 					slides[1].h1.addEventListener( 'transitionend', callback );
 				});
 
+				QUnit.test( 'Does not add [data-auto-animate] on non auto-animated slides', assert => {
+					Reveal.slide(2);
+					Reveal.next();
+					assert.ok( slides[3].slide.hasAttribute( 'data-auto-animate' ) === false )
+				});
+
+				QUnit.test( 'autoAnimate config option', assert => {
+					Reveal.configure({ autoAnimate: false });
+
+					assert.ok( document.querySelectorAll( 'data-auto-animate-target' ).length === 0, 'Removes all [data-auto-animate-target]' )
+					assert.ok( Array.prototype.every.call( document.querySelectorAll( 'section[data-auto-animate]' ), el => {
+						return el.dataset.autoAnimate === '';
+					}, 'All data-auto-animate attributes are reset' ) );
+
+					Reveal.configure({ autoAnimate: true });
+				});
+
 			} );
 
 			Reveal.initialize();