<commit_before>/*	
		=========================================================================================
 		*
		*	FlipbookJS
 		*
 		=========================================================================================
		*----------------------------------------------------------------------------------------
 		*
 		*	slide animator that animates each slide leading to the target slide
 		*
 		=========================================================================================
		*
		*   author          >>  <NAME>
		* 
		*   site            >>  http://ChristopherMil.es
		*   github          >>  http://github.com/creatologist
		*
		=========================================================================================
*/

//===============================================================================================
//----------------------------------------------------------------------------------------------- DO IT

var Flipbook = function( slides ) {
	
	slides = slides.toArray().reverse();
	
	this.atSlide = 0;
	this.currentSlide = slides[0];
	
	this.slides = slides;	
	this.totalSlides = slides.length;
	
	for ( var i = 0, len = this.totalSlides; i < len; i++ ) {
		$( this.slides[i] ).attr( 'flipbookSlide', i );
	}
};

Flipbook.prototype = {
	
	flipTo : function( slideNum, duration, animationParams, finishCallback ) {
		
		if ( slideNum < this.atSlide ) slideNum -= 1;
		
		var totalSlides = slideNum - this.atSlide;
		
		var forward = true;
		if ( totalSlides < 0 ) forward = false;
		
		totalSlides = Math.abs( totalSlides );
		
		var t,
			pause = 0;
			
		if ( typeof duration == 'number' ) t = duration;
		else {
			t = duration.duration;
			pause = duration.pause;
		}
		
		var dTime = t / totalSlides;
		var delay = 0;
		
		var self = this;
		var last = false;
		
		for ( var i = 0, len = totalSlides; i < len; i++ ) {
			var n = i;
			if ( !forward ) n = -n;
			
			n = this.atSlide + n;
			
			if ( forward && i == len - 1 ) last = true;
			else if ( !forward && n == slideNum + 1 ) last = true;
			
			if ( last ) {
				$( this.slides[n] ).delay( delay + ( pause * i ) ).animate( animationParams, dTime, function() {
					if ( forward ) self.atSlide = Number( $( this ).attr( 'flipbookSlide' ) ) + 1;
					else self.atSlide = Number( $( this ).attr( 'flipbookSlide' ) );
					
					if ( finishCallback ) finishCallback();
				} );
			} else {
				$( this.slides[n] ).delay( delay + ( pause * i ) ).animate( animationParams, dTime, function() {
					if ( forward ) self.atSlide = Number( $( this ).attr( 'flipbookSlide' ) ) + 1;
					else self.atSlide = Number( $( this ).attr( 'flipbookSlide' ) );
				} );
			}
			
			
			delay += dTime;
		}
		
	}
	
};
<commit_msg>added a reset and onUpdate event listener<commit_after>/*	
		=========================================================================================
 		*
		*	FlipbookJS
 		*
 		=========================================================================================
		*----------------------------------------------------------------------------------------
 		*
 		*	slide animator that animates each slide leading to the target slide
 		*
 		=========================================================================================
		*
		*   author          >>  <NAME>
		* 
		*   site            >>  http://ChristopherMil.es
		*   github          >>  http://github.com/creatologist
		*
		=========================================================================================
*/

//===============================================================================================
//----------------------------------------------------------------------------------------------- DO IT

var Flipbook = function( slides, onUpdate ) {
	
	slides = slides.toArray().reverse();
	
	this.atSlide = 0;
	this.currentSlide = slides[0];
	
	this.slides = slides;	
	this.totalSlides = slides.length;
	
	this.onUpdate;
	
	if ( onUpdate ) this.onUpdate = onUpdate;
	
	for ( var i = 0, len = this.totalSlides; i < len; i++ ) {
		$( this.slides[i] ).attr( 'flipbookSlide', i );
	}
};

Flipbook.prototype = {
	
	reset : function( style ) {
		this.atSlide = 0;
		for ( var i = 0, len = this.totalSlides; i < len; i++ ) {
			$( this.slides[i] ).css( style );
		}
	},
	
	flipTo : function( slideNum, duration, animationParams, finishCallback ) {
		
		if ( slideNum < this.atSlide ) slideNum -= 1;
		
		var totalSlides = slideNum - this.atSlide;
		
		var forward = true;
		if ( totalSlides < 0 ) forward = false;
		
		totalSlides = Math.abs( totalSlides );
		
		var t,
			pause = 0;
			
		if ( typeof duration == 'number' ) t = duration;
		else {
			t = duration.duration;
			pause = duration.pause;
		}
		
		var dTime = t / totalSlides;
		var delay = 0;
		
		var self = this;
		var last = false;
		
		for ( var i = 0, len = totalSlides; i < len; i++ ) {
			var n = i;
			if ( !forward ) n = -n;
			
			n = this.atSlide + n;
			
			if ( forward && i == len - 1 ) last = true;
			else if ( !forward && n == slideNum + 1 ) last = true;
			
			if ( last ) {
				$( this.slides[n] ).delay( delay + ( pause * i ) ).animate( animationParams, dTime, function() {
					
					var slideIndex = Number( $( this ).attr( 'flipbookSlide' ) );
					
					if ( forward ) self.atSlide = slideIndex + 1;
					else self.atSlide = slideIndex;
					
					if ( self.onUpdate ) self.onUpdate( self.atSlide, self.slides[ self.atSlide ], self );
					
					if ( finishCallback ) finishCallback();
				} );
			} else {
				$( this.slides[n] ).delay( delay + ( pause * i ) ).animate( animationParams, dTime, function() {
					var slideIndex = Number( $( this ).attr( 'flipbookSlide' ) );
					
					if ( forward ) self.atSlide = slideIndex + 1;
					else self.atSlide = slideIndex;
					
					if ( self.onUpdate ) self.onUpdate( self.atSlide, self.slides[ self.atSlide ], self );
				} );
			}
			
			
			delay += dTime;
		}
		
	}
	
};

{'fraction_non_alphanumeric': 0.33214829862874556, 'fraction_numerical': 0.004401557474183172, 'mean_word_length': 2.2248908296943233, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2523613', 'n_tokens_mistral': 2109, 'n_tokens_neox': 1668, 'n_words': 425}