Created
January 2, 2013 19:49
-
-
Save Carreau/4437348 to your computer and use it in GitHub Desktop.
Custom.js to edit top-level metadata of IPython notebook. Please Use only for développement purpose.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var raw_edit = function(notebook){ | |
var md = notebook.metadata | |
var textarea = $('<textarea/>') | |
.attr('rows','13') | |
.attr('cols','75') | |
.attr('name','metadata') | |
.text(JSON.stringify(md, null,4)||''); | |
var dialogform = $('<div/>').attr('title','Edit the metadata') | |
.append( | |
$('<form/>').append( | |
$('<fieldset/>').append( | |
$('<label/>') | |
.attr('for','metadata') | |
.text("Metadata (I know what I'm dooing and I won't complain if it breaks my notebook)") | |
) | |
.append($('<br/>')) | |
.append( | |
textarea | |
) | |
) | |
); | |
var editor = CodeMirror.fromTextArea(textarea[0], { | |
lineNumbers: true, | |
matchBrackets: true, | |
}); | |
$(dialogform).dialog({ | |
autoOpen: true, | |
height: 300, | |
width: 650, | |
modal: true, | |
buttons: { | |
"Ok": function() { | |
//validate json and set it | |
try { | |
var json = JSON.parse(editor.getValue()); | |
notebook.metadata = json; | |
$( this ).dialog( "close" ); | |
} | |
catch(e) | |
{ | |
alert('invalid json'); | |
} | |
}, | |
Cancel: function() { | |
$( this ).dialog( "close" ); | |
} | |
}, | |
close: function() { | |
//cleanup on close | |
$(this).remove(); | |
} | |
}); | |
editor.refresh(); | |
} | |
$([IPython.events]).on('notebook_loaded.Notebook', function(){ | |
IPython.toolbar.add_buttons_group([ | |
{ | |
'label' : 'edit meta', | |
'icon' : 'ui-icon-calculator', // select your icon from http://jqueryui.com/themeroller/ | |
'callback': function(){raw_edit(IPython.notebook)} | |
} | |
// add more button here if needed. | |
]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment