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:
21
src/plugins/stop/README.md
Normal file
21
src/plugins/stop/README.md
Normal 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
35
src/plugins/stop/stop.js
Normal 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 );
|
||||
|
||||
Reference in New Issue
Block a user