mirror of
https://github.com/hakimel/reveal.js.git
synced 2025-08-11 00:55:01 +02:00
add 'slidechange' event that can prevent navigation #3003
This commit is contained in:
21
js/reveal.js
21
js/reveal.js
@@ -618,6 +618,8 @@ export default function( revealElement, options ) {
|
||||
dispatchPostMessage( type );
|
||||
}
|
||||
|
||||
return event;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1192,9 +1194,22 @@ export default function( revealElement, options ) {
|
||||
* @param {number} [v=indexv] Vertical index of the target slide
|
||||
* @param {number} [f] Index of a fragment within the
|
||||
* target slide to activate
|
||||
* @param {number} [o] Origin for use in multimaster environments
|
||||
* @param {number} [origin] Origin for use in multimaster environments
|
||||
*/
|
||||
function slide( h, v, f, o ) {
|
||||
function slide( h, v, f, origin ) {
|
||||
|
||||
// Dispatch an event before hte slide
|
||||
const slidechange = dispatchEvent({
|
||||
type: 'slidechange',
|
||||
data: {
|
||||
indexh: h === undefined ? indexh : h,
|
||||
indexv: v === undefined ? indexv : v,
|
||||
origin
|
||||
}
|
||||
});
|
||||
|
||||
// Abort if this slide change was prevented by an event listener
|
||||
if( slidechange.defaultPrevented ) return;
|
||||
|
||||
// Remember where we were at before
|
||||
previousSlide = currentSlide;
|
||||
@@ -1330,7 +1345,7 @@ export default function( revealElement, options ) {
|
||||
indexv,
|
||||
previousSlide,
|
||||
currentSlide,
|
||||
origin: o
|
||||
origin
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user