Skip to content

Instantly share code, notes, and snippets.

@damianavila
Created June 16, 2013 19:36
Show Gist options
  • Save damianavila/5793132 to your computer and use it in GitHub Desktop.
Save damianavila/5793132 to your computer and use it in GitHub Desktop.
Reveal extension for metadata editing.
//----------------------------------------------------------------------------
// Copyright (C) 2012 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
//CellToolbar Example
//============================================================================
/**
* $.getScript('/static/js/celltoolbarpresets/slideshow.js');
* ```
* or more generally
* ```
* $.getScript('url to this file');
* ```
*/
// IIFE without asignement, we don't modifiy the IPython namespace
(function (IPython) {
"use strict";
var CellToolbar = IPython.CellToolbar;
var slideshow_preset = [];
var select_type = CellToolbar.utils.select_ui_generator([
["-" ,undefined ],
["Slide" ,"slide" ],
["Sub-Slide" ,"subslide" ],
["Fragment" ,"fragment" ],
["Skip" ,"skip" ],
["Notes" ,"notes" ],
],
// setter
function(cell, value){
// we check that the slideshow namespace exist and create it if needed
if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
// set the value
cell.metadata.slideshow.slide_type = value
},
//geter
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
},
"Slide Type");
CellToolbar.register_callback('slideshow.select',select_type);
slideshow_preset.push('slideshow.select');
var reveal_preset = slideshow_preset.slice();
var select_align = CellToolbar.utils.select_ui_generator([
["Left" ,undefined ],
["Center" ,"center" ],
["Right" ,"right" ],
],
// setter
function(cell, value){
// we check that the slideshow namespace exist and create it if needed
if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
// set the value
cell.metadata.slideshow.align_type = value
},
//geter
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.align_type
},
"Alignment");
CellToolbar.register_callback('slideshow.select_align',select_align);
reveal_preset.push('slideshow.select_align');
CellToolbar.register_preset('Reveal',reveal_preset);
console.log('Reveal extension for metadata editing loaded.');
}(IPython));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment