decktape/plugins/rise.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-08-25 16:11:18 +03:00
const { pause } = require('../libs/util');
2017-08-21 01:43:32 +03:00
exports.create = page => new RISE(page);
2016-07-12 02:35:54 +03:00
2017-08-21 01:43:32 +03:00
class RISE {
2016-07-12 02:35:54 +03:00
2017-08-21 01:43:32 +03:00
constructor(page) {
this.page = page;
}
2016-07-12 02:35:54 +03:00
2017-08-21 01:43:32 +03:00
getName() {
return 'RISE';
}
2016-07-12 02:35:54 +03:00
2017-08-21 01:43:32 +03:00
isActive() {
return this.page.evaluate(_ => typeof $ !== 'undefined' && $('#start_livereveal').length)
2017-08-21 01:43:32 +03:00
}
2016-07-12 02:35:54 +03:00
2017-08-25 16:11:18 +03:00
async configure() {
// Wait until the RISE extension has loaded
await this.page.waitForSelector('#start_livereveal', { timeout: 30000 });
2017-08-25 16:11:18 +03:00
// Click on the 'Enter/Exit Live Reveal Slideshow' button in the notebook toolbar
await this.page.evaluate(_ => {
$('#start_livereveal').click();
$('#help_b, #exit_b').fadeToggle();
});
// Then wait until Reveal.js gets configured by the RISE extension
await this.page.waitForFunction('typeof Reveal !== \'undefined\'', { timeout: 30000 });
2017-08-25 16:11:18 +03:00
// Finally override Reveal.js configuration
await this.page.evaluate(_ => Reveal.configure({
controls : false,
progress : false,
// FIXME: 0 is still displayed when slideNumber is set to false!
// slideNumber : false,
fragments : false,
}));
2017-08-21 01:43:32 +03:00
}
2016-07-12 02:35:54 +03:00
2017-08-21 01:43:32 +03:00
slideCount() {
// TODO: the getTotalSlides API does not report the number of slides accurately
// as it does not take stacks and some index-less fragments into account
// getTotalSlides API is only available starting reveal.js version 3.0.0
return this.page.evaluate(_ => typeof Reveal.getTotalSlides === 'function'
? Reveal.getTotalSlides()
: undefined);
}
2016-07-12 02:35:54 +03:00
2017-08-21 01:43:32 +03:00
hasNextSlide() {
return this.page.evaluate(_ => !Reveal.isLastSlide());
2017-08-21 01:43:32 +03:00
}
2016-07-12 02:35:54 +03:00
2017-08-21 01:43:32 +03:00
nextSlide() {
return this.page.evaluate(_ => Reveal.next());
}
2016-07-17 18:47:43 +03:00
2017-08-21 01:43:32 +03:00
currentSlideIndex() {
return this.page.evaluate(_ => {
const indices = Reveal.getIndices();
const id = Reveal.getCurrentSlide().getAttribute('id');
return typeof id === 'string' && id.length
? '/' + id
: '/' + indices.h + (indices.v > 0 ? '/' + indices.v : '');
});
}
}