##// END OF EJS Templates
Move glob to global level import.
Move glob to global level import.

File last commit:

r4614:eb895bf2
r4624:0e2ee7f3
Show More
textcell.js
257 lines | 7.2 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
//============================================================================
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 // TextCell
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 //============================================================================
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var IPython = (function (IPython) {
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 // TextCell base class
var TextCell = function (notebook) {
this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
this.placeholder = this.placeholder || '';
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Cell.apply(this, arguments);
this.rendered = false;
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 this.cell_type = this.cell_type || 'text';
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype = new IPython.Cell();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.create_element = function () {
var cell = $("<div>").addClass('cell text_cell border-box-sizing');
var input_area = $('<div/>').addClass('text_cell_input');
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 this.code_mirror = CodeMirror(input_area.get(0), {
indentUnit : 4,
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 mode: this.code_mirror_mode,
Brian E. Granger
Updating CodeMirror to v 2.12....
r4504 theme: 'default',
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 value: this.placeholder
});
// The tabindex=-1 makes this div focusable.
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 var render_area = $('<div/>').addClass('text_cell_render').
Brian E. Granger
Starting work on a Markdown cell.
r4507 addClass('rendered_html').attr('tabindex','-1');
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 cell.append(input_area).append(render_area);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.element = cell;
};
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.bind_events = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Cell.prototype.bind_events.apply(this);
var that = this;
this.element.keydown(function (event) {
if (event.which === 13) {
if (that.rendered) {
that.edit();
event.preventDefault();
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 });
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.select = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Cell.prototype.select.apply(this);
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 var output = this.element.find("div.text_cell_render");
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 output.trigger('focus');
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.edit = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (this.rendered === true) {
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 var text_cell = this.element;
var output = text_cell.find("div.text_cell_render");
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 output.hide();
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 text_cell.find('div.text_cell_input').show();
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 this.code_mirror.focus();
this.code_mirror.refresh();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.rendered = false;
Brian E. Granger
Removed HTMLCell from UI and added better placeholder logic.
r4614 if (this.get_source() === this.placeholder) {
this.set_source('');
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 };
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 // Subclasses must define render.
TextCell.prototype.render = function () {};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.config_mathjax = function () {
var text_cell = this.element;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var that = this;
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 text_cell.click(function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 that.edit();
}).focusout(function () {
that.render();
});
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 text_cell.trigger("focusout");
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 };
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.get_source = function() {
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 return this.code_mirror.getValue();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.set_source = function(text) {
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 this.code_mirror.setValue(text);
this.code_mirror.refresh();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Fixed text cell rendering bug.
r4513 TextCell.prototype.get_rendered = function() {
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 return this.element.find('div.text_cell_render').html();
};
TextCell.prototype.set_rendered = function(text) {
this.element.find('div.text_cell_render').html(text);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.at_top = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (this.rendered) {
return true;
} else {
return false;
}
};
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.at_bottom = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (this.rendered) {
return true;
} else {
return false;
}
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.fromJSON = function (data) {
if (data.cell_type === this.cell_type) {
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 if (data.source !== undefined) {
this.set_source(data.source);
Brian E. Granger
Fixed text cell rendering bug.
r4513 this.set_rendered(data.rendered || '');
this.rendered = false;
this.render();
Brian E. Granger
Massive work on the notebook document format....
r4484 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Fixed text cell rendering bug.
r4513 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.toJSON = function () {
Brian E. Granger
Massive work on the notebook document format....
r4484 var data = {}
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 data.cell_type = this.cell_type;
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 data.source = this.get_source();
Brian E. Granger
Massive work on the notebook document format....
r4484 return data;
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 };
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508
// HTMLCell
var HTMLCell = function (notebook) {
this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
IPython.TextCell.apply(this, arguments);
this.cell_type = 'html';
};
HTMLCell.prototype = new TextCell();
HTMLCell.prototype.render = function () {
if (this.rendered === false) {
var text = this.get_source();
if (text === "") {text = this.placeholder;};
this.set_rendered(text);
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
this.rendered = true;
};
};
// MarkdownCell
var MarkdownCell = function (notebook) {
this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
IPython.TextCell.apply(this, arguments);
this.cell_type = 'markdown';
};
MarkdownCell.prototype = new TextCell();
MarkdownCell.prototype.render = function () {
if (this.rendered === false) {
var text = this.get_source();
if (text === "") {text = this.placeholder;};
var html = IPython.markdown_converter.makeHtml(text);
this.set_rendered(html);
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
this.rendered = true;
};
};
// RSTCell
var RSTCell = function (notebook) {
this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$";
IPython.TextCell.apply(this, arguments);
this.cell_type = 'rst';
};
RSTCell.prototype = new TextCell();
RSTCell.prototype.render = function () {
if (this.rendered === false) {
var text = this.get_source();
if (text === "") {text = this.placeholder;};
var settings = {
processData : false,
cache : false,
type : "POST",
data : text,
headers : {'Content-Type': 'application/x-rst'},
success : $.proxy(this.handle_render,this)
};
$.ajax("/rstservice/render", settings);
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
this.set_rendered("Rendering...");
};
};
RSTCell.prototype.handle_render = function (data, status, xhr) {
this.set_rendered(data);
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
this.rendered = true;
};
IPython.TextCell = TextCell;
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 IPython.HTMLCell = HTMLCell;
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 IPython.MarkdownCell = MarkdownCell;
IPython.RSTCell = RSTCell;
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return IPython;
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }(IPython));
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349