Skip to content
Snippets Groups Projects
Select Git revision
  • b63f62d8c71d76303c0232b21ceefcaddf9ce909
  • main default protected
  • jw_sonar
  • v6.0.0 protected
  • bedran_exercise-list
  • ask-user-to-delete-exercises-on-duplicates
  • update-dependencies
  • jw_sonar_backup
  • add_route_assignments
  • 6.0.0-dev
  • 5.0.1
  • 5.0.0
  • 4.1.0
  • 4.0.0
  • 3.5.3
  • 3.5.2
  • 3.5.1
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.3
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.1
  • 3.0.0
29 results

UserResultExtension.ts

Blame
  • progress.js 1.98 KiB
    /**
     * Creates a visual progress bar for the presentation.
     */
    export default class Progress {
    
    	constructor( Reveal ) {
    
    		this.Reveal = Reveal;
    
    		this.onProgressClicked = this.onProgressClicked.bind( this );
    
    	}
    
    	render() {
    
    		this.element = document.createElement( 'div' );
    		this.element.className = 'progress';
    		this.Reveal.getRevealElement().appendChild( this.element );
    
    		this.bar = document.createElement( 'span' );
    		this.element.appendChild( this.bar );
    
    	}
    
    	/**
    	 * Called when the reveal.js config is updated.
    	 */
    	configure( config, oldConfig ) {
    
    		this.element.style.display = config.progress ? 'block' : 'none';
    
    	}
    
    	bind() {
    
    		if( this.Reveal.getConfig().progress && this.element ) {
    			this.element.addEventListener( 'click', this.onProgressClicked, false );
    		}
    
    	}
    
    	unbind() {
    
    		if ( this.Reveal.getConfig().progress && this.element ) {
    			this.element.removeEventListener( 'click', this.onProgressClicked, false );
    		}
    
    	}
    
    	/**
    	 * Updates the progress bar to reflect the current slide.
    	 */
    	update() {
    
    		// Update progress if enabled
    		if( this.Reveal.getConfig().progress && this.bar ) {
    
    			let scale = this.Reveal.getProgress();
    
    			// Don't fill the progress bar if there's only one slide
    			if( this.Reveal.getTotalSlides() < 2 ) {
    				scale = 0;
    			}
    
    			this.bar.style.transform = 'scaleX('+ scale +')';
    
    		}
    
    	}
    
    	getMaxWidth() {
    
    		return this.Reveal.getRevealElement().offsetWidth;
    
    	}
    
    	/**
    	 * Clicking on the progress bar results in a navigation to the
    	 * closest approximate horizontal slide using this equation:
    	 *
    	 * ( clickX / presentationWidth ) * numberOfSlides
    	 *
    	 * @param {object} event
    	 */
    	onProgressClicked( event ) {
    
    		this.Reveal.onUserInput( event );
    
    		event.preventDefault();
    
    		let slidesTotal = this.Reveal.getHorizontalSlides().length;
    		let slideIndex = Math.floor( ( event.clientX / this.getMaxWidth() ) * slidesTotal );
    
    		if( this.Reveal.getConfig().rtl ) {
    			slideIndex = slidesTotal - slideIndex;
    		}
    
    		this.Reveal.slide( slideIndex );
    
    	}
    
    
    }