From 5be8d3ec6f060291d9fc65f017cfa1b49d70138b 2013-11-21 00:16:16 From: MinRK Date: 2013-11-21 00:16:16 Subject: [PATCH] add dialog to raw cell toolbar --- diff --git a/IPython/html/static/notebook/js/celltoolbarpresets/rawcell.js b/IPython/html/static/notebook/js/celltoolbarpresets/rawcell.js index 74e2dac..3c65444 100644 --- a/IPython/html/static/notebook/js/celltoolbarpresets/rawcell.js +++ b/IPython/html/static/notebook/js/celltoolbarpresets/rawcell.js @@ -14,6 +14,7 @@ var CellToolbar = IPython.CellToolbar; var raw_cell_preset = []; + var utils = IPython.utils; var select_type = CellToolbar.utils.select_ui_generator([ ["None", "-"], @@ -22,27 +23,56 @@ ["HTML", "text/html"], ["markdown", "text/markdown"], ["Python", "text/python"], - ["Custom", , "dialog"], + ["Custom", "dialog"], ], // setter function(cell, value) { - if (value === '-') { - delete cell.metadata.raw_mime; + if (value === "-") { + delete cell.metadata.raw_mimetype; } else if (value === 'dialog'){ - // IPython.dialog.modal( - // "Set custom raw cell format", - // - // OK - // ) - // + var dialog = $('
').append( + $("

") + .html("Set the MIME type of the raw cell:") + ).append( + $("
") + ).append( + $('').attr('type','text').attr('size','25') + .val(cell.metadata.raw_mimetype || "-") + ); + IPython.dialog.modal({ + title: "Raw Cell MIME Type", + body: dialog, + buttons : { + "Cancel": {}, + "OK": { + class: "btn-primary", + click: function () { + console.log(cell); + cell.metadata.raw_mimetype = $(this).find('input').val(); + console.log(cell.metadata); + } + } + }, + open : function (event, ui) { + var that = $(this); + // Upon ENTER, click the OK button. + that.find('input[type="text"]').keydown(function (event, ui) { + if (event.which === utils.keycodes.ENTER) { + that.find('.btn-primary').first().click(); + return false; + } + }); + that.find('input[type="text"]').focus().select(); + } + }); } else { - cell.metadata.raw_mime = value; + cell.metadata.raw_mimetype = value; } }, //getter function(cell) { - return cell.metadata.raw_mime || "-"; + return cell.metadata.raw_mimetype || ""; }, // name "Raw NBConvert Format",