-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
skip autoplay for some time after user interaction #729
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
"use strict"; | ||
|
||
var autoplayDefault = 0; | ||
var userSkipAutoplayDefault = 0; | ||
var userSkipAutoplay = 0; | ||
var currentStepTimeout = 0; | ||
var api = null; | ||
var timeoutHandle = null; | ||
|
@@ -26,6 +28,7 @@ | |
// or anything. `impress:init` event data gives you everything you | ||
// need to control the presentation that was just initialized. | ||
api = event.detail.api; | ||
var gc = api.lib.gc; | ||
root = event.target; | ||
|
||
// Element attributes starting with "data-", become available under | ||
|
@@ -36,15 +39,25 @@ | |
autoplayDefault = util.toNumber( data.autoplay, 0 ); | ||
} | ||
|
||
if ( data.userSkipAutoplay ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming convention: You must call the attribute |
||
userSkipAutoplayDefault = util.toNumber( data.userSkipAutoplay, 0 ); | ||
} | ||
|
||
var toolbar = document.querySelector( "#impress-toolbar" ); | ||
if ( toolbar ) { | ||
addToolbarButton( toolbar ); | ||
} | ||
|
||
api.lib.gc.pushCallback( function() { | ||
gc.pushCallback( function() { | ||
clearTimeout( timeoutHandle ); | ||
} ); | ||
|
||
gc.addEventListener( document, "keydown", user ); | ||
gc.addEventListener( document, "keyup", user ); | ||
gc.addEventListener( document, "mousemove", user ); | ||
gc.addEventListener( document, "click", user ); | ||
gc.addEventListener( document, "touch", user ); | ||
|
||
// Note that right after impress:init event, also impress:stepenter is | ||
// triggered for the first slide, so that's where code flow continues. | ||
}, false ); | ||
|
@@ -59,6 +72,15 @@ | |
reloadTimeout( event ); | ||
}, false ); | ||
|
||
var user = function( event ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you call this |
||
if ( status !== "paused" ) { | ||
userSkipAutoplay = userSkipAutoplayDefault; | ||
if ( status !== "delayed" ) { | ||
status = "delayed"; | ||
} | ||
} | ||
}; | ||
|
||
// If default autoplay time was defined in the presentation root, or | ||
// in this step, set timeout. | ||
var reloadTimeout = function( event ) { | ||
|
@@ -88,7 +110,18 @@ | |
} | ||
|
||
if ( timeout > 0 ) { | ||
timeoutHandle = setTimeout( function() { api.next(); }, timeout * 1000 ); | ||
timeoutHandle = setTimeout( function() { | ||
if (status === "delayed") { | ||
if (userSkipAutoplay > 0) { | ||
userSkipAutoplay = userSkipAutoplay - 1; | ||
setAutoplayTimeout( timeout ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this... If I have
...then the total time on the slide is set to 15 seconds? This is a very weird outcome. A simpler alternative, both for users and as implementation would be to just have userdelay as a boolean:
and then in
You could make this enabled by default. It seems like a good feature. |
||
} else { | ||
status = "playing"; | ||
api.next(); | ||
} | ||
} else { | ||
api.next(); | ||
}}, timeout * 1000 ); | ||
} | ||
setButtonText(); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like I was lazy and there's no documentation for this plugin. (Either in the comment above, or a separate README file.) Could you add it now? Including your own addition.