default.js
51 lines
| 1.5 KiB
| application/javascript
|
JavascriptLexer
|
r17217 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
define([ | ||||
'jquery', | ||||
'notebook/js/celltoolbar', | ||||
'base/js/dialog', | ||||
], function($, celltoolbar, dialog) { | ||||
|
r9078 | "use strict"; | ||
|
r17217 | var CellToolbar = celltoolbar.CellToolbar; | ||
|
r9078 | |||
|
r17284 | var raw_edit = function (cell) { | ||
dialog.edit_metadata({ | ||||
md: cell.metadata, | ||||
callback: function (md) { | ||||
cell.metadata = md; | ||||
}, | ||||
name: 'Cell', | ||||
notebook: this.notebook, | ||||
keyboard_manager: this.keyboard_manager | ||||
|
r9078 | }); | ||
|
r12872 | }; | ||
|
r9078 | |||
var add_raw_edit_button = function(div, cell) { | ||||
|
r17217 | var button_container = $(div); | ||
|
r10935 | var button = $('<button/>') | ||
|
r16913 | .addClass("btn btn-default btn-xs") | ||
|
r13669 | .text("Edit Metadata") | ||
|
r10935 | .click( function () { | ||
raw_edit(cell); | ||||
return false; | ||||
}); | ||||
|
r9078 | button_container.append(button); | ||
|
r12872 | }; | ||
|
r9078 | |||
|
r17217 | var register = function (notebook, events) { | ||
CellToolbar.register_callback('default.rawedit', add_raw_edit_button); | ||||
|
r17284 | raw_edit = $.proxy(raw_edit, { | ||
notebook: notebook, | ||||
keyboard_manager: notebook.keyboard_manager | ||||
}); | ||||
|
r17217 | var example_preset = []; | ||
example_preset.push('default.rawedit'); | ||||
|
r9078 | |||
|
r17217 | CellToolbar.register_preset('Edit Metadata', example_preset, notebook, events); | ||
console.log('Default extension for cell metadata editing loaded.'); | ||||
}; | ||||
return {'register': register}; | ||||
}); | ||||