##// END OF EJS Templates
avoid references to fiel out of directory...
avoid references to fiel out of directory request for packaging, it would be nice for example not to reference files outside of exampel directory copy ../../_static/logo.png in logo/logo.png use subfolder for demo purpose of targetting subfolder in demo notebook

File last commit:

r7523:6f3a3b2e
r9992:713f1db0
Show More
cell.js
163 lines | 4.4 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
//============================================================================
// Cell
//============================================================================
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 E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var utils = IPython.utils;
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Fixing auto-indent issues in CodeMirror config....
r5959
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var Cell = function () {
Brian Granger
Updating cell logic....
r5944 this.placeholder = this.placeholder || '';
MinRK
add read-only view for notebooks...
r5200 this.read_only = false;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.selected = false;
Brian E. Granger
Autoindentation fixed and enabled by default.
r4529 this.element = null;
MinRK
add empty metadata field on cells/worksheets...
r7523 this.metadata = {};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.create_element();
Brian E. Granger
Autoindentation fixed and enabled by default.
r4529 if (this.element !== null) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.element.data("cell", this);
this.bind_events();
}
this.cell_id = utils.uuid();
};
Brian Granger
Fixing auto-indent issues in CodeMirror config....
r5959
Brian Granger
Work on the base Cell API....
r5943 // Subclasses must implement create_element.
Cell.prototype.create_element = function () {};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian Granger
Fixing auto-indent issues in CodeMirror config....
r5959
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Cell.prototype.bind_events = function () {
var that = this;
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 // We trigger events so that Cell doesn't have to depend on Notebook.
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 that.element.click(function (event) {
if (that.selected === false) {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 $([IPython.events]).trigger('select.Cell', {'cell':that});
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 }
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 });
that.element.focusin(function (event) {
if (that.selected === false) {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 $([IPython.events]).trigger('select.Cell', {'cell':that});
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 }
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 });
};
Brian Granger
Fixing auto-indent issues in CodeMirror config....
r5959
Brian Granger
Work on the base Cell API....
r5943 // typeset with MathJax if MathJax is available
Cell.prototype.typeset = function () {
if (window.MathJax){
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
};
Cell.prototype.select = function () {
this.element.addClass('ui-widget-content ui-corner-all');
this.selected = true;
};
Cell.prototype.unselect = function () {
this.element.removeClass('ui-widget-content ui-corner-all');
this.selected = false;
};
Cell.prototype.get_text = function () {
};
Cell.prototype.set_text = function (text) {
};
Cell.prototype.refresh = function () {
this.code_mirror.refresh();
};
Cell.prototype.edit = function () {
};
Cell.prototype.render = function () {
};
Cell.prototype.toJSON = function () {
MinRK
add empty metadata field on cells/worksheets...
r7523 var data = {};
data.metadata = this.metadata;
return data;
Brian Granger
Work on the base Cell API....
r5943 };
Cell.prototype.fromJSON = function (data) {
MinRK
add empty metadata field on cells/worksheets...
r7523 if (data.metadata !== undefined) {
this.metadata = data.metadata;
}
Brian Granger
Work on the base Cell API....
r5943 };
Brian Granger
Lots of small notebook improvements....
r5946 Cell.prototype.is_splittable = function () {
return true;
};
Cell.prototype.get_pre_cursor = function () {
var cursor = this.code_mirror.getCursor();
var text = this.code_mirror.getRange({line:0,ch:0}, cursor);
text = text.replace(/^\n+/, '').replace(/\n+$/, '');
return text;
}
Cell.prototype.get_post_cursor = function () {
var cursor = this.code_mirror.getCursor();
var last_line_num = this.code_mirror.lineCount()-1;
var last_line_len = this.code_mirror.getLine(last_line_num).length;
var end = {line:last_line_num, ch:last_line_len}
var text = this.code_mirror.getRange(cursor, end);
text = text.replace(/^\n+/, '').replace(/\n+$/, '');
return text;
};
Brian Granger
Fixing auto-indent issues in CodeMirror config....
r5959
Brian E. Granger
Adding Cell.grow back to fix bug....
r4400 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
// http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
var lines = dom.value.split(/\r|\r\n|\n/);
lines_count = lines.length;
if (lines_count >= 1) {
dom.rows = lines_count;
} else {
dom.rows = 1;
}
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian Granger
Making keyboard shortcut for showing line numbers consistent.
r6059 Cell.prototype.toggle_line_numbers = function () {
if (this.code_mirror.getOption('lineNumbers') == false) {
this.code_mirror.setOption('lineNumbers', true);
} else {
this.code_mirror.setOption('lineNumbers', false);
}
this.code_mirror.refresh();
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Cell = Cell;
return IPython;
}(IPython));
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349