Skip to content

Commit

Permalink
add getSlidePath API method, update URL tests to work with new replac…
Browse files Browse the repository at this point in the history
…eState throttle
  • Loading branch information
hakimel committed Mar 9, 2022
1 parent 2a239ae commit 3786133
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions js/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,9 @@ export default function( revealElement, options ) {
// Helper method, retrieves query string as a key:value map
getQueryHash: Util.getQueryHash,

// Returns the path to the current slide as represented in the URL
getSlidePath: location.getHash.bind( location ),

// Returns reveal.js DOM elements
getRevealElement: () => revealElement,
getSlidesElement: () => dom.slides,
Expand Down
20 changes: 10 additions & 10 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,38 +341,38 @@ <h1>4</h1>
Reveal.configure({ hash: true, fragmentInURL: false });

Reveal.slide( 2, 0 );
assert.strictEqual( window.location.hash, '#/2' );
assert.strictEqual( Reveal.getSlidePath(), '/2' );

Reveal.slide( 2, 1 );
assert.strictEqual( window.location.hash, '#/2/1' );
assert.strictEqual( Reveal.getSlidePath(), '/2/1' );

Reveal.slide( 2, 0, 1 );
assert.strictEqual( window.location.hash, '#/2' );
assert.strictEqual( Reveal.getSlidePath(), '/2' );

Reveal.slide( 2, 2, 0 );
assert.strictEqual( window.location.hash, '#/fragments3' );
assert.strictEqual( Reveal.getSlidePath(), '/fragments3' );

Reveal.slide( 2, 2, 1 );
assert.strictEqual( window.location.hash, '#/fragments3' );
assert.strictEqual( Reveal.getSlidePath(), '/fragments3' );
});

QUnit.test( 'Write (fragmentInURL: true)', function( assert ) {
Reveal.configure({ hash: true, fragmentInURL: true });

Reveal.slide( 2, 0, -1 );
assert.strictEqual( window.location.hash, '#/2' );
assert.strictEqual( Reveal.getSlidePath(), '/2' );

Reveal.slide( 2, 1, -1 );
assert.strictEqual( window.location.hash, '#/2/1' );
assert.strictEqual( Reveal.getSlidePath(), '/2/1' );

Reveal.slide( 2, 0, 1 );
assert.strictEqual( window.location.hash, '#/2/0/1' );
assert.strictEqual( Reveal.getSlidePath(), '/2/0/1' );

Reveal.slide( 2, 2, -1 );
assert.strictEqual( window.location.hash, '#/fragments3' );
assert.strictEqual( Reveal.getSlidePath(), '/fragments3' );

Reveal.slide( 2, 2, 1 );
assert.strictEqual( window.location.hash, '#/fragments3/1' );
assert.strictEqual( Reveal.getSlidePath(), '/fragments3/1' );
});

QUnit.test( 'Read', async function( assert ) {
Expand Down

0 comments on commit 3786133

Please sign in to comment.