").addClass('cell text_cell').
append(
$("
").
addClass('text_cell_input').
attr('rows',1).
attr('cols',80).
autogrow()
).append(
$('
').addClass('text_cell_render')
)
this.element = cell;
};
TextCell.prototype.select = function () {
this.edit();
Cell.prototype.select.apply(this);
};
TextCell.prototype.edit = function () {
var text_cell = this.element;
var input = text_cell.find("textarea.text_cell_input");
var output = text_cell.find("div.text_cell_render");
output.hide();
input.show().trigger('focus');
};
TextCell.prototype.render = function () {
var text_cell = this.element;
var input = text_cell.find("textarea.text_cell_input");
var output = text_cell.find("div.text_cell_render");
var text = input.val();
if (text === "") {
text = this.placeholder;
input.val(text);
};
output.html(text)
input.html(text);
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
input.hide();
output.show();
};
TextCell.prototype.config_mathjax = function () {
var text_cell = this.element;
var that = this;
text_cell.click(function () {
that.edit();
}).focusout(function () {
that.render();
});
text_cell.trigger("focusout");
};
TextCell.prototype.get_text = function() {
return this.element.find("textarea.text_cell_input").val();
};
TextCell.prototype.set_text = function(text) {
this.element.find("textarea.text_cell_input").val(text);
this.element.find("textarea.text_cell_input").html(text);
this.element.find("div.text_cell_render").html(text);
};
TextCell.prototype.fromJSON = function (data) {
if (data.cell_type === 'text') {
this.set_text(data.text);
};
}
TextCell.prototype.toJSON = function () {
return {
cell_type : 'text',
text : this.get_text(),
};
};
//============================================================================
// On document ready
//============================================================================
var Kernel = function () {
this.kernel_id = null;
this.base_url = "/kernels";
this.kernel_url = null;
};
Kernel.prototype.get_msg = function (msg_type, content) {
var msg = {
header : {
msg_id : uuid(),
username : "bgranger",
session: this.session_id
},
msg_type : msg_type,
content : content,
parent_header : {}
};
return msg;
}
Kernel.prototype.start_kernel = function (callback, context) {
var that = this;
$.post(this.base_url,
function (kernel_id) {
that._handle_start_kernel(kernel_id, callback, context);
},
'json'
);
};
Kernel.prototype._handle_start_kernel = function (kernel_id, callback, context) {
this.kernel_id = kernel_id;
this.kernel_url = this.base_url + "/" + this.kernel_id;
this._start_channels();
callback.call(context);
};
Kernel.prototype._start_channels = function () {
var ws_url = "ws://127.0.0.1:8888" + this.kernel_url;
this.shell_channel = new WebSocket(ws_url + "/shell");
this.iopub_channel = new WebSocket(ws_url + "/iopub");
}
Kernel.prototype.execute = function (code) {
var content = {
code : code,
silent : false,
user_variables : [],
user_expressions : {}
};
var msg = this.get_msg("execute_request", content);
this.shell_channel.send(JSON.stringify(msg));
return msg.header.msg_id;
}
Kernel.prototype.interrupt = function () {
$.post(this.kernel_url + "/interrupt");
};
Kernel.prototype.restart = function () {
this.status_restarting();
url = this.kernel_url + "/restart"
var that = this;
$.post(url, function (kernel_id) {
console.log("Kernel restarted: " + kernel_id);
that.kernel_id = kernel_id;
that.kernel_url = that.base_url + "/" + that.kernel_id;
that.status_idle();
}, 'json');
};
Kernel.prototype.status_busy = function () {
$("#kernel_status").removeClass("status_idle");
$("#kernel_status").removeClass("status_restarting");
$("#kernel_status").addClass("status_busy");
$("#kernel_status").text("Busy");
};
Kernel.prototype.status_idle = function () {
$("#kernel_status").removeClass("status_busy");
$("#kernel_status").removeClass("status_restarting");
$("#kernel_status").addClass("status_idle");
$("#kernel_status").text("Idle");
};
Kernel.prototype.status_restarting = function () {
$("#kernel_status").removeClass("status_busy");
$("#kernel_status").removeClass("status_idle");
$("#kernel_status").addClass("status_restarting");
$("#kernel_status").text("Restarting");
};
//============================================================================
// On document ready
//============================================================================
$(document).ready(function () {
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
},
displayAlign: 'left', // Change this to 'center' to center equations.
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}}
}
});
IPYTHON.notebook = new Notebook('div.notebook');
IPYTHON.notebook.insert_code_cell_after();
$("#menu_tabs").tabs();
$("#help_toolbar").buttonset();
$("#kernel_toolbar").buttonset();
$("#interrupt_kernel").click(function () {IPYTHON.notebook.kernel.interrupt();});
$("#restart_kernel").click(function () {IPYTHON.notebook.kernel.restart();});
$("#kernel_status").addClass("status_idle");
$("#move_cell").buttonset();
$("#move_up").button("option", "icons", {primary:"ui-icon-arrowthick-1-n"});
$("#move_up").button("option", "text", false);
$("#move_up").click(function () {IPYTHON.notebook.move_cell_up();});
$("#move_down").button("option", "icons", {primary:"ui-icon-arrowthick-1-s"});
$("#move_down").button("option", "text", false);
$("#move_down").click(function () {IPYTHON.notebook.move_cell_down();});
$("#insert_delete").buttonset();
$("#insert_cell_before").click(function () {IPYTHON.notebook.insert_code_cell_before();});
$("#insert_cell_after").click(function () {IPYTHON.notebook.insert_code_cell_after();});
$("#delete_cell").button("option", "icons", {primary:"ui-icon-closethick"});
$("#delete_cell").button("option", "text", false);
$("#delete_cell").click(function () {IPYTHON.notebook.delete_cell();});
$("#cell_type").buttonset();
$("#to_code").click(function () {IPYTHON.notebook.text_to_code();});
$("#to_text").click(function () {IPYTHON.notebook.code_to_text();});
$("#sort").buttonset();
$("#sort_cells").click(function () {IPYTHON.notebook.sort_cells();});
$("#toggle").buttonset();
$("#collapse").click(function () {IPYTHON.notebook.collapse();});
$("#expand").click(function () {IPYTHON.notebook.expand();});
});