goto()

in js/controllers/fragments.js [290:350]


	goto( index, offset = 0 ) {

		let currentSlide = this.Reveal.getCurrentSlide();
		if( currentSlide && this.Reveal.getConfig().fragments ) {

			let fragments = this.sort( currentSlide.querySelectorAll( '.fragment:not(.disabled)' ) );
			if( fragments.length ) {

				// If no index is specified, find the current
				if( typeof index !== 'number' ) {
					let lastVisibleFragment = this.sort( currentSlide.querySelectorAll( '.fragment:not(.disabled).visible' ) ).pop();

					if( lastVisibleFragment ) {
						index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
					}
					else {
						index = -1;
					}
				}

				// Apply the offset if there is one
				index += offset;

				let changedFragments = this.update( index, fragments );

				if( changedFragments.hidden.length ) {
					this.Reveal.dispatchEvent({
						type: 'fragmenthidden',
						data: {
							fragment: changedFragments.hidden[0],
							fragments: changedFragments.hidden
						}
					});
				}

				if( changedFragments.shown.length ) {
					this.Reveal.dispatchEvent({
						type: 'fragmentshown',
						data: {
							fragment: changedFragments.shown[0],
							fragments: changedFragments.shown
						}
					});
				}

				this.Reveal.controls.update();
				this.Reveal.progress.update();

				if( this.Reveal.getConfig().fragmentInURL ) {
					this.Reveal.location.writeURL();
				}

				return !!( changedFragments.shown.length || changedFragments.hidden.length );

			}

		}

		return false;

	}