Merge pull request #2571 from Carreau/jsdoc

Start to document Javascript

see IPython/frontend/html/notebook/static/js/readme on how to compile/see it.
pull/37/head
Bussonnier Matthias 14 years ago
commit 459f816d54

@ -8,12 +8,25 @@
//============================================================================
// Cell
//============================================================================
/**
* An extendable module that provide base functionnality to create cell for notebook.
* @module IPython
* @namespace IPython
* @submodule Cell
*/
var IPython = (function (IPython) {
var utils = IPython.utils;
/**
* The Base `Cell` class from which to inherit
* @class Cell
*/
/*
* @constructor
*/
var Cell = function () {
this.placeholder = this.placeholder || '';
this.read_only = false;
@ -31,10 +44,21 @@ var IPython = (function (IPython) {
};
// Subclasses must implement create_element.
/**
* Empty. Subclasses must implement create_element.
* This should contain all the code to create the DOM element in notebook
* and will be called by Base Class constructor.
* @method create_element
*/
Cell.prototype.create_element = function () {};
/**
* Subclasses can implement override bind_events.
* Be carefull to call the parent method when overwriting as it fires event.
* this will be triggerd after create_element in constructor.
* @method bind_events
*/
Cell.prototype.bind_events = function () {
var that = this;
// We trigger events so that Cell doesn't have to depend on Notebook.
@ -50,6 +74,10 @@ var IPython = (function (IPython) {
});
};
/**
* Triger typsetting of math by mathjax on current cell element
* @method typeset
*/
Cell.prototype.typeset = function () {
if (window.MathJax){
var cell_math = this.element.get(0);
@ -57,39 +85,69 @@ var IPython = (function (IPython) {
}
};
/**
* should be triggerd when cell is selected
* @method select
*/
Cell.prototype.select = function () {
this.element.addClass('ui-widget-content ui-corner-all');
this.selected = true;
};
/**
* should be triggerd when cell is unselected
* @method unselect
*/
Cell.prototype.unselect = function () {
this.element.removeClass('ui-widget-content ui-corner-all');
this.selected = false;
};
/**
* should be overritten by subclass
* @method get_text
*/
Cell.prototype.get_text = function () {
};
/**
* should be overritten by subclass
* @method set_text
* @param {string} text
*/
Cell.prototype.set_text = function (text) {
};
/**
* Refresh codemirror instance
* @method refresh
*/
Cell.prototype.refresh = function () {
this.code_mirror.refresh();
};
/**
* should be overritten by subclass
* @method edit
**/
Cell.prototype.edit = function () {
};
/**
* should be overritten by subclass
* @method render
**/
Cell.prototype.render = function () {
};
/**
* should be overritten by subclass
* serialise cell to json.
* @method toJSON
**/
Cell.prototype.toJSON = function () {
var data = {};
data.metadata = this.metadata;
@ -97,6 +155,10 @@ var IPython = (function (IPython) {
};
/**
* should be overritten by subclass
* @method fromJSON
**/
Cell.prototype.fromJSON = function (data) {
if (data.metadata !== undefined) {
this.metadata = data.metadata;
@ -104,11 +166,19 @@ var IPython = (function (IPython) {
};
/**
* can the cell be splitted in 2 cells.
* @method is_splittable
**/
Cell.prototype.is_splittable = function () {
return true;
};
/**
* @return {String} - the text before the cursor
* @method get_pre_cursor
**/
Cell.prototype.get_pre_cursor = function () {
var cursor = this.code_mirror.getCursor();
var text = this.code_mirror.getRange({line:0,ch:0}, cursor);
@ -117,6 +187,10 @@ var IPython = (function (IPython) {
}
/**
* @return {String} - the text after the cursor
* @method get_post_cursor
**/
Cell.prototype.get_post_cursor = function () {
var cursor = this.code_mirror.getCursor();
var last_line_num = this.code_mirror.lineCount()-1;
@ -128,9 +202,15 @@ var IPython = (function (IPython) {
};
/** Grow the cell by hand. This is used upon reloading from JSON, when the
* autogrow handler is not called.
*
* could be made static
*
* @param {Dom element} - element
* @method grow
**/
Cell.prototype.grow = function(element) {
// Grow the cell by hand. This is used upon reloading from JSON, when the
// autogrow handler is not called.
var dom = element.get(0);
var lines_count = 0;
// modified split rule from
@ -144,7 +224,10 @@ var IPython = (function (IPython) {
}
};
/**
* Toggle CodeMirror LineNumber
* @method toggle_line_numbers
**/
Cell.prototype.toggle_line_numbers = function () {
if (this.code_mirror.getOption('lineNumbers') == false) {
this.code_mirror.setOption('lineNumbers', true);
@ -154,11 +237,22 @@ var IPython = (function (IPython) {
this.code_mirror.refresh();
};
/**
* force codemirror highlight mode
* @method force_highlight
* @param {object} - CodeMirror mode
**/
Cell.prototype.force_highlight = function(mode) {
this.user_highlight = mode;
this.auto_highlight();
};
/**
* Try to autodetect cell highlight mode, or use selected mode
* @methods _auto_highlight
* @private
* @param {String|object|undefined} - CodeMirror mode | 'auto'
**/
Cell.prototype._auto_highlight = function (modes) {
//Here we handle manually selected modes
if( this.user_highlight != undefined && this.user_highlight != 'auto' )

@ -8,6 +8,12 @@
//============================================================================
// CodeCell
//============================================================================
/**
* An extendable module that provide base functionnality to create cell for notebook.
* @module IPython
* @namespace IPython
* @submodule CodeCell
*/
var IPython = (function (IPython) {
"use strict";
@ -16,9 +22,18 @@ var IPython = (function (IPython) {
var key = IPython.utils.keycodes;
CodeMirror.modeURL = "/static/codemirror/mode/%N/%N.js";
/**
* A Cell conceived to write code.
*
* The kernel doesn't have to be set at creation time, in that case
* it will be null and set_kernel has to be called later.
* @class CodeCell
* @extends IPython.Cell
*
* @constructor
* @param {Object|null} kernel
*/
var CodeCell = function (kernel) {
// The kernel doesn't have to be set at creation time, in that case
// it will be null and set_kernel has to be called later.
this.kernel = kernel || null;
this.code_mirror = null;
this.input_prompt_number = null;
@ -36,11 +51,14 @@ var IPython = (function (IPython) {
CodeCell.prototype = new IPython.Cell();
/**
* @method auto_highlight
*/
CodeCell.prototype.auto_highlight = function () {
this._auto_highlight(IPython.config.cell_magic_highlight)
};
/** @method create_element */
CodeCell.prototype.create_element = function () {
var cell = $('<div></div>').addClass('cell border-box-sizing code_cell vbox');
cell.attr('tabindex','2');
@ -69,11 +87,14 @@ var IPython = (function (IPython) {
}
};
/**
* This method gets called in CodeMirror's onKeyDown/onKeyPress
* handlers and is used to provide custom key handling. Its return
* value is used to determine if CodeMirror should ignore the event:
* true = ignore, false = don't ignore.
* @method handle_codemirror_keyevent
*/
CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
// This method gets called in CodeMirror's onKeyDown/onKeyPress
// handlers and is used to provide custom key handling. Its return
// value is used to determine if CodeMirror should ignore the event:
// true = ignore, false = don't ignore.
if (this.read_only){
return false;
@ -155,7 +176,10 @@ var IPython = (function (IPython) {
this.kernel = kernel;
}
/**
* Execute current code cell to the kernel
* @method execute
*/
CodeCell.prototype.execute = function () {
this.output_area.clear_output(true, true, true);
this.set_input_prompt('*');
@ -169,7 +193,10 @@ var IPython = (function (IPython) {
var msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false});
};
/**
* @method _handle_execute_reply
* @private
*/
CodeCell.prototype._handle_execute_reply = function (content) {
this.set_input_prompt(content.execution_count);
this.element.removeClass("running");
@ -226,20 +253,17 @@ var IPython = (function (IPython) {
};
CodeCell.input_prompt_classical = function (prompt_value, lines_number) {
var ns = prompt_value || "&nbsp;";
return 'In&nbsp;[' + ns + ']:'
};
CodeCell.input_prompt_continuation = function (prompt_value, lines_number) {
var html = [CodeCell.input_prompt_classical(prompt_value, lines_number)];
for(var i=1; i < lines_number; i++){html.push(['...:'])};
return html.join('</br>')
};
CodeCell.input_prompt_function = CodeCell.input_prompt_classical;

@ -1,7 +1,35 @@
/*
Placeholder for custom user javascript
mainly to be overridden in profile/static/js/custom.js
This will always be an empty file in IPython
*/
// leave at least 2 line with only a star on it below, or doc generation fails
/**
*
*
* Placeholder for custom user javascript
* mainly to be overridden in profile/static/js/custom.js
* This will always be an empty file in IPython
*
* User could add any javascript in the `profile/static/js/custom.js` file
* (and should create it if it does not exist).
* It will be executed by the ipython notebook at load time.
*
* Same thing with `profile/static/css/custom.css` to inject custom css into the notebook.
*
* Example :
*
* Create a custom button in toolbar that execute `%qtconsole` in kernel
* and hence open a qtconsole attached to the same kernel as the current notebook
*
* $([IPython.events]).on('notebook_loaded.Notebook', function(){
* IPython.toolbar.add_buttons_group([
* {
* 'label' : 'run qtconsole',
* 'icon' : 'ui-icon-calculator', // select your icon from http://jqueryui.com/themeroller/
* 'callback': function(){IPython.notebook.kernel.execute('%qtconsole')}
* }
* // add more button here if needed.
* ]);
* });
*
* @module IPython
* @namespace IPython
* @class customjs
* @static
*/

@ -9,12 +9,21 @@
// Kernel
//============================================================================
/**
* @module IPython
* @namespace IPython
* @submodule Kernel
*/
var IPython = (function (IPython) {
var utils = IPython.utils;
// Initialization and connection.
/**
* A Kernel Class to communicate with the Python kernel
* @Class Kernel
*/
var Kernel = function (base_url) {
this.kernel_id = null;
this.shell_channel = null;
@ -50,6 +59,10 @@ var IPython = (function (IPython) {
return msg;
};
/**
* Start the Python kernel
* @method start
*/
Kernel.prototype.start = function (notebook_id) {
var that = this;
if (!this.running) {
@ -62,7 +75,14 @@ var IPython = (function (IPython) {
};
};
/**
* Restart the python kernel.
*
* Emit a 'status_restarting.Kernel' event with
* the current object as parameter
*
* @method restart
*/
Kernel.prototype.restart = function () {
$([IPython.events]).trigger('status_restarting.Kernel', {kernel: this});
var that = this;
@ -122,6 +142,12 @@ var IPython = (function (IPython) {
};
/**
* Start the `shell`and `iopub` channels.
* Will stop and restart them if they already exist.
*
* @method start_channels
*/
Kernel.prototype.start_channels = function () {
var that = this;
this.stop_channels();
@ -162,7 +188,10 @@ var IPython = (function (IPython) {
}, 1000);
};
/**
* Start the `shell`and `iopub` channels.
* @method stop_channels
*/
Kernel.prototype.stop_channels = function () {
if (this.shell_channel !== null) {
this.shell_channel.onclose = function (evt) {};
@ -178,17 +207,28 @@ var IPython = (function (IPython) {
// Main public methods.
/**
* Get info on object asynchronoulsy
*
* @async
* @param objname {string}
* @param callback {dict}
* @method object_info_request
*
* @example
*
* When calling this method pass a callbacks structure of the form:
*
* callbacks = {
* 'object_info_reply': object_info_reply_callback
* }
*
* The `object_info_reply_callback` will be passed the content object of the
*
* `object_into_reply` message documented in
* [IPython dev documentation](http://ipython.org/ipython-doc/dev/development/messaging.html#object-information)
*/
Kernel.prototype.object_info_request = function (objname, callbacks) {
// When calling this method pass a callbacks structure of the form:
//
// callbacks = {
// 'object_info_reply': object_into_reply_callback
// }
//
// The object_info_reply_callback will be passed the content object of the
// object_into_reply message documented here:
//
// http://ipython.org/ipython-doc/dev/development/messaging.html#object-information
if(typeof(objname)!=null && objname!=null)
{
var content = {
@ -202,42 +242,61 @@ var IPython = (function (IPython) {
return;
}
/**
* Execute given code into kernel, and pass result to callback.
*
* @async
* @method execute
* @param {string} code
* @param callback {Object} With the following keys
* @param callback.'execute_reply' {function}
* @param callback.'output' {function}
* @param callback.'clear_output' {function}
* @param callback.'set_next_input' {function}
* @param {object} [options]
* @param [options.silent=false] {Boolean}
* @param [options.user_expressions=empty_dict] {Dict}
* @param [options.user_variables=empty_list] {List od Strings}
* @param [options.allow_stdin=false] {Boolean} true|false
*
* @example
*
* The options object should contain the options for the execute call. Its default
* values are:
*
* options = {
* silent : true,
* user_variables : [],
* user_expressions : {},
* allow_stdin : false
* }
*
* When calling this method pass a callbacks structure of the form:
*
* callbacks = {
* 'execute_reply': execute_reply_callback,
* 'output': output_callback,
* 'clear_output': clear_output_callback,
* 'set_next_input': set_next_input_callback
* }
*
* The `execute_reply_callback` will be passed the content and metadata
* objects of the `execute_reply` message documented
* [here](http://ipython.org/ipython-doc/dev/development/messaging.html#execute)
*
* The `output_callback` will be passed `msg_type` ('stream','display_data','pyout','pyerr')
* of the output and the content and metadata objects of the PUB/SUB channel that contains the
* output:
*
* http://ipython.org/ipython-doc/dev/development/messaging.html#messages-on-the-pub-sub-socket
*
* The `clear_output_callback` will be passed a content object that contains
* stdout, stderr and other fields that are booleans, as well as the metadata object.
*
* The `set_next_input_callback` will be passed the text that should become the next
* input cell.
*/
Kernel.prototype.execute = function (code, callbacks, options) {
// The options object should contain the options for the execute call. Its default
// values are:
//
// options = {
// silent : true,
// user_variables : [],
// user_expressions : {},
// allow_stdin : false
// }
//
// When calling this method pass a callbacks structure of the form:
//
// callbacks = {
// 'execute_reply': execute_reply_callback,
// 'output': output_callback,
// 'clear_output': clear_output_callback,
// 'set_next_input': set_next_input_callback
// }
//
// The execute_reply_callback will be passed the content and metadata objects of the execute_reply
// message documented here:
//
// http://ipython.org/ipython-doc/dev/development/messaging.html#execute
//
// The output_callback will be passed msg_type ('stream','display_data','pyout','pyerr')
// of the output and the content and metadata objects of the PUB/SUB channel that contains the
// output:
//
// http://ipython.org/ipython-doc/dev/development/messaging.html#messages-on-the-pub-sub-socket
//
// The clear_output_callback will be passed a content object that contains
// stdout, stderr and other fields that are booleans, as well as the metadata object.
//
// The set_next_input_callback will be passed the text that should become the next
// input cell.
var content = {
code : code,
@ -254,18 +313,25 @@ var IPython = (function (IPython) {
return msg.header.msg_id;
};
/**
* When calling this method pass a callbacks structure of the form:
*
* callbacks = {
* 'complete_reply': complete_reply_callback
* }
*
* The `complete_reply_callback` will be passed the content object of the
* `complete_reply` message documented
* [here](http://ipython.org/ipython-doc/dev/development/messaging.html#complete)
*
* @method complete
* @param line {integer}
* @param cursor_pos {integer}
* @param {dict} callbacks
* @param callbacks.complete_reply {function} `complete_reply_callback`
*
*/
Kernel.prototype.complete = function (line, cursor_pos, callbacks) {
// When calling this method pass a callbacks structure of the form:
//
// callbacks = {
// 'complete_reply': complete_reply_callback
// }
//
// The complete_reply_callback will be passed the content object of the
// complete_reply message documented here:
//
// http://ipython.org/ipython-doc/dev/development/messaging.html#complete
callbacks = callbacks || {};
var content = {
text : '',

@ -9,11 +9,24 @@
// TextCell
//============================================================================
/**
A module that allow to create different type of Text Cell
@module IPython
@namespace IPython
*/
var IPython = (function (IPython) {
// TextCell base class
var key = IPython.utils.keycodes;
/**
* Construct a new TextCell, codemirror mode is by default 'htmlmixed', and cell type is 'text'
* cell start as not redered.
*
* @class TextCell
* @constructor TextCell
* @extend Ipython.Cell
*/
var TextCell = function () {
this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
IPython.Cell.apply(this, arguments);
@ -21,10 +34,13 @@ var IPython = (function (IPython) {
this.cell_type = this.cell_type || 'text';
};
TextCell.prototype = new IPython.Cell();
/**
* Create the DOM element of the TextCell
* @method create_element
* @private
*/
TextCell.prototype.create_element = function () {
var cell = $("<div>").addClass('cell text_cell border-box-sizing');
cell.attr('tabindex','2');
@ -47,6 +63,12 @@ var IPython = (function (IPython) {
};
/**
* Bind the DOM evet to cell actions
* Need to be called after TextCell.create_element
* @private
* @method bind_event
*/
TextCell.prototype.bind_events = function () {
IPython.Cell.prototype.bind_events.apply(this);
var that = this;
@ -63,13 +85,19 @@ var IPython = (function (IPython) {
});
};
/**
* This method gets called in CodeMirror's onKeyDown/onKeyPress
* handlers and is used to provide custom key handling.
*
* Subclass should override this method to have custom handeling
*
* @method handle_codemirror_keyevent
* @param {CodeMirror} editor - The codemirror instance bound to the cell
* @param {event} event -
* @return {Boolean} `true` if CodeMirror should ignore the event, `false` Otherwise
*/
TextCell.prototype.handle_codemirror_keyevent = function (editor, event) {
// This method gets called in CodeMirror's onKeyDown/onKeyPress
// handlers and is used to provide custom key handling. Its return
// value is used to determine if CodeMirror should ignore the event:
// true = ignore, false = don't ignore.
if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
// Always ignore shift-enter in CodeMirror as we handle it.
return true;
@ -77,26 +105,36 @@ var IPython = (function (IPython) {
return false;
};
/**
* Select the current cell and trigger 'focus'
* @method select
*/
TextCell.prototype.select = function () {
IPython.Cell.prototype.select.apply(this);
var output = this.element.find("div.text_cell_render");
output.trigger('focus');
};
/**
* unselect the current cell and `render` it
* @method unselect
*/
TextCell.prototype.unselect = function() {
// render on selection of another cell
this.render();
IPython.Cell.prototype.unselect.apply(this);
};
/**
*
* put the current cell in edition mode
* @method edit
*/
TextCell.prototype.edit = function () {
if ( this.read_only ) return;
if (this.rendered === true) {
var text_cell = this.element;
var output = text_cell.find("div.text_cell_render");
var output = text_cell.find("div.text_cell_render");
output.hide();
text_cell.find('div.text_cell_input').show();
this.code_mirror.refresh();
@ -113,31 +151,56 @@ var IPython = (function (IPython) {
};
// Subclasses must define render.
/**
* Empty, Subclasses must define render.
* @method render
*/
TextCell.prototype.render = function () {};
/**
* setter: {{#crossLink "TextCell/set_text"}}{{/crossLink}}
* @method get_text
* @retrun {string} CodeMirror current text value
*/
TextCell.prototype.get_text = function() {
return this.code_mirror.getValue();
};
/**
* @param {string} text - Codemiror text value
* @see TextCell#get_text
* @method set_text
* */
TextCell.prototype.set_text = function(text) {
this.code_mirror.setValue(text);
this.code_mirror.refresh();
};
/**
* setter :{{#crossLink "TextCell/set_rendered"}}{{/crossLink}}
* @method get_rendered
* @return {html} html of rendered element
* */
TextCell.prototype.get_rendered = function() {
return this.element.find('div.text_cell_render').html();
};
/**
* @method set_rendered
*/
TextCell.prototype.set_rendered = function(text) {
this.element.find('div.text_cell_render').html(text);
};
/**
* not deprecated, but implementation wrong
* @method at_top
* @deprecated
* @return {Boolean} true is cell rendered, false otherwise
* I doubt this is what it is supposed to do
* this implementation is completly false
*/
TextCell.prototype.at_top = function () {
if (this.rendered) {
return true;
@ -147,6 +210,14 @@ var IPython = (function (IPython) {
};
/**
* not deprecated, but implementation wrong
* @method at_bottom
* @deprecated
* @return {Boolean} true is cell rendered, false otherwise
* I doubt this is what it is supposed to do
* this implementation is completly false
* */
TextCell.prototype.at_bottom = function () {
if (this.rendered) {
return true;
@ -155,7 +226,11 @@ var IPython = (function (IPython) {
}
};
/**
* Create Text cell from JSON
* @param {json} data - JSON serialized text-cell
* @method fromJSON
*/
TextCell.prototype.fromJSON = function (data) {
IPython.Cell.prototype.fromJSON.apply(this, arguments);
if (data.cell_type === this.cell_type) {
@ -171,7 +246,9 @@ var IPython = (function (IPython) {
}
};
/** Generate JSON from cell
* @return {object} cell data serialised to json
*/
TextCell.prototype.toJSON = function () {
var data = IPython.Cell.prototype.toJSON.apply(this);
data.cell_type = this.cell_type;
@ -180,8 +257,11 @@ var IPython = (function (IPython) {
};
// HTMLCell
/**
* @constructor HtmlCell
* @class HtmlCell
* @extends Ipython.TextCell
*/
var HTMLCell = function () {
this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
IPython.TextCell.apply(this, arguments);
@ -191,7 +271,9 @@ var IPython = (function (IPython) {
HTMLCell.prototype = new TextCell();
/**
* @method render
*/
HTMLCell.prototype.render = function () {
if (this.rendered === false) {
var text = this.get_text();
@ -205,8 +287,11 @@ var IPython = (function (IPython) {
};
// MarkdownCell
/**
* @class MarkdownCell
* @constructor MarkdownCell
* @extends Ipython.HtmlCell
*/
var MarkdownCell = function () {
this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
IPython.TextCell.apply(this, arguments);
@ -216,7 +301,9 @@ var IPython = (function (IPython) {
MarkdownCell.prototype = new TextCell();
/**
* @method render
*/
MarkdownCell.prototype.render = function () {
if (this.rendered === false) {
var text = this.get_text();
@ -255,6 +342,11 @@ var IPython = (function (IPython) {
// RawCell
/**
* @class RawCell
* @constructor RawCell
* @extends Ipython.TextCell
*/
var RawCell = function () {
this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
this.code_mirror_mode = 'rst';
@ -270,21 +362,23 @@ var IPython = (function (IPython) {
RawCell.prototype = new TextCell();
/**
* Trigger autodetection of highlight scheme for current cell
* @method auto_highlight
*/
RawCell.prototype.auto_highlight = function () {
this._auto_highlight(IPython.config.raw_cell_highlight);
};
/** @method render **/
RawCell.prototype.render = function () {
this.rendered = true;
this.edit();
};
/** @method handle_codemirror_keyevent **/
RawCell.prototype.handle_codemirror_keyevent = function (editor, event) {
// This method gets called in CodeMirror's onKeyDown/onKeyPress
// handlers and is used to provide custom key handling. Its return
// value is used to determine if CodeMirror should ignore the event:
// true = ignore, false = don't ignore.
var that = this;
if (event.which === key.UPARROW && event.type === 'keydown') {
@ -309,14 +403,14 @@ var IPython = (function (IPython) {
return false;
};
/** @method select **/
RawCell.prototype.select = function () {
IPython.Cell.prototype.select.apply(this);
this.code_mirror.refresh();
this.code_mirror.focus();
};
/** @method at_top **/
RawCell.prototype.at_top = function () {
var cursor = this.code_mirror.getCursor();
if (cursor.line === 0 && cursor.ch === 0) {
@ -327,6 +421,7 @@ var IPython = (function (IPython) {
};
/** @method at_bottom **/
RawCell.prototype.at_bottom = function () {
var cursor = this.code_mirror.getCursor();
if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) {
@ -337,19 +432,30 @@ var IPython = (function (IPython) {
};
// HTMLCell
/**
* @class HeadingCell
* @extends Ipython.TextCell
*/
/**
* @constructor HeadingCell
* @extends Ipython.TextCell
*/
var HeadingCell = function () {
this.placeholder = "Type Heading Here";
IPython.TextCell.apply(this, arguments);
this.cell_type = 'heading';
/**
* heading level of the cell, use getter and setter to access
* @property level
*/
this.level = 1;
this.cell_type = 'heading';
};
HeadingCell.prototype = new TextCell();
/** @method fromJSON */
HeadingCell.prototype.fromJSON = function (data) {
if (data.level != undefined){
this.level = data.level;
@ -358,6 +464,7 @@ var IPython = (function (IPython) {
};
/** @method toJSON */
HeadingCell.prototype.toJSON = function () {
var data = IPython.TextCell.prototype.toJSON.apply(this);
data.level = this.get_level();
@ -365,6 +472,10 @@ var IPython = (function (IPython) {
};
/**
* Change heading level of cell, and re-render
* @method set_level
*/
HeadingCell.prototype.set_level = function (level) {
this.level = level;
if (this.rendered) {
@ -373,7 +484,10 @@ var IPython = (function (IPython) {
};
};
/** The depth of header cell, based on html (h1 to h6)
* @method get_level
* @return {integer} level - for 1 to 6
*/
HeadingCell.prototype.get_level = function () {
return this.level;
};

@ -8,9 +8,20 @@
//============================================================================
// ToolBar
//============================================================================
/**
* @module IPython
* @namespace IPython
* @submodule ToolBar
*/
var IPython = (function (IPython) {
/**
* A generic toolbar on which one can add button
* @class ToolBar
* @constructor
* @param {Dom object} selector
*/
var ToolBar = function (selector) {
this.selector = selector;
if (this.selector !== undefined) {
@ -19,37 +30,38 @@ var IPython = (function (IPython) {
}
};
// add a group of button into the current toolbar.
//
// First argument : Mandatory
// list of dict as argument, each dict should contain
// 3 mandatory keys and values :
// label : string -- the text to show on hover
// icon : string -- the jQuery-ui icon to add on this button
// callback : function -- the callback to execute on a click
//
// and optionally an 'id' key that is assigned to the button element
//
// Second Argument, optional,
// string reprensenting the id to give to the button group.
//
// Example
//
// IPython.toolbar.add_button_group([
// {label:'my button',
// icon:'ui-icon-disk',
// callback:function(){alert('hoho'),
// id : 'my_button_id', // this is optional
// }
// },
// {label:'my second button',
// icon:'ui-icon-scissors',
// callback:function(){alert('be carefull I cut')}
// }
// ],
// "my_button_group_id"
// )
//
/**
* add a group of button into the current toolbar.
*
*
* @example
*
* IPython.toolbar.add_button_group([
* {
* label:'my button',
* icon:'ui-icon-disk',
* callback:function(){alert('hoho'),
* id : 'my_button_id', // this is optional
* },
* {
* label:'my second button',
* icon:'ui-icon-scissors',
* callback:function(){alert('be carefull I cut')}
* }
* ],
* "my_button_group_id"
* )
*
* @method add_buttons_group
* @param list {List}
* List of button of the group, with the following paramter for each :
* @param list.label {string} text to show on button hover
* @param list.icon {string} icon to choose from [jQuery ThemeRoller](http://jqueryui.com/themeroller/)
* @param list.callback {function} function to be called on button click
* @param [list.id] {String} id to give to the button
* @param [group_id] {String} optionnal id to give to the group
*
*/
ToolBar.prototype.add_buttons_group = function (list, group_id) {
var span_group = $('<span/>');
if( group_id != undefined ) {
@ -80,7 +92,10 @@ var IPython = (function (IPython) {
css('border-right-style','none');
};
/**
* Show and hide toolbar
* @method toggle
*/
ToolBar.prototype.toggle = function () {
this.element.toggle();
if (IPython.layout_manager != undefined) {

Loading…
Cancel
Save