public
Last active

Slideshow mode of Notebook

  • Download Gist
slideshow.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
<div id='presentation_mode'>
<style>
.pmode{ display: none !important }
</style>
<script>
grp=0;
pmode = function(){
init()
cells = $('.cell')
nbcells = IPython.notebook.get_cells();
$('div#notebook').addClass('pove');
clist = [];
var lgrp = [];
for(var i in nbcells) {
if (nbcells[i].code_mirror.getValue().match(/(\n)?(<!--|#)?====(-->)?(\n)?/) != null){
clist.push(lgrp)
lgrp = [i]
} else{
lgrp.push(i)
}
}
clist.push(lgrp)
$(cells).fadeOut(500);
ccell = 0;
ncellingrp = 0;
$(cells[clist[grp][0]]).fadeIn()
prev_grp = function(){
for(var i in clist[grp]){
$(cells).fadeOut()
}
grp = grp-1;
setTimeout(function(){$(cells[clist[grp][0]]).fadeIn()},800)
ccell = 0; //current cell
}
next_grp = function(){
for(var i in clist[grp]){
$(cells).fadeOut()
}
grp = grp +1;
var vcell = clist[grp] ;
if (vcell != undefined ){
setTimeout(function(){
$(cells[clist[grp][0]]).fadeIn()},800
)
} else {
setTimeout(function(){stop()},200);
}
ccell = 0; //current cell
console.log('ccel is ', ccell);
}
next_cell = function(){
ccell = ccell+1;
var vcell = cells[clist[grp][ccell]];
if ( vcell != undefined ){
$(vcell).fadeIn();
}else{
next_grp()
}
setTimeout(function(){IPython.layout_manager.do_resize();},1000);
}
nslide = function(){next_grp()}
pslide = function(){prev_grp()}
nstep = function(){next_cell()}
$('#menubar, #pager_splitter, #pager, #header,#toolbar').addClass('pmode');
 
};
var init = function()
{
var pt = $('<div/>').attr('id','toolbar_present').addClass('toolbar');
$('#toolbar').after(pt);
ptoolbar = new IPython.ToolBar('#toolbar_present');
IPython.ptoolbar = ptoolbar;
ptoolbar.addButtonsGroup([{label:'Next Slide', icon:'ui-icon-stop', callback:function(){stop()}}])
ptoolbar.addButtonsGroup([
{label:'Next Slide', icon:'ui-icon-seek-prev', callback:function(){pslide()}},
{label:'Next Slide', icon:'ui-icon-seek-next', callback:function(){nslide()}},
])
ptoolbar.addButtonsGroup([{label:'Step Next Cell', icon:'ui-icon-play', callback:function(){nstep()}}])
}
var stop = function() {
$(cells).show();
$(ptoolbar.selector).remove();
$('.pmode').removeClass('pmode');
$('div#notebook').removeClass('pove');
}
var sid = 'start_pmode'
if(($('#'+sid)).length == 0) {
IPython.toolbar.addButtonsGroup([
{'label':'Start Slideshow', 'icon':'ui-icon-image', 'callback':function(){pmode()},'id':sid},
])
}
</script>
</div>

e2032e seem to be working, improving when arriving at the end.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.