slideshow.js
62 lines
| 2.3 KiB
| application/javascript
|
JavascriptLexer
Jonathan Frederic
|
r17217 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
Matthias BUSSONNIER
|
r9087 | |||
Jonathan Frederic
|
r17217 | define([ | ||
'jquery', | ||||
'notebook/js/celltoolbar', | ||||
], function($, celltoolbar) { | ||||
Matthias BUSSONNIER
|
r9087 | "use strict"; | ||
Jonathan Frederic
|
r17217 | |||
var CellToolbar = celltoolbar.CellToolbar; | ||||
Matthias BUSSONNIER
|
r9087 | var slideshow_preset = []; | ||
Jonathan Frederic
|
r17865 | var _update_cell = function(cell, old_slide_class) { | ||
// Remove the old slide DOM class if set. | ||||
if (old_slide_class && old_slide_class != '-') { | ||||
cell.element.removeClass('slideshow-'+old_slide_class); | ||||
} | ||||
// add a DOM class to the cell | ||||
var value = _get_cell_type(cell); | ||||
if (value != '-') { cell.element.addClass('slideshow-'+value); } | ||||
}; | ||||
var _get_cell_type = function(cell) { | ||||
var ns = cell.metadata.slideshow; | ||||
// if the slideshow namespace does not exist return `undefined` | ||||
// (will be interpreted as `false` by checkbox) otherwise | ||||
// return the value | ||||
return (ns === undefined)? undefined: ns.slide_type; | ||||
}; | ||||
Matthias BUSSONNIER
|
r9087 | var select_type = CellToolbar.utils.select_ui_generator([ | ||
Matthias BUSSONNIER
|
r12649 | ["-" ,"-" ], | ||
Matthias BUSSONNIER
|
r9087 | ["Slide" ,"slide" ], | ||
Matthias BUSSONNIER
|
r9088 | ["Sub-Slide" ,"subslide" ], | ||
Matthias BUSSONNIER
|
r9087 | ["Fragment" ,"fragment" ], | ||
["Skip" ,"skip" ], | ||||
Matthias BUSSONNIER
|
r9088 | ["Notes" ,"notes" ], | ||
Matthias BUSSONNIER
|
r9087 | ], | ||
// setter | ||||
function(cell, value){ | ||||
// we check that the slideshow namespace exist and create it if needed | ||||
Jonathan Frederic
|
r17217 | if (cell.metadata.slideshow === undefined){cell.metadata.slideshow = {};} | ||
Matthias BUSSONNIER
|
r9087 | // set the value | ||
Jonathan Frederic
|
r17865 | var old = cell.metadata.slideshow.slide_type; | ||
Jonathan Frederic
|
r17217 | cell.metadata.slideshow.slide_type = value; | ||
Jonathan Frederic
|
r17865 | // update the slideshow class set on the cell | ||
_update_cell(cell, old); | ||||
Matthias BUSSONNIER
|
r9087 | }, | ||
//geter | ||||
Jonathan Frederic
|
r17865 | _get_cell_type, | ||
Matthias BUSSONNIER
|
r9087 | "Slide Type"); | ||
Matthias BUSSONNIER
|
r17454 | var register = function (notebook) { | ||
Jonathan Frederic
|
r17217 | CellToolbar.register_callback('slideshow.select',select_type); | ||
slideshow_preset.push('slideshow.select'); | ||||
Matthias BUSSONNIER
|
r9087 | |||
Matthias BUSSONNIER
|
r17454 | CellToolbar.register_preset('Slideshow',slideshow_preset, notebook); | ||
Jonathan Frederic
|
r17217 | console.log('Slideshow extension for metadata editing loaded.'); | ||
}; | ||||
return {'register': register}; | ||||
}); | ||||