diff --git a/IPython/html/static/base/js/dialog.js b/IPython/html/static/base/js/dialog.js
index 1d99bfe..7fbcd7c 100644
--- a/IPython/html/static/base/js/dialog.js
+++ b/IPython/html/static/base/js/dialog.js
@@ -60,7 +60,7 @@ IPython.dialog = (function (IPython) {
});
// destroy dialog on hide, unless explicitly asked not to
- if (options.destroy == undefined || options.destroy) {
+ if (options.destroy === undefined || options.destroy) {
dialog.on("hidden", function () {
dialog.remove();
});
@@ -75,10 +75,69 @@ IPython.dialog = (function (IPython) {
}
return dialog.modal(options);
- }
+ };
+
+ var edit_metadata = function (md, callback, name) {
+ name = name || "Cell";
+ var error_div = $('
').css('color', 'red');
+ var message =
+ "Manually edit the JSON below to manipulate the metadata for this " + name + "." +
+ " We recommend putting custom metadata attributes in an appropriately named sub-structure," +
+ " so they don't conflict with those of others.";
+
+ var textarea = $('')
+ .attr('rows', '13')
+ .attr('cols', '80')
+ .attr('name', 'metadata')
+ .text(JSON.stringify(md || {}, null, 2));
+
+ var dialogform = $('').attr('title', 'Edit the metadata')
+ .append(
+ $('').append(
+ $('').append(
+ $('')
+ .attr('for','metadata')
+ .text(message)
+ )
+ .append(error_div)
+ .append($('
'))
+ .append(textarea)
+ )
+ );
+ var editor = CodeMirror.fromTextArea(textarea[0], {
+ lineNumbers: true,
+ matchBrackets: true,
+ indentUnit: 2,
+ autoIndent: true,
+ mode: 'application/json',
+ });
+ IPython.dialog.modal({
+ title: "Edit " + name + " Metadata",
+ body: dialogform,
+ buttons: {
+ OK: { class : "btn-primary",
+ click: function() {
+ // validate json and set it
+ var new_md;
+ try {
+ new_md = JSON.parse(editor.getValue());
+ } catch(e) {
+ console.log(e);
+ error_div.text('WARNING: Could not save invalid JSON.');
+ return false;
+ }
+ callback(new_md);
+ }
+ },
+ Cancel: {}
+ }
+ });
+ editor.refresh();
+ };
return {
modal : modal,
+ edit_metadata : edit_metadata,
};
}(IPython));
diff --git a/IPython/html/static/notebook/js/celltoolbarpresets/default.js b/IPython/html/static/notebook/js/celltoolbarpresets/default.js
index 723ebbd..fb1ae46 100644
--- a/IPython/html/static/notebook/js/celltoolbarpresets/default.js
+++ b/IPython/html/static/notebook/js/celltoolbarpresets/default.js
@@ -19,54 +19,10 @@
var CellToolbar = IPython.CellToolbar;
var raw_edit = function(cell){
-
- var md = cell.metadata
- var error_div = $('').css('color','red')
-
- var textarea = $('')
- .attr('rows','13')
- .attr('cols','75')
- .attr('name','metadata')
- .text(JSON.stringify(md, null,4)||'');
- var dialogform = $('').attr('title','Edit the metadata')
- .append(
- $('').append(
- $('').append(
- $('')
- .attr('for','metadata')
- .text("Manually edit the JSON below to manipulate the metadata for this cell. This assumes you know what you are doing and won't complain if it breaks your notebook. We also recommend putting your metadata attributes in an appropriately named sub-structure, so they don't conflict with those of others.")
- )
- .append(error_div)
- .append($('
'))
- .append(
- textarea
- )
- )
- );
- var editor = CodeMirror.fromTextArea(textarea[0], {
- lineNumbers: true,
- matchBrackets: true,
- });
- IPython.dialog.modal({
- title: "Edit Cell Metadata",
- body: dialogform,
- buttons: {
- "OK": { class : "btn-primary",
- click: function() {
- //validate json and set it
- try {
- var json = JSON.parse(editor.getValue());
- cell.metadata = json;
- } catch(e) {
- error_div.text('Warning, invalid json, not saved');
- return false;
- }
- }},
- Cancel: {}
- }
+ IPython.dialog.edit_metadata(cell.metadata, function (md) {
+ cell.metadata = md;
});
- editor.refresh();
- }
+ };
var add_raw_edit_button = function(div, cell) {
var button_container = div;
@@ -78,13 +34,13 @@
return false;
});
button_container.append(button);
- }
+ };
- CellToolbar.register_callback('default.rawedit',add_raw_edit_button);
- var example_preset = []
+ CellToolbar.register_callback('default.rawedit', add_raw_edit_button);
+ var example_preset = [];
example_preset.push('default.rawedit');
- CellToolbar.register_preset('Default',example_preset);
+ CellToolbar.register_preset('Default', example_preset);
console.log('Default extension for metadata editing loaded.');
}(IPython));