Add a framework for synchronously executed preInit and preStepLeave plugins.

This allows plugins to register to be executed at the beginning of
impress().init() and impress().goto() respectively. By returning false,
a plugin can also cancel the event.

Also adds 3 plugins that use this: rel, goto and stop.
This commit is contained in:
Henrik Ingo
2017-10-11 18:41:02 +03:00
parent 8902a0a709
commit 82ff7cbde0
8 changed files with 767 additions and 43 deletions

View File

@@ -0,0 +1,21 @@
Stop Plugin
===========
Example:
<!-- Stop at this slide.
(For example, when used on the last slide, this prevents the
presentation from wrapping back to the beginning.) -->
<div class="step stop">
The stop plugin is a pre-stepleave plugin. It is executed before
`impress:stepleave` event. If the current slide has `class="stop"`
set, it will disable the next() command by setting the next slide to the current
slide.
Author
------
Copyright 2016 Henrik Ingo (@henrikingo)
Released under the MIT license.

35
src/plugins/stop/stop.js Normal file
View File

@@ -0,0 +1,35 @@
/**
* Stop Plugin
*
* Example:
*
* <!-- Stop at this slide.
* (For example, when used on the last slide, this prevents the
* presentation from wrapping back to the beginning.) -->
* <div class="step stop">
*
* Copyright 2016 Henrik Ingo (@henrikingo)
* Released under the MIT license.
*/
/* global document, window */
( function( document, window ) {
"use strict";
var stop = function( event ) {
if ( ( !event ) || ( !event.target ) ) {
return;
}
if ( event.target.classList.contains( "stop" ) ) {
if ( event.detail.reason === "next" ) {
return false;
}
}
};
// Register the plugin to be called in pre-stepleave phase
// The weight makes this plugin run fairly early.
window.impress.addPreStepLeavePlugin( stop, 2 );
} )( document, window );