##// END OF EJS Templates
Merge pull request #931 from minrk/readonly...
Merge pull request #931 from minrk/readonly The notebook now supports a `--read-only` flag, which allows users to view all notebooks being served but not to edit them or execute any code. These actions are not allowed and the buttons, shortcuts, etc. are removed, but the requests will raise authentication errors if they manage to send the events anyway. Save/print functions remain available. This flag can be used in two modes: 1. When running an unauthenticated server, one can run a *second* read-only server in the same directory on a public IP address. This will let users connect to the read-only view without having to worry about configuring passwords and certificates for the execution server. 2. When running a server configured with authentication (and hopefully an SSL certificate), starting it with `--read-only` allows unauthenticated users read-only access to notebooks. This means that the same server on a single port can be both used by authenticated users for execution and by the public for viewing the available notebooks.

File last commit:

r5200:4e4c27a3
r5219:80e60eb2 merge
Show More
cell.js
97 lines | 2.9 KiB | application/javascript | JavascriptLexer
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// Cell
//============================================================================
var IPython = (function (IPython) {
var utils = IPython.utils;
var Cell = function (notebook) {
this.notebook = notebook;
this.read_only = false;
if (notebook){
this.read_only = notebook.read_only;
}
this.selected = false;
this.element = null;
this.create_element();
if (this.element !== null) {
this.set_autoindent(true);
this.element.data("cell", this);
this.bind_events();
}
this.cell_id = utils.uuid();
};
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.bind_events = function () {
var that = this;
var nb = that.notebook
that.element.click(function (event) {
if (that.selected === false) {
nb.select(nb.find_cell_index(that));
};
});
that.element.focusin(function (event) {
if (that.selected === false) {
nb.select(nb.find_cell_index(that));
};
});
};
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;
}
};
Cell.prototype.set_autoindent = function (state) {
if (state) {
this.code_mirror.setOption('tabMode', 'indent');
this.code_mirror.setOption('enterMode', 'indent');
} else {
this.code_mirror.setOption('tabMode', 'shift');
this.code_mirror.setOption('enterMode', 'flat');
}
};
// Subclasses must implement create_element.
Cell.prototype.create_element = function () {};
IPython.Cell = Cell;
return IPython;
}(IPython));