mirror of
https://github.com/astefanutti/decktape.git
synced 2025-01-05 21:23:15 +03:00
Add maxSlides option for the generic plugin
This commit is contained in:
parent
a5fc5f9250
commit
12a7813aab
@ -86,7 +86,11 @@ Iterates over the [available plugins](/plugins), picks the compatible one for pr
|
||||
|
||||
### `generic`
|
||||
|
||||
Emulates the end-user interaction by pressing the key with the specified `keycode` and iterates over the presentation as long as any change to the DOM is detected by observing mutation events to the body element and its subtree. The `keycode` value must be one of the [PhantomJS page event keys](https://github.com/ariya/phantomjs/blob/cab2635e66d74b7e665c44400b8b20a8f225153a/src/modules/webpage.js#L329) and defaults to `Right`, e.g.:
|
||||
Emulates the end-user interaction by pressing the key with the specified `keycode` option and iterates over the presentation as long as:
|
||||
+ Any change to the DOM is detected by observing mutation events targeting the body element and its subtree,
|
||||
+ Nor the number of slides exported has reached the specified `maxSlides` option.
|
||||
|
||||
The `keycode` value must be one of the [PhantomJS page event keys](https://github.com/ariya/phantomjs/blob/cab2635e66d74b7e665c44400b8b20a8f225153a/src/modules/webpage.js#L329) and defaults to `Right`, e.g.:
|
||||
|
||||
```
|
||||
phantomjs decktape.js generic --keycode=Space
|
||||
|
@ -5,14 +5,19 @@ exports.options = {
|
||||
keycode: {
|
||||
default: "Right",
|
||||
help: "Key code pressed to navigate to next slide"
|
||||
},
|
||||
maxSlides: {
|
||||
help: "Maximum number of slides to export"
|
||||
}
|
||||
};
|
||||
|
||||
exports.help =
|
||||
"Emulates the end-user interaction by pressing the key with the specified [keycode]\n" +
|
||||
"and iterates over the presentation as long as any change to the DOM is detected\n" +
|
||||
"by observing mutation events to the body element and its subtree.\n" +
|
||||
"The [keycode] must be one of the PhantomJS page event keys and defaults to [Right].";
|
||||
"Emulates the end-user interaction by pressing the key with the specified [keycode] option\n" +
|
||||
"and iterates over the presentation as long as:\n" +
|
||||
"- Any change to the DOM is detected by observing mutation events targeting the body element\n" +
|
||||
" and its subtree,\n" +
|
||||
"- Nor the number of slides exported has reached the specified [maxSlides] option.\n" +
|
||||
"The [keycode] option must be one of the PhantomJS page event keys and defaults to [Right].";
|
||||
|
||||
exports.create = function (page, options) {
|
||||
return new Generic(page, options);
|
||||
@ -55,6 +60,8 @@ Generic.prototype = {
|
||||
|
||||
// A priori knowledge is impossible to achieve in a generic way. Thus the only way is to actually emulate end-user interaction by pressing the configured key and check whether the DOM has changed a posteriori.
|
||||
hasNextSlide: function () {
|
||||
if (this.options.maxSlides && this.currentSlide >= this.options.maxSlides)
|
||||
return false;
|
||||
// PhantomJS actually sends a 'keydown' DOM event when sending a 'keypress' user event. Hence 'keypress' event is skipped to avoid moving forward two steps instead of one. See https://github.com/ariya/phantomjs/issues/11094 for more details.
|
||||
["keydown"/*, "keypress"*/, "keyup"].forEach(function (event) {
|
||||
this.page.sendEvent(event, this.keycode);
|
||||
|
Loading…
Reference in New Issue
Block a user