Merge pull request #5980 from jdfreder/requirejs

use require.js
Min RK 12 years ago
commit 96832f6aca

@ -1,21 +1,12 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// On document ready
//============================================================================
$(document).ready(function () {
IPython.page = new IPython.Page();
var ipython = ipython || {};
require(['base/js/page'], function(page) {
var page_instance = new page.Page();
$('button#login_submit').addClass("btn btn-default");
IPython.page.show();
page_instance.show();
$('input#password_input').focus();
ipython.page = page_instance;
});

@ -1,20 +1,16 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// Login button
//============================================================================
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'base/js/utils',
'jquery',
], function(IPython, utils, $){
"use strict";
var LoginWidget = function (selector, options) {
options = options || {};
this.base_url = options.base_url || IPython.utils.get_body_data("baseUrl");
this.base_url = options.base_url || utils.get_body_data("baseUrl");
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
@ -31,13 +27,13 @@ var IPython = (function (IPython) {
LoginWidget.prototype.bind_events = function () {
var that = this;
this.element.find("button#logout").click(function () {
window.location = IPython.utils.url_join_encode(
window.location = utils.url_join_encode(
that.base_url,
"logout"
);
});
this.element.find("button#login").click(function () {
window.location = IPython.utils.url_join_encode(
window.location = utils.url_join_encode(
that.base_url,
"login"
);
@ -47,6 +43,5 @@ var IPython = (function (IPython) {
// Set module variables
IPython.LoginWidget = LoginWidget;
return IPython;
}(IPython));
return {'LoginWidget': LoginWidget};
});

@ -1,20 +1,11 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// On document ready
//============================================================================
$(document).ready(function () {
IPython.page = new IPython.Page();
var ipython = ipython || {};
require(['base/js/page'], function(page) {
var page_instance = new page.Page();
$('#ipython-main-app').addClass('border-box-sizing');
IPython.page.show();
page_instance.show();
ipython.page = page_instance;
});

@ -1,20 +1,14 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Utility for modal dialogs with bootstrap
//============================================================================
IPython.namespace('IPython.dialog');
IPython.dialog = (function (IPython) {
define([
'base/js/namespace',
'jquery',
], function(IPython, $) {
"use strict";
var modal = function (options) {
var modal = $("<div/>")
.addClass("modal")
.addClass("fade")
@ -79,26 +73,28 @@ IPython.dialog = (function (IPython) {
});
}
modal.on("hidden.bs.modal", function () {
if (IPython.notebook) {
var cell = IPython.notebook.get_selected_cell();
if (options.notebook) {
var cell = options.notebook.get_selected_cell();
if (cell) cell.select();
IPython.keyboard_manager.enable();
IPython.keyboard_manager.command_mode();
}
if (options.keyboard_manager) {
options.keyboard_manager.enable();
options.keyboard_manager.command_mode();
}
});
if (IPython.keyboard_manager) {
IPython.keyboard_manager.disable();
if (options.keyboard_manager) {
options.keyboard_manager.disable();
}
return modal.modal(options);
};
var edit_metadata = function (md, callback, name) {
name = name || "Cell";
var edit_metadata = function (options) {
options.name = options.name || "Cell";
var error_div = $('<div/>').css('color', 'red');
var message =
"Manually edit the JSON below to manipulate the metadata for this " + name + "." +
"Manually edit the JSON below to manipulate the metadata for this " + options.name + "." +
" We recommend putting custom metadata attributes in an appropriately named sub-structure," +
" so they don't conflict with those of others.";
@ -106,7 +102,7 @@ IPython.dialog = (function (IPython) {
.attr('rows', '13')
.attr('cols', '80')
.attr('name', 'metadata')
.text(JSON.stringify(md || {}, null, 2));
.text(JSON.stringify(options.md || {}, null, 2));
var dialogform = $('<div/>').attr('title', 'Edit the metadata')
.append(
@ -128,8 +124,8 @@ IPython.dialog = (function (IPython) {
autoIndent: true,
mode: 'application/json',
});
var modal = IPython.dialog.modal({
title: "Edit " + name + " Metadata",
var modal = modal({
title: "Edit " + options.name + " Metadata",
body: dialogform,
buttons: {
OK: { class : "btn-primary",
@ -143,19 +139,25 @@ IPython.dialog = (function (IPython) {
error_div.text('WARNING: Could not save invalid JSON.');
return false;
}
callback(new_md);
options.callback(new_md);
}
},
Cancel: {}
}
},
notebook: options.notebook,
keyboard_manager: options.keyboard_manager,
});
modal.on('shown.bs.modal', function(){ editor.refresh(); });
};
return {
var dialog = {
modal : modal,
edit_metadata : edit_metadata,
};
}(IPython));
// Backwards compatability.
IPython.dialog = dialog;
return dialog;
});

@ -1,13 +1,5 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// Events
//============================================================================
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
// Give us an object to bind all events to. This object should be created
// before all other objects so it exists when others register event handlers.
@ -15,18 +7,13 @@
// $([IPython.events]).trigger('event.Namespace');
// To handle it:
// $([IPython.events]).on('event.Namespace',function () {});
var IPython = (function (IPython) {
define(['base/js/namespace'], function(IPython) {
"use strict";
var utils = IPython.utils;
var Events = function () {};
// Backwards compatability.
IPython.Events = Events;
IPython.events = new Events();
return IPython;
}(IPython));
return {'Events': Events};
});

@ -1,19 +1,14 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Keyboard management
//============================================================================
IPython.namespace('IPython.keyboard');
IPython.keyboard = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
], function(IPython, $, utils) {
"use strict";
// Setup global keycodes and inverse keycodes.
// See http://unixpapa.com/js/key.html for a complete description. The short of
@ -51,8 +46,8 @@ IPython.keyboard = (function (IPython) {
'; :': 186, '= +': 187, '- _': 189
};
var browser = IPython.utils.browser[0];
var platform = IPython.utils.platform;
var browser = utils.browser[0];
var platform = utils.platform;
if (browser === 'Firefox' || browser === 'Opera' || browser === 'Netscape') {
$.extend(_keycodes, _mozilla_keycodes);
@ -130,18 +125,19 @@ IPython.keyboard = (function (IPython) {
// Shortcut manager class
var ShortcutManager = function (delay) {
var ShortcutManager = function (delay, events) {
this._shortcuts = {};
this._counts = {};
this._timers = {};
this.delay = delay || 800; // delay in milliseconds
this.events = events;
};
ShortcutManager.prototype.help = function () {
var help = [];
for (var shortcut in this._shortcuts) {
var help_string = this._shortcuts[shortcut]['help'];
var help_index = this._shortcuts[shortcut]['help_index'];
var help_string = this._shortcuts[shortcut].help;
var help_index = this._shortcuts[shortcut].help_index;
if (help_string) {
if (platform === 'MacOS') {
shortcut = shortcut.replace('meta', 'cmd');
@ -182,7 +178,7 @@ IPython.keyboard = (function (IPython) {
this._shortcuts[shortcut] = data;
if (!suppress_help_update) {
// update the keyboard shortcuts notebook help
$([IPython.events]).trigger('rebuild.QuickHelp');
this.events.trigger('rebuild.QuickHelp');
}
};
@ -191,7 +187,7 @@ IPython.keyboard = (function (IPython) {
this.add_shortcut(shortcut, data[shortcut], true);
}
// update the keyboard shortcuts notebook help
$([IPython.events]).trigger('rebuild.QuickHelp');
this.events.trigger('rebuild.QuickHelp');
};
ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) {
@ -200,7 +196,7 @@ IPython.keyboard = (function (IPython) {
delete this._shortcuts[shortcut];
if (!suppress_help_update) {
// update the keyboard shortcuts notebook help
$([IPython.events]).trigger('rebuild.QuickHelp');
this.events.trigger('rebuild.QuickHelp');
}
};
@ -211,7 +207,7 @@ IPython.keyboard = (function (IPython) {
var timer = null;
if (c[shortcut] === data.count-1) {
c[shortcut] = 0;
var timer = t[shortcut];
timer = t[shortcut];
if (timer) {clearTimeout(timer); delete t[shortcut];}
return data.handler(event);
} else {
@ -228,7 +224,7 @@ IPython.keyboard = (function (IPython) {
var shortcut = event_to_shortcut(event);
var data = this._shortcuts[shortcut];
if (data) {
var handler = data['handler'];
var handler = data.handler;
if (handler) {
if (data.count === 1) {
return handler(event);
@ -243,10 +239,10 @@ IPython.keyboard = (function (IPython) {
ShortcutManager.prototype.handles = function (event) {
var shortcut = event_to_shortcut(event);
var data = this._shortcuts[shortcut];
return !( data === undefined || data.handler === undefined )
}
return !( data === undefined || data.handler === undefined );
};
return {
var keyboard = {
keycodes : keycodes,
inv_keycodes : inv_keycodes,
ShortcutManager : ShortcutManager,
@ -256,4 +252,8 @@ IPython.keyboard = (function (IPython) {
event_to_shortcut : event_to_shortcut
};
}(IPython));
// For backwards compatability.
IPython.keyboard = keyboard;
return keyboard;
});

@ -1,34 +1,8 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
var IPython = IPython || {};
IPython.version = "3.0.0-dev";
IPython.namespace = function (ns_string) {
"use strict";
var parts = ns_string.split('.'),
parent = IPython,
i;
// String redundant leading global
if (parts[0] === "IPython") {
parts = parts.slice(1);
}
for (i=0; i<parts.length; i+=1) {
// Create property if it doesn't exist
if (typeof parent[parts[i]] === "undefined") {
parent[parts[i]] = {};
}
}
return parent;
};
define([], function(){
IPython.version = "3.0.0-dev";
return IPython;
});

@ -1,15 +1,10 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// Global header/site setup.
//============================================================================
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
], function(IPython, $){
"use strict";
var Page = function () {
@ -22,11 +17,9 @@ var IPython = (function (IPython) {
$('div#site').addClass('border-box-sizing');
};
Page.prototype.bind_events = function () {
};
Page.prototype.show = function () {
// The header and site divs start out hidden to prevent FLOUC.
// Main scripts should call this method after styling everything.
@ -34,23 +27,19 @@ var IPython = (function (IPython) {
this.show_site();
};
Page.prototype.show_header = function () {
// The header and site divs start out hidden to prevent FLOUC.
// Main scripts should call this method after styling everything.
$('div#header').css('display','block');
};
Page.prototype.show_site = function () {
// The header and site divs start out hidden to prevent FLOUC.
// Main scripts should call this method after styling everything.
$('div#site').css('display','block');
};
// Register self in the global namespace for convenience.
IPython.Page = Page;
return IPython;
}(IPython));
return {'Page': Page};
});

@ -1,20 +1,7 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// On document ready
//============================================================================
$(document).ready(function () {
"use strict";
IPython.page = new IPython.Page();
IPython.page.show();
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
require(['base/js/page'], function(page) {
var page_instance = new page.Page();
page_instance.show();
});

@ -1,19 +1,12 @@
//----------------------------------------------------------------------------
// Copyright (C) 2014 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Utilities
//============================================================================
IPython.namespace('IPython.security');
IPython.security = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'components/google-caja/html-css-sanitizer-minified',
], function(IPython, $) {
"use strict";
var utils = IPython.utils;
var noop = function (x) { return x; };
@ -117,10 +110,12 @@ IPython.security = (function (IPython) {
return sanitized;
};
return {
var security = {
caja: caja,
sanitize_html: sanitize_html
};
}(IPython));
IPython.security = security;
return security;
});

@ -1,13 +1,10 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Utilities
//============================================================================
IPython.namespace('IPython.utils');
IPython.utils = (function (IPython) {
define([
'base/js/namespace',
'jquery',
], function(IPython, $){
"use strict";
IPython.load_extensions = function () {
@ -528,8 +525,8 @@ IPython.utils = (function (IPython) {
}
console.log(msg);
};
return {
var utils = {
regex_split : regex_split,
uuid : uuid,
fixConsole : fixConsole,
@ -553,5 +550,8 @@ IPython.utils = (function (IPython) {
log_ajax_error : log_ajax_error,
};
}(IPython));
// Backwards compatability.
IPython.utils = utils;
return utils;
});

@ -17,7 +17,7 @@
* 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('app_initialized.NotebookApp', function(){
* IPython.events.on('app_initialized.NotebookApp', function(){
* IPython.toolbar.add_buttons_group([
* {
* 'label' : 'run qtconsole',
@ -35,7 +35,7 @@
* At the completion of the dashboard loading, load an unofficial javascript extension
* that is installed in profile/static/custom/
*
* $([IPython.events]).on('app_initialized.DashboardApp', function(){
* IPython.events.on('app_initialized.DashboardApp', function(){
* require(['custom/unofficial_extension.js'])
* });
*

@ -1,53 +1,60 @@
//----------------------------------------------------------------------------
// 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
//============================================================================
/**
* An extendable module that provide base functionnality to create cell for notebook.
* @module IPython
* @namespace IPython
* @submodule Cell
*/
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
], function(IPython, $, utils) {
"use strict";
var utils = IPython.utils;
var keycodes = IPython.keyboard.keycodes;
// monkey patch CM to be able to syntax highlight cell magics
// bug reported upstream,
// see https://github.com/marijnh/CodeMirror2/issues/670
if(CodeMirror.getMode(1,'text/plain').indent === undefined ){
CodeMirror.modes.null = function() {
return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}};
};
}
/**
* The Base `Cell` class from which to inherit
* @class Cell
**/
CodeMirror.patchedGetMode = function(config, mode){
var cmmode = CodeMirror.getMode(config, mode);
if(cmmode.indent === null) {
console.log('patch mode "' , mode, '" on the fly');
cmmode.indent = function(){return 0;};
}
return cmmode;
};
// end monkey patching CodeMirror
/*
* @constructor
*
* @param {object|undefined} [options]
* @param [options.cm_config] {object} config to pass to CodeMirror, will extend default parameters
*/
var Cell = function (options) {
options = this.mergeopt(Cell, options);
// Constructor
//
// The Base `Cell` class from which to inherit.
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// config: dictionary
// keyboard_manager: KeyboardManager instance
options = options || {};
this.keyboard_manager = options.keyboard_manager;
this.events = options.events;
var config = this.mergeopt(Cell, options.config);
// superclass default overwrite our default
this.placeholder = options.placeholder || '';
this.read_only = options.cm_config.readOnly;
this.placeholder = config.placeholder || '';
this.read_only = config.cm_config.readOnly;
this.selected = false;
this.rendered = false;
this.mode = 'command';
this.metadata = {};
// load this from metadata later ?
this.user_highlight = 'auto';
this.cm_config = options.cm_config;
this.cm_config = config.cm_config;
this.cell_id = utils.uuid();
this._options = options;
this._options = config;
// For JS VM engines optimization, attributes should be all set (even
// to null) in the constructor, and if possible, if different subclass
@ -132,27 +139,27 @@ var IPython = (function (IPython) {
// We trigger events so that Cell doesn't have to depend on Notebook.
that.element.click(function (event) {
if (!that.selected) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
that.events.trigger('select.Cell', {'cell':that});
}
});
that.element.focusin(function (event) {
if (!that.selected) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
that.events.trigger('select.Cell', {'cell':that});
}
});
if (this.code_mirror) {
this.code_mirror.on("change", function(cm, change) {
$([IPython.events]).trigger("set_dirty.Notebook", {value: true});
that.events.trigger("set_dirty.Notebook", {value: true});
});
}
if (this.code_mirror) {
this.code_mirror.on('focus', function(cm, change) {
$([IPython.events]).trigger('edit_mode.Cell', {cell: that});
that.events.trigger('edit_mode.Cell', {cell: that});
});
}
if (this.code_mirror) {
this.code_mirror.on('blur', function(cm, change) {
$([IPython.events]).trigger('command_mode.Cell', {cell: that});
that.events.trigger('command_mode.Cell', {cell: that});
});
}
};
@ -171,7 +178,7 @@ var IPython = (function (IPython) {
*/
Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
var that = this;
var shortcuts = IPython.keyboard_manager.edit_shortcuts;
var shortcuts = this.keyboard_manager.edit_shortcuts;
// if this is an edit_shortcuts shortcut, the global keyboard/shortcut
// manager will handle it
@ -549,9 +556,8 @@ var IPython = (function (IPython) {
this.code_mirror.setOption('mode', default_mode);
};
// Backwards compatability.
IPython.Cell = Cell;
return IPython;
}(IPython));
return {'Cell': Cell};
});

@ -1,32 +1,25 @@
//----------------------------------------------------------------------------
// Copyright (C) 2012 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.
//----------------------------------------------------------------------------
//============================================================================
// CellToolbar
//============================================================================
/**
* A Module to control the per-cell toolbar.
* @module IPython
* @namespace IPython
* @submodule CellToolbar
*/
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
], function(IPython, $) {
"use strict";
/**
* @constructor
* @class CellToolbar
* @param {The cell to attach the metadata UI to} cell
*/
var CellToolbar = function (cell) {
var CellToolbar = function (options) {
// Constructor
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// cell: Cell instance
// notebook: Notebook instance
CellToolbar._instances.push(this);
this.cell = cell;
this.notebook = options.notebook;
this.events = options.events;
this.cell = options.cell;
this.create_element();
this.rebuild();
return this;
@ -34,7 +27,7 @@ var IPython = (function (IPython) {
CellToolbar.prototype.create_element = function () {
this.inner_element = $('<div/>').addClass('celltoolbar')
this.inner_element = $('<div/>').addClass('celltoolbar');
this.element = $('<div/>').addClass('ctb_hideshow')
.append(this.inner_element);
};
@ -182,13 +175,13 @@ var IPython = (function (IPython) {
* CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
* CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
*/
CellToolbar.register_preset = function(name, preset_list) {
CellToolbar.register_preset = function(name, preset_list, notebook, events) {
CellToolbar._presets[name] = preset_list;
$([IPython.events]).trigger('preset_added.CellToolbar', {name: name});
events.trigger('preset_added.CellToolbar', {name: name});
// When "register_callback" is called by a custom extension, it may be executed after notebook is loaded.
// In that case, activate the preset if needed.
if (IPython.notebook && IPython.notebook.metadata && IPython.notebook.metadata.celltoolbar === name)
this.activate_preset(name);
if (notebook && notebook.metadata && notebook.metadata.celltoolbar === name)
CellToolbar.activate_preset(name, events);
};
@ -221,7 +214,7 @@ var IPython = (function (IPython) {
*
* CellToolbar.activate_preset('foo.foo_preset1');
*/
CellToolbar.activate_preset = function(preset_name){
CellToolbar.activate_preset = function(preset_name, events){
var preset = CellToolbar._presets[preset_name];
if(preset !== undefined){
@ -229,7 +222,9 @@ var IPython = (function (IPython) {
CellToolbar.rebuild_all();
}
$([IPython.events]).trigger('preset_activated.CellToolbar', {name: preset_name});
if (events) {
events.trigger('preset_activated.CellToolbar', {name: preset_name});
}
};
@ -283,7 +278,7 @@ var IPython = (function (IPython) {
}
// If there are no controls or the cell is a rendered TextCell hide the toolbar.
if (!this.ui_controls_list.length || (this.cell instanceof IPython.TextCell && this.cell.rendered)) {
if (!this.ui_controls_list.length || (this.cell_type != 'code' && this.cell.rendered)) {
this.hide();
} else {
this.show();
@ -415,8 +410,8 @@ var IPython = (function (IPython) {
};
};
// Backwards compatability.
IPython.CellToolbar = CellToolbar;
return IPython;
}(IPython));
return {'CellToolbar': CellToolbar};
});

@ -1,31 +1,23 @@
//----------------------------------------------------------------------------
// Copyright (C) 2012 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.
//----------------------------------------------------------------------------
//============================================================================
// CellToolbar Default
//============================================================================
/**
* Example Use for the CellToolbar library
*/
// IIFE without asignement, we don't modifiy the IPython namespace
(function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'jquery',
'notebook/js/celltoolbar',
'base/js/dialog',
], function($, celltoolbar, dialog) {
"use strict";
var CellToolbar = IPython.CellToolbar;
var CellToolbar = celltoolbar.CellToolbar;
var raw_edit = function(cell){
IPython.dialog.edit_metadata(cell.metadata, function (md) {
dialog.edit_metadata(cell.metadata, function (md) {
cell.metadata = md;
});
};
var add_raw_edit_button = function(div, cell) {
var button_container = div;
var button_container = $(div);
var button = $('<button/>')
.addClass("btn btn-default btn-xs")
.text("Edit Metadata")
@ -36,11 +28,13 @@
button_container.append(button);
};
CellToolbar.register_callback('default.rawedit', add_raw_edit_button);
var example_preset = [];
example_preset.push('default.rawedit');
var register = function (notebook, events) {
CellToolbar.register_callback('default.rawedit', add_raw_edit_button);
var example_preset = [];
example_preset.push('default.rawedit');
CellToolbar.register_preset('Edit Metadata', example_preset);
console.log('Default extension for cell metadata editing loaded.');
}(IPython));
CellToolbar.register_preset('Edit Metadata', example_preset, notebook, events);
console.log('Default extension for cell metadata editing loaded.');
};
return {'register': register};
});

@ -1,28 +1,20 @@
//----------------------------------------------------------------------------
// Copyright (C) 2012 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.
//----------------------------------------------------------------------------
//============================================================================
// CellToolbar Example
//============================================================================
/**
* Example Use for the CellToolbar library
* add the following to your custom.js to load
* Celltoolbar UI for slideshow
*
* ```
* $.getScript('/static/js/celltoolbarpresets/example.js');
* ```
*/
// IIFE without asignement, we don't modifiy the IPython namespace
(function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
// Example Use for the CellToolbar library
// add the following to your custom.js to load
// Celltoolbar UI for slideshow
// ```
// $.getScript('/static/js/celltoolbarpresets/example.js');
// ```
define([
'jquery',
'notebook/js/celltoolbar',
], function($, celltoolbar) {
"use strict";
var CellToolbar = IPython.CellToolbar;
var CellToolbar = celltoolbar.CellToolbar;
var example_preset = [];
@ -32,32 +24,32 @@
var fun = function(value){
try{
if(value){
cell.code_mirror.setOption('readOnly','nocursor')
button.button('option','icons',{primary:'ui-icon-locked'})
cell.code_mirror.setOption('readOnly','nocursor');
button.button('option','icons',{primary:'ui-icon-locked'});
} else {
cell.code_mirror.setOption('readOnly',false)
button.button('option','icons',{primary:'ui-icon-unlocked'})
cell.code_mirror.setOption('readOnly',false);
button.button('option','icons',{primary:'ui-icon-unlocked'});
}
} catch(e){}
}
fun(cell.metadata.ro)
};
fun(cell.metadata.ro);
button.click(function(){
var v = cell.metadata.ro;
var locked = !v;
cell.metadata.ro = locked;
fun(locked)
fun(locked);
})
.css('height','16px')
.css('width','35px');
button_container.append(button);
}
};
CellToolbar.register_callback('example.lock',simple_button);
example_preset.push('example.lock');
var toggle_test = function(div, cell) {
var button_container = $(div)
var button_container = $(div);
var button = $('<div/>')
.button({label:String(cell.metadata.foo)}).
css('width','65px');
@ -65,9 +57,9 @@
var v = cell.metadata.foo;
cell.metadata.foo = !v;
button.button("option","label",String(!v));
})
});
button_container.append(button);
}
};
CellToolbar.register_callback('example.toggle',toggle_test);
example_preset.push('example.toggle');
@ -76,16 +68,16 @@
// setter
function(cell, value){
// we check that the slideshow namespace exist and create it if needed
if (cell.metadata.yn_test == undefined){cell.metadata.yn_test = {}}
if (cell.metadata.yn_test === undefined){cell.metadata.yn_test = {};}
// set the value
cell.metadata.yn_test.value = value
cell.metadata.yn_test.value = value;
},
//geter
function(cell){ var ns = cell.metadata.yn_test;
// if the slideshow namespace does not exist return `undefined`
// (will be interpreted as `false` by checkbox) otherwise
// return the value
return (ns == undefined)? undefined: ns.value
return (ns === undefined)? undefined: ns.value;
}
);
@ -103,16 +95,16 @@
// setter
function(cell,value){
// we check that the slideshow namespace exist and create it if needed
if (cell.metadata.test == undefined){cell.metadata.test = {}}
if (cell.metadata.test === undefined){cell.metadata.test = {};}
// set the value
cell.metadata.test.slide_type = value
cell.metadata.test.slide_type = value;
},
//geter
function(cell){ var ns = cell.metadata.test;
// if the slideshow namespace does not exist return `undefined`
// (will be interpreted as `false` by checkbox) otherwise
// return the value
return (ns == undefined)? undefined: ns.slide_type
return (ns === undefined)? undefined: ns.slide_type;
});
CellToolbar.register_callback('example.select',select_test);
@ -120,7 +112,7 @@
var simple_dialog = function(title,text){
var dlg = $('<div/>').attr('title',title)
.append($('<p/>').text(text))
.append($('<p/>').text(text));
$(dlg).dialog({
autoOpen: true,
height: 300,
@ -131,24 +123,26 @@
$(this).remove();
}
});
}
};
var add_simple_dialog_button = function(div, cell) {
var help_text = ["This is the Metadata editting UI.",
"It heavily rely on plugin to work ",
"and is still under developpement. You shouldn't wait too long before",
" seeing some customisable buttons in those toolbar."
].join('\n')
var button_container = $(div)
].join('\n');
var button_container = $(div);
var button = $('<div/>').button({label:'?'})
.click(function(){simple_dialog('help',help_text); return false;})
.click(function(){simple_dialog('help',help_text); return false;});
button_container.append(button);
}
CellToolbar.register_callback('example.help',add_simple_dialog_button)
example_preset.push('example.help')
};
CellToolbar.register_preset('Example',example_preset);
console.log('Example extension for metadata editing loaded.');
var register = function (notebook, events) {
CellToolbar.register_callback('example.help',add_simple_dialog_button);
example_preset.push('example.help');
}(IPython));
CellToolbar.register_preset('Example',example_preset, notebook, events);
console.log('Example extension for metadata editing loaded.');
};
return {'register': register};
});

@ -1,18 +1,15 @@
//----------------------------------------------------------------------------
// Copyright (C) 2012 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// CellToolbar Example
//============================================================================
define([
'jquery',
'notebook/js/celltoolbar',
'base/js/dialog',
'base/js/keyboard',
], function($, celltoolbar, dialog, keyboard) {
"use strict";
(function(IPython) {
"use strict";
var CellToolbar = IPython.CellToolbar;
var CellToolbar = celltoolbar.CellToolbar;
var raw_cell_preset = [];
var select_type = CellToolbar.utils.select_ui_generator([
@ -39,7 +36,7 @@
$('<input/>').attr('type','text').attr('size','25')
.val(cell.metadata.raw_mimetype || "-")
);
IPython.dialog.modal({
dialog.modal({
title: "Raw Cell MIME Type",
body: dialog,
buttons : {
@ -57,7 +54,7 @@
var that = $(this);
// Upon ENTER, click the OK button.
that.find('input[type="text"]').keydown(function (event, ui) {
if (event.which === IPython.keyboard.keycodes.enter) {
if (event.which === keyboard.keycodes.enter) {
that.find('.btn-primary').first().click();
return false;
}
@ -77,11 +74,13 @@
"Raw NBConvert Format"
);
CellToolbar.register_callback('raw_cell.select', select_type, ['raw']);
raw_cell_preset.push('raw_cell.select');
var register = function (notebook, events) {
CellToolbar.register_callback('raw_cell.select', select_type, ['raw']);
raw_cell_preset.push('raw_cell.select');
CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
console.log('Raw Cell Format toolbar preset loaded.');
CellToolbar.register_preset('Raw Cell Format', raw_cell_preset, notebook, events);
console.log('Raw Cell Format toolbar preset loaded.');
};
return {'register': register};
}(IPython));
});

@ -1,19 +1,14 @@
//----------------------------------------------------------------------------
// Copyright (C) 2012 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
//CellToolbar Example
//============================================================================
// IIFE without asignement, we don't modifiy the IPython namespace
(function (IPython) {
define([
'jquery',
'notebook/js/celltoolbar',
], function($, celltoolbar) {
"use strict";
var CellToolbar = IPython.CellToolbar;
var CellToolbar = celltoolbar.CellToolbar;
var slideshow_preset = [];
var select_type = CellToolbar.utils.select_ui_generator([
@ -27,24 +22,25 @@
// setter
function(cell, value){
// we check that the slideshow namespace exist and create it if needed
if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
if (cell.metadata.slideshow === undefined){cell.metadata.slideshow = {};}
// set the value
cell.metadata.slideshow.slide_type = value
cell.metadata.slideshow.slide_type = value;
},
//geter
function(cell){ var ns = cell.metadata.slideshow;
// if the slideshow namespace does not exist return `undefined`
// (will be interpreted as `false` by checkbox) otherwise
// return the value
return (ns == undefined)? undefined: ns.slide_type
return (ns === undefined)? undefined: ns.slide_type;
},
"Slide Type");
CellToolbar.register_callback('slideshow.select',select_type);
slideshow_preset.push('slideshow.select');
CellToolbar.register_preset('Slideshow',slideshow_preset);
console.log('Slideshow extension for metadata editing loaded.');
var register = function (notebook, events) {
CellToolbar.register_callback('slideshow.select',select_type);
slideshow_preset.push('slideshow.select');
}(IPython));
CellToolbar.register_preset('Slideshow',slideshow_preset, notebook, events);
console.log('Slideshow extension for metadata editing loaded.');
};
return {'register': register};
});

@ -1,68 +1,67 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// CodeCell
//============================================================================
/**
* An extendable module that provide base functionnality to create cell for notebook.
* @module IPython
* @namespace IPython
* @submodule CodeCell
*/
/* local util for codemirror */
var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
/**
*
* function to delete until previous non blanking space character
* or first multiple of 4 tabstop.
* @private
*/
CodeMirror.commands.delSpaceToPrevTabStop = function(cm){
var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
if (!posEq(from, to)) { cm.replaceRange("", from, to); return; }
var cur = cm.getCursor(), line = cm.getLine(cur.line);
var tabsize = cm.getOption('tabSize');
var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
from = {ch:cur.ch-chToPrevTabStop,line:cur.line};
var select = cm.getRange(from,cur);
if( select.match(/^\ +$/) !== null){
cm.replaceRange("",from,cur);
} else {
cm.deleteH(-1,"char");
}
};
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/keyboard',
'notebook/js/cell',
'notebook/js/outputarea',
'notebook/js/completer',
'notebook/js/celltoolbar',
], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar) {
"use strict";
var Cell = cell.Cell;
var utils = IPython.utils;
var keycodes = IPython.keyboard.keycodes;
/* local util for codemirror */
var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
/**
* 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
* @param {object|undefined} [options]
* @param [options.cm_config] {object} config to pass to CodeMirror
* function to delete until previous non blanking space character
* or first multiple of 4 tabstop.
* @private
*/
CodeMirror.commands.delSpaceToPrevTabStop = function(cm){
var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
if (!posEq(from, to)) { cm.replaceRange("", from, to); return; }
var cur = cm.getCursor(), line = cm.getLine(cur.line);
var tabsize = cm.getOption('tabSize');
var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
from = {ch:cur.ch-chToPrevTabStop,line:cur.line};
var select = cm.getRange(from,cur);
if( select.match(/^\ +$/) !== null){
cm.replaceRange("",from,cur);
} else {
cm.deleteH(-1,"char");
}
};
var keycodes = keyboard.keycodes;
var CodeCell = function (kernel, options) {
// Constructor
//
// A Cell conceived to write code.
//
// Parameters:
// kernel: Kernel instance
// 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.
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// config: dictionary
// keyboard_manager: KeyboardManager instance
// notebook: Notebook instance
// tooltip: Tooltip instance
this.kernel = kernel || null;
this.notebook = options.notebook;
this.collapsed = false;
this.events = options.events;
this.tooltip = options.tooltip;
this.config = options.config;
// create all attributed in constructor function
// even if null for V8 VM optimisation
@ -77,9 +76,11 @@ var IPython = (function (IPython) {
onKeyEvent: $.proxy(this.handle_keyevent,this)
};
options = this.mergeopt(CodeCell, options, {cm_config:cm_overwrite_options});
IPython.Cell.apply(this,[options]);
var config = this.mergeopt(CodeCell, this.config, {cm_config: cm_overwrite_options});
Cell.apply(this,[{
config: config,
keyboard_manager: options.keyboard_manager,
events: this.events}]);
// Attributes we want to override in this subclass.
this.cell_type = "code";
@ -109,18 +110,18 @@ var IPython = (function (IPython) {
CodeCell.msg_cells = {};
CodeCell.prototype = new IPython.Cell();
CodeCell.prototype = new Cell();
/**
* @method auto_highlight
*/
CodeCell.prototype.auto_highlight = function () {
this._auto_highlight(IPython.config.cell_magic_highlight);
this._auto_highlight(this.config.cell_magic_highlight);
};
/** @method create_element */
CodeCell.prototype.create_element = function () {
IPython.Cell.prototype.create_element.apply(this, arguments);
Cell.prototype.create_element.apply(this, arguments);
var cell = $('<div></div>').addClass('cell border-box-sizing code_cell');
cell.attr('tabindex','2');
@ -128,10 +129,13 @@ var IPython = (function (IPython) {
var input = $('<div></div>').addClass('input');
var prompt = $('<div/>').addClass('prompt input_prompt');
var inner_cell = $('<div/>').addClass('inner_cell');
this.celltoolbar = new IPython.CellToolbar(this);
this.celltoolbar = new celltoolbar.CellToolbar({
cell: this,
events: this.events,
notebook: this.notebook});
inner_cell.append(this.celltoolbar.element);
var input_area = $('<div/>').addClass('input_area');
this.code_mirror = CodeMirror(input_area.get(0), this.cm_config);
this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
$(this.code_mirror.getInputField()).attr("spellcheck", "false");
inner_cell.append(input_area);
input.append(prompt).append(inner_cell);
@ -158,13 +162,17 @@ var IPython = (function (IPython) {
var output = $('<div></div>');
cell.append(input).append(widget_area).append(output);
this.element = cell;
this.output_area = new IPython.OutputArea(output, true);
this.completer = new IPython.Completer(this);
this.output_area = new outputarea.OutputArea({
selector: output,
prompt_area: true,
events: this.events,
keyboard_manager: this.keyboard_manager});
this.completer = new completer.Completer(this, this.events);
};
/** @method bind_events */
CodeCell.prototype.bind_events = function () {
IPython.Cell.prototype.bind_events.apply(this);
Cell.prototype.bind_events.apply(this);
var that = this;
this.element.focusout(
@ -187,7 +195,7 @@ var IPython = (function (IPython) {
// they are sent, and remove tooltip if any, except for tab again
var tooltip_closed = null;
if (event.type === 'keydown' && event.which != keycodes.tab ) {
tooltip_closed = IPython.tooltip.remove_and_cancel_tooltip();
tooltip_closed = this.tooltip.remove_and_cancel_tooltip();
}
var cur = editor.getCursor();
@ -195,21 +203,21 @@ var IPython = (function (IPython) {
this.auto_highlight();
}
if (event.which === keycodes.down && event.type === 'keypress' && IPython.tooltip.time_before_tooltip >= 0) {
if (event.which === keycodes.down && event.type === 'keypress' && this.tooltip.time_before_tooltip >= 0) {
// triger on keypress (!) otherwise inconsistent event.which depending on plateform
// browser and keyboard layout !
// Pressing '(' , request tooltip, don't forget to reappend it
// The second argument says to hide the tooltip if the docstring
// is actually empty
IPython.tooltip.pending(that, true);
this.tooltip.pending(that, true);
} else if ( tooltip_closed && event.which === keycodes.esc && event.type === 'keydown') {
// If tooltip is active, cancel it. The call to
// remove_and_cancel_tooltip above doesn't pass, force=true.
// Because of this it won't actually close the tooltip
// if it is in sticky mode. Thus, we have to check again if it is open
// and close it with force=true.
if (!IPython.tooltip._hidden) {
IPython.tooltip.remove_and_cancel_tooltip(true);
if (!this.tooltip._hidden) {
this.tooltip.remove_and_cancel_tooltip(true);
}
// If we closed the tooltip, don't let CM or the global handlers
// handle this event.
@ -223,12 +231,12 @@ var IPython = (function (IPython) {
return false;
}
}
IPython.tooltip.request(that);
this.tooltip.request(that);
event.stop();
return true;
} else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
// Tab completion.
IPython.tooltip.remove_and_cancel_tooltip();
this.tooltip.remove_and_cancel_tooltip();
if (editor.somethingSelected()) {
return false;
}
@ -246,7 +254,7 @@ var IPython = (function (IPython) {
// keyboard event wasn't one of those unique to code cells, let's see
// if it's one of the generic ones (i.e. check edit mode shortcuts)
return IPython.Cell.prototype.handle_codemirror_keyevent.apply(this, [editor, event]);
return Cell.prototype.handle_codemirror_keyevent.apply(this, [editor, event]);
};
// Kernel related calls.
@ -305,7 +313,7 @@ var IPython = (function (IPython) {
};
CodeCell.prototype._open_with_pager = function (payload) {
$([IPython.events]).trigger('open_with_text.Pager', payload);
this.events.trigger('open_with_text.Pager', payload);
};
/**
@ -315,7 +323,7 @@ var IPython = (function (IPython) {
CodeCell.prototype._handle_execute_reply = function (msg) {
this.set_input_prompt(msg.content.execution_count);
this.element.removeClass("running");
$([IPython.events]).trigger('set_dirty.Notebook', {value: true});
this.events.trigger('set_dirty.Notebook', {value: true});
};
/**
@ -324,7 +332,7 @@ var IPython = (function (IPython) {
*/
CodeCell.prototype._handle_set_next_input = function (payload) {
var data = {'cell': this, 'text': payload.text};
$([IPython.events]).trigger('set_next_input.Notebook', data);
this.events.trigger('set_next_input.Notebook', data);
};
/**
@ -339,7 +347,7 @@ var IPython = (function (IPython) {
// Basic cell manipulation.
CodeCell.prototype.select = function () {
var cont = IPython.Cell.prototype.select.apply(this);
var cont = Cell.prototype.select.apply(this);
if (cont) {
this.code_mirror.refresh();
this.auto_highlight();
@ -348,7 +356,7 @@ var IPython = (function (IPython) {
};
CodeCell.prototype.render = function () {
var cont = IPython.Cell.prototype.render.apply(this);
var cont = Cell.prototype.render.apply(this);
// Always execute, even if we are already in the rendered state
return cont;
};
@ -451,7 +459,7 @@ var IPython = (function (IPython) {
// JSON serialization
CodeCell.prototype.fromJSON = function (data) {
IPython.Cell.prototype.fromJSON.apply(this, arguments);
Cell.prototype.fromJSON.apply(this, arguments);
if (data.cell_type === 'code') {
if (data.input !== undefined) {
this.set_text(data.input);
@ -479,7 +487,7 @@ var IPython = (function (IPython) {
CodeCell.prototype.toJSON = function () {
var data = IPython.Cell.prototype.toJSON.apply(this);
var data = Cell.prototype.toJSON.apply(this);
data.input = this.get_text();
// is finite protect against undefined and '*' value
if (isFinite(this.input_prompt_number)) {
@ -499,11 +507,11 @@ var IPython = (function (IPython) {
* @return is the action being taken
*/
CodeCell.prototype.unselect = function () {
var cont = IPython.Cell.prototype.unselect.apply(this);
var cont = Cell.prototype.unselect.apply(this);
if (cont) {
// When a code cell is usnelected, make sure that the corresponding
// tooltip and completer to that cell is closed.
IPython.tooltip.remove_and_cancel_tooltip(true);
this.tooltip.remove_and_cancel_tooltip(true);
if (this.completer !== null) {
this.completer.close();
}
@ -511,7 +519,8 @@ var IPython = (function (IPython) {
return cont;
};
// Backwards compatability.
IPython.CodeCell = CodeCell;
return IPython;
}(IPython));
return {'CodeCell': CodeCell};
});

@ -8,7 +8,6 @@
CodeMirror.requireMode('gfm', function(){
CodeMirror.requireMode('stex', function(){
console.log('defining custom mode...');
CodeMirror.defineMode("ipythongfm", function(config, parserConfig) {
var gfm_mode = CodeMirror.getMode(config, "gfm");

@ -1,17 +1,17 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
// Completer
//
// Completer is be a class that takes a cell instance.
var IPython = (function (IPython) {
// that will prevent us from misspelling
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/keyboard',
'notebook/js/contexthint',
], function(IPython, $, utils, keyboard) {
"use strict";
// easier key mapping
var keycodes = IPython.keyboard.keycodes;
var utils = IPython.utils;
var keycodes = keyboard.keycodes;
var prepend_n_prc = function(str, n) {
for( var i =0 ; i< n ; i++){
@ -78,14 +78,14 @@ var IPython = (function (IPython) {
}
var Completer = function (cell) {
var Completer = function (cell, events) {
this.cell = cell;
this.editor = cell.code_mirror;
var that = this;
$([IPython.events]).on('status_busy.Kernel', function () {
events.on('status_busy.Kernel', function () {
that.skip_kernel_completion = true;
});
$([IPython.events]).on('status_idle.Kernel', function () {
events.on('status_idle.Kernel', function () {
that.skip_kernel_completion = false;
});
};
@ -379,7 +379,9 @@ var IPython = (function (IPython) {
that.carry_on_completion();
}, 50);
};
// For backwards compatability.
IPython.Completer = Completer;
return IPython;
}(IPython));
return {'Completer': Completer};
});

@ -1,12 +1,15 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
// highly adapted for codemiror jshint
(function () {
define([], function() {
"use strict";
function forEach(arr, f) {
var forEach = function(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
};
function arrayContains(arr, item) {
var arrayContains = function(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
@ -17,7 +20,7 @@
return false;
}
return arr.indexOf(item) != -1;
}
};
CodeMirror.contextHint = function (editor) {
// Find the token at the cursor
@ -26,7 +29,7 @@
tprop = token;
// If it's not a 'word-style' token, ignore the token.
// If it is a property, find out what it is a property of.
var list = new Array();
var list = [];
var clist = getCompletions(token, editor);
for (var i = 0; i < clist.length; i++) {
list.push({
@ -40,55 +43,56 @@
line: cur.line,
ch: token.end
}
})
});
}
return list;
}
};
// find all 'words' of current cell
var getAllTokens = function (editor) {
var found = [];
var found = [];
// add to found if not already in it
// add to found if not already in it
function maybeAdd(str) {
if (!arrayContains(found, str)) found.push(str);
}
function maybeAdd(str) {
if (!arrayContains(found, str)) found.push(str);
}
// loop through all token on all lines
var lineCount = editor.lineCount();
// loop on line
for (var l = 0; l < lineCount; l++) {
var line = editor.getLine(l);
//loop on char
for (var c = 1; c < line.length; c++) {
var tk = editor.getTokenAt({
line: l,
ch: c
});
// if token has a class, it has geat chances of beeing
// of interest. Add it to the list of possible completions.
// we could skip token of ClassName 'comment'
// or 'number' and 'operator'
if (tk.className != null) {
maybeAdd(tk.string);
}
// jump to char after end of current token
c = tk.end;
// loop through all token on all lines
var lineCount = editor.lineCount();
// loop on line
for (var l = 0; l < lineCount; l++) {
var line = editor.getLine(l);
//loop on char
for (var c = 1; c < line.length; c++) {
var tk = editor.getTokenAt({
line: l,
ch: c
});
// if token has a class, it has geat chances of beeing
// of interest. Add it to the list of possible completions.
// we could skip token of ClassName 'comment'
// or 'number' and 'operator'
if (tk.className !== null) {
maybeAdd(tk.string);
}
// jump to char after end of current token
c = tk.end;
}
return found;
}
return found;
};
function getCompletions(token, editor) {
var getCompletions = function(token, editor) {
var candidates = getAllTokens(editor);
// filter all token that have a common start (but nox exactly) the lenght of the current token
var lambda = function (x) {
return (x.indexOf(token.string) == 0 && x != token.string)
return (x.indexOf(token.string) === 0 && x != token.string);
};
var filterd = candidates.filter(lambda);
return filterd;
}
})();
};
return {'contextHint': CodeMirror.contextHint};
});

@ -1,468 +1,476 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Keyboard management
//============================================================================
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/keyboard',
], function(IPython, $, utils, keyboard) {
"use strict";
var browser = utils.browser[0];
var platform = utils.platform;
var browser = IPython.utils.browser[0];
var platform = IPython.utils.platform;
// Main keyboard manager for the notebook
var keycodes = keyboard.keycodes;
// Default keyboard shortcuts
var KeyboardManager = function (options) {
// Constructor
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// pager: Pager instance
this.mode = 'command';
this.enabled = true;
this.pager = options.pager;
this.quick_help = undefined;
this.notebook = undefined;
this.bind_events();
this.command_shortcuts = new keyboard.ShortcutManager(undefined, options.events);
this.command_shortcuts.add_shortcuts(this.get_default_common_shortcuts());
this.command_shortcuts.add_shortcuts(this.get_default_command_shortcuts());
this.edit_shortcuts = new keyboard.ShortcutManager(undefined, options.events);
this.edit_shortcuts.add_shortcuts(this.get_default_common_shortcuts());
this.edit_shortcuts.add_shortcuts(this.get_default_edit_shortcuts());
};
var default_common_shortcuts = {
'shift' : {
help : '',
help_index : '',
handler : function (event) {
// ignore shift keydown
return true;
}
},
'shift-enter' : {
help : 'run cell, select below',
help_index : 'ba',
handler : function (event) {
IPython.notebook.execute_cell_and_select_below();
return false;
}
},
'ctrl-enter' : {
help : 'run cell',
help_index : 'bb',
handler : function (event) {
IPython.notebook.execute_cell();
return false;
}
},
'alt-enter' : {
help : 'run cell, insert below',
help_index : 'bc',
handler : function (event) {
IPython.notebook.execute_cell_and_insert_below();
return false;
KeyboardManager.prototype.get_default_common_shortcuts = function() {
var that = this;
var shortcuts = {
'shift' : {
help : '',
help_index : '',
handler : function (event) {
// ignore shift keydown
return true;
}
},
'shift-enter' : {
help : 'run cell, select below',
help_index : 'ba',
handler : function (event) {
that.notebook.execute_cell_and_select_below();
return false;
}
},
'ctrl-enter' : {
help : 'run cell',
help_index : 'bb',
handler : function (event) {
that.notebook.execute_cell();
return false;
}
},
'alt-enter' : {
help : 'run cell, insert below',
help_index : 'bc',
handler : function (event) {
that.notebook.execute_cell_and_insert_below();
return false;
}
}
};
if (platform === 'MacOS') {
shortcuts['cmd-s'] =
{
help : 'save notebook',
help_index : 'fb',
handler : function (event) {
that.notebook.save_checkpoint();
event.preventDefault();
return false;
}
};
} else {
shortcuts['ctrl-s'] =
{
help : 'save notebook',
help_index : 'fb',
handler : function (event) {
that.notebook.save_checkpoint();
event.preventDefault();
return false;
}
};
}
return shortcuts;
};
if (platform === 'MacOS') {
default_common_shortcuts['cmd-s'] =
{
help : 'save notebook',
help_index : 'fb',
KeyboardManager.prototype.get_default_edit_shortcuts = function() {
var that = this;
return {
'esc' : {
help : 'command mode',
help_index : 'aa',
handler : function (event) {
IPython.notebook.save_checkpoint();
event.preventDefault();
that.notebook.command_mode();
return false;
}
};
} else {
default_common_shortcuts['ctrl-s'] =
{
help : 'save notebook',
help_index : 'fb',
},
'ctrl-m' : {
help : 'command mode',
help_index : 'ab',
handler : function (event) {
IPython.notebook.save_checkpoint();
event.preventDefault();
that.notebook.command_mode();
return false;
}
};
}
// Edit mode defaults
var default_edit_shortcuts = {
'esc' : {
help : 'command mode',
help_index : 'aa',
handler : function (event) {
IPython.notebook.command_mode();
return false;
}
},
'ctrl-m' : {
help : 'command mode',
help_index : 'ab',
handler : function (event) {
IPython.notebook.command_mode();
return false;
}
},
'up' : {
help : '',
help_index : '',
handler : function (event) {
var index = IPython.notebook.get_selected_index();
var cell = IPython.notebook.get_cell(index);
if (cell && cell.at_top() && index !== 0) {
event.preventDefault();
IPython.notebook.command_mode();
IPython.notebook.select_prev();
IPython.notebook.edit_mode();
var cm = IPython.notebook.get_selected_cell().code_mirror;
cm.setCursor(cm.lastLine(), 0);
return false;
} else if (cell) {
var cm = cell.code_mirror;
cm.execCommand('goLineUp');
},
'up' : {
help : '',
help_index : '',
handler : function (event) {
var index = that.notebook.get_selected_index();
var cell = that.notebook.get_cell(index);
if (cell && cell.at_top() && index !== 0) {
event.preventDefault();
that.notebook.command_mode();
that.notebook.select_prev();
that.notebook.edit_mode();
var cm = that.notebook.get_selected_cell().code_mirror;
cm.setCursor(cm.lastLine(), 0);
return false;
} else if (cell) {
var cm = cell.code_mirror;
cm.execCommand('goLineUp');
return false;
}
}
},
'down' : {
help : '',
help_index : '',
handler : function (event) {
var index = that.notebook.get_selected_index();
var cell = that.notebook.get_cell(index);
if (cell.at_bottom() && index !== (that.notebook.ncells()-1)) {
event.preventDefault();
that.notebook.command_mode();
that.notebook.select_next();
that.notebook.edit_mode();
var cm = that.notebook.get_selected_cell().code_mirror;
cm.setCursor(0, 0);
return false;
} else {
var cm = cell.code_mirror;
cm.execCommand('goLineDown');
return false;
}
}
},
'ctrl-shift--' : {
help : 'split cell',
help_index : 'ea',
handler : function (event) {
that.notebook.split_cell();
return false;
}
}
},
'down' : {
help : '',
help_index : '',
handler : function (event) {
var index = IPython.notebook.get_selected_index();
var cell = IPython.notebook.get_cell(index);
if (cell.at_bottom() && index !== (IPython.notebook.ncells()-1)) {
event.preventDefault();
IPython.notebook.command_mode();
IPython.notebook.select_next();
IPython.notebook.edit_mode();
var cm = IPython.notebook.get_selected_cell().code_mirror;
cm.setCursor(0, 0);
return false;
} else {
var cm = cell.code_mirror;
cm.execCommand('goLineDown');
},
'ctrl-shift-subtract' : {
help : '',
help_index : 'eb',
handler : function (event) {
that.notebook.split_cell();
return false;
}
}
},
'ctrl-shift--' : {
help : 'split cell',
help_index : 'ea',
handler : function (event) {
IPython.notebook.split_cell();
return false;
}
},
'ctrl-shift-subtract' : {
help : '',
help_index : 'eb',
handler : function (event) {
IPython.notebook.split_cell();
return false;
}
},
},
};
};
// Command mode defaults
var default_command_shortcuts = {
'enter' : {
help : 'edit mode',
help_index : 'aa',
handler : function (event) {
IPython.notebook.edit_mode();
return false;
}
},
'up' : {
help : 'select previous cell',
help_index : 'da',
handler : function (event) {
var index = IPython.notebook.get_selected_index();
if (index !== 0 && index !== null) {
IPython.notebook.select_prev();
IPython.notebook.focus_cell();
KeyboardManager.prototype.get_default_command_shortcuts = function() {
var that = this;
return {
'enter' : {
help : 'edit mode',
help_index : 'aa',
handler : function (event) {
that.notebook.edit_mode();
return false;
}
return false;
}
},
'down' : {
help : 'select next cell',
help_index : 'db',
handler : function (event) {
var index = IPython.notebook.get_selected_index();
if (index !== (IPython.notebook.ncells()-1) && index !== null) {
IPython.notebook.select_next();
IPython.notebook.focus_cell();
},
'up' : {
help : 'select previous cell',
help_index : 'da',
handler : function (event) {
var index = that.notebook.get_selected_index();
if (index !== 0 && index !== null) {
that.notebook.select_prev();
that.notebook.focus_cell();
}
return false;
}
return false;
}
},
'k' : {
help : 'select previous cell',
help_index : 'dc',
handler : function (event) {
var index = IPython.notebook.get_selected_index();
if (index !== 0 && index !== null) {
IPython.notebook.select_prev();
IPython.notebook.focus_cell();
},
'down' : {
help : 'select next cell',
help_index : 'db',
handler : function (event) {
var index = that.notebook.get_selected_index();
if (index !== (that.notebook.ncells()-1) && index !== null) {
that.notebook.select_next();
that.notebook.focus_cell();
}
return false;
}
return false;
}
},
'j' : {
help : 'select next cell',
help_index : 'dd',
handler : function (event) {
var index = IPython.notebook.get_selected_index();
if (index !== (IPython.notebook.ncells()-1) && index !== null) {
IPython.notebook.select_next();
IPython.notebook.focus_cell();
},
'k' : {
help : 'select previous cell',
help_index : 'dc',
handler : function (event) {
var index = that.notebook.get_selected_index();
if (index !== 0 && index !== null) {
that.notebook.select_prev();
that.notebook.focus_cell();
}
return false;
}
return false;
}
},
'x' : {
help : 'cut cell',
help_index : 'ee',
handler : function (event) {
IPython.notebook.cut_cell();
return false;
}
},
'c' : {
help : 'copy cell',
help_index : 'ef',
handler : function (event) {
IPython.notebook.copy_cell();
return false;
}
},
'shift-v' : {
help : 'paste cell above',
help_index : 'eg',
handler : function (event) {
IPython.notebook.paste_cell_above();
return false;
}
},
'v' : {
help : 'paste cell below',
help_index : 'eh',
handler : function (event) {
IPython.notebook.paste_cell_below();
return false;
}
},
'd' : {
help : 'delete cell (press twice)',
help_index : 'ej',
count: 2,
handler : function (event) {
IPython.notebook.delete_cell();
return false;
}
},
'a' : {
help : 'insert cell above',
help_index : 'ec',
handler : function (event) {
IPython.notebook.insert_cell_above();
IPython.notebook.select_prev();
IPython.notebook.focus_cell();
return false;
}
},
'b' : {
help : 'insert cell below',
help_index : 'ed',
handler : function (event) {
IPython.notebook.insert_cell_below();
IPython.notebook.select_next();
IPython.notebook.focus_cell();
return false;
}
},
'y' : {
help : 'to code',
help_index : 'ca',
handler : function (event) {
IPython.notebook.to_code();
return false;
}
},
'm' : {
help : 'to markdown',
help_index : 'cb',
handler : function (event) {
IPython.notebook.to_markdown();
return false;
}
},
'r' : {
help : 'to raw',
help_index : 'cc',
handler : function (event) {
IPython.notebook.to_raw();
return false;
}
},
'1' : {
help : 'to heading 1',
help_index : 'cd',
handler : function (event) {
IPython.notebook.to_heading(undefined, 1);
return false;
}
},
'2' : {
help : 'to heading 2',
help_index : 'ce',
handler : function (event) {
IPython.notebook.to_heading(undefined, 2);
return false;
}
},
'3' : {
help : 'to heading 3',
help_index : 'cf',
handler : function (event) {
IPython.notebook.to_heading(undefined, 3);
return false;
}
},
'4' : {
help : 'to heading 4',
help_index : 'cg',
handler : function (event) {
IPython.notebook.to_heading(undefined, 4);
return false;
}
},
'5' : {
help : 'to heading 5',
help_index : 'ch',
handler : function (event) {
IPython.notebook.to_heading(undefined, 5);
return false;
}
},
'6' : {
help : 'to heading 6',
help_index : 'ci',
handler : function (event) {
IPython.notebook.to_heading(undefined, 6);
return false;
}
},
'o' : {
help : 'toggle output',
help_index : 'gb',
handler : function (event) {
IPython.notebook.toggle_output();
return false;
}
},
'shift-o' : {
help : 'toggle output scrolling',
help_index : 'gc',
handler : function (event) {
IPython.notebook.toggle_output_scroll();
return false;
}
},
's' : {
help : 'save notebook',
help_index : 'fa',
handler : function (event) {
IPython.notebook.save_checkpoint();
return false;
}
},
'ctrl-j' : {
help : 'move cell down',
help_index : 'eb',
handler : function (event) {
IPython.notebook.move_cell_down();
return false;
}
},
'ctrl-k' : {
help : 'move cell up',
help_index : 'ea',
handler : function (event) {
IPython.notebook.move_cell_up();
return false;
}
},
'l' : {
help : 'toggle line numbers',
help_index : 'ga',
handler : function (event) {
IPython.notebook.cell_toggle_line_numbers();
return false;
}
},
'i' : {
help : 'interrupt kernel (press twice)',
help_index : 'ha',
count: 2,
handler : function (event) {
IPython.notebook.kernel.interrupt();
return false;
}
},
'0' : {
help : 'restart kernel (press twice)',
help_index : 'hb',
count: 2,
handler : function (event) {
IPython.notebook.restart_kernel();
return false;
}
},
'h' : {
help : 'keyboard shortcuts',
help_index : 'ge',
handler : function (event) {
IPython.quick_help.show_keyboard_shortcuts();
return false;
}
},
'z' : {
help : 'undo last delete',
help_index : 'ei',
handler : function (event) {
IPython.notebook.undelete_cell();
return false;
}
},
'shift-m' : {
help : 'merge cell below',
help_index : 'ek',
handler : function (event) {
IPython.notebook.merge_cell_below();
return false;
}
},
'q' : {
help : 'close pager',
help_index : 'gd',
handler : function (event) {
IPython.pager.collapse();
return false;
}
},
};
// Main keyboard manager for the notebook
var ShortcutManager = IPython.keyboard.ShortcutManager;
var keycodes = IPython.keyboard.keycodes;
var KeyboardManager = function () {
this.mode = 'command';
this.enabled = true;
this.bind_events();
this.command_shortcuts = new ShortcutManager();
this.command_shortcuts.add_shortcuts(default_common_shortcuts);
this.command_shortcuts.add_shortcuts(default_command_shortcuts);
this.edit_shortcuts = new ShortcutManager();
this.edit_shortcuts.add_shortcuts(default_common_shortcuts);
this.edit_shortcuts.add_shortcuts(default_edit_shortcuts);
},
'j' : {
help : 'select next cell',
help_index : 'dd',
handler : function (event) {
var index = that.notebook.get_selected_index();
if (index !== (that.notebook.ncells()-1) && index !== null) {
that.notebook.select_next();
that.notebook.focus_cell();
}
return false;
}
},
'x' : {
help : 'cut cell',
help_index : 'ee',
handler : function (event) {
that.notebook.cut_cell();
return false;
}
},
'c' : {
help : 'copy cell',
help_index : 'ef',
handler : function (event) {
that.notebook.copy_cell();
return false;
}
},
'shift-v' : {
help : 'paste cell above',
help_index : 'eg',
handler : function (event) {
that.notebook.paste_cell_above();
return false;
}
},
'v' : {
help : 'paste cell below',
help_index : 'eh',
handler : function (event) {
that.notebook.paste_cell_below();
return false;
}
},
'd' : {
help : 'delete cell (press twice)',
help_index : 'ej',
count: 2,
handler : function (event) {
that.notebook.delete_cell();
return false;
}
},
'a' : {
help : 'insert cell above',
help_index : 'ec',
handler : function (event) {
that.notebook.insert_cell_above();
that.notebook.select_prev();
that.notebook.focus_cell();
return false;
}
},
'b' : {
help : 'insert cell below',
help_index : 'ed',
handler : function (event) {
that.notebook.insert_cell_below();
that.notebook.select_next();
that.notebook.focus_cell();
return false;
}
},
'y' : {
help : 'to code',
help_index : 'ca',
handler : function (event) {
that.notebook.to_code();
return false;
}
},
'm' : {
help : 'to markdown',
help_index : 'cb',
handler : function (event) {
that.notebook.to_markdown();
return false;
}
},
'r' : {
help : 'to raw',
help_index : 'cc',
handler : function (event) {
that.notebook.to_raw();
return false;
}
},
'1' : {
help : 'to heading 1',
help_index : 'cd',
handler : function (event) {
that.notebook.to_heading(undefined, 1);
return false;
}
},
'2' : {
help : 'to heading 2',
help_index : 'ce',
handler : function (event) {
that.notebook.to_heading(undefined, 2);
return false;
}
},
'3' : {
help : 'to heading 3',
help_index : 'cf',
handler : function (event) {
that.notebook.to_heading(undefined, 3);
return false;
}
},
'4' : {
help : 'to heading 4',
help_index : 'cg',
handler : function (event) {
that.notebook.to_heading(undefined, 4);
return false;
}
},
'5' : {
help : 'to heading 5',
help_index : 'ch',
handler : function (event) {
that.notebook.to_heading(undefined, 5);
return false;
}
},
'6' : {
help : 'to heading 6',
help_index : 'ci',
handler : function (event) {
that.notebook.to_heading(undefined, 6);
return false;
}
},
'o' : {
help : 'toggle output',
help_index : 'gb',
handler : function (event) {
that.notebook.toggle_output();
return false;
}
},
'shift-o' : {
help : 'toggle output scrolling',
help_index : 'gc',
handler : function (event) {
that.notebook.toggle_output_scroll();
return false;
}
},
's' : {
help : 'save notebook',
help_index : 'fa',
handler : function (event) {
that.notebook.save_checkpoint();
return false;
}
},
'ctrl-j' : {
help : 'move cell down',
help_index : 'eb',
handler : function (event) {
that.notebook.move_cell_down();
return false;
}
},
'ctrl-k' : {
help : 'move cell up',
help_index : 'ea',
handler : function (event) {
that.notebook.move_cell_up();
return false;
}
},
'l' : {
help : 'toggle line numbers',
help_index : 'ga',
handler : function (event) {
that.notebook.cell_toggle_line_numbers();
return false;
}
},
'i' : {
help : 'interrupt kernel (press twice)',
help_index : 'ha',
count: 2,
handler : function (event) {
that.notebook.kernel.interrupt();
return false;
}
},
'0' : {
help : 'restart kernel (press twice)',
help_index : 'hb',
count: 2,
handler : function (event) {
that.notebook.restart_kernel();
return false;
}
},
'h' : {
help : 'keyboard shortcuts',
help_index : 'ge',
handler : function (event) {
that.quick_help.show_keyboard_shortcuts();
return false;
}
},
'z' : {
help : 'undo last delete',
help_index : 'ei',
handler : function (event) {
that.notebook.undelete_cell();
return false;
}
},
'shift-m' : {
help : 'merge cell below',
help_index : 'ek',
handler : function (event) {
that.notebook.merge_cell_below();
return false;
}
},
'q' : {
help : 'close pager',
help_index : 'gd',
handler : function (event) {
that.pager.collapse();
return false;
}
},
};
};
KeyboardManager.prototype.bind_events = function () {
@ -473,7 +481,7 @@ var IPython = (function (IPython) {
};
KeyboardManager.prototype.handle_keydown = function (event) {
var notebook = IPython.notebook;
var notebook = this.notebook;
if (event.which === keycodes.esc) {
// Intercept escape at highest level to avoid closing
@ -545,18 +553,14 @@ var IPython = (function (IPython) {
// is_focused must be used to check for the case where an element within
// the element being removed is focused.
e.on('remove', function () {
if (IPython.utils.is_focused(e[0])) {
if (utils.is_focused(e[0])) {
that.enable();
}
});
};
IPython.default_common_shortcuts = default_common_shortcuts;
IPython.default_edit_shortcuts = default_edit_shortcuts;
IPython.default_command_shortcuts = default_command_shortcuts;
// For backwards compatability.
IPython.KeyboardManager = KeyboardManager;
return IPython;
}(IPython));
return {'KeyboardManager': KeyboardManager};
});

@ -1,78 +1,93 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// On document ready
//============================================================================
// for the time beeing, we have to pass marked as a parameter here,
// as injecting require.js make marked not to put itself in the globals,
// which make both this file fail at setting marked configuration, and textcell.js
// which search marked into global.
require(['components/marked/lib/marked',
'widgets/js/init',
'components/bootstrap-tour/build/js/bootstrap-tour.min'],
function (marked) {
require([
'base/js/namespace',
'jquery',
'notebook/js/notebook',
'base/js/utils',
'base/js/page',
'notebook/js/layoutmanager',
'base/js/events',
'auth/js/loginwidget',
'notebook/js/maintoolbar',
'notebook/js/pager',
'notebook/js/quickhelp',
'notebook/js/menubar',
'notebook/js/notificationarea',
'notebook/js/savewidget',
'notebook/js/keyboardmanager',
'notebook/js/config',
], function(
IPython,
$,
notebook,
utils,
page,
layoutmanager,
events,
loginwidget,
maintoolbar,
pager,
quickhelp,
menubar,
notificationarea,
savewidget,
keyboardmanager,
config
) {
"use strict";
window.marked = marked;
// monkey patch CM to be able to syntax highlight cell magics
// bug reported upstream,
// see https://github.com/marijnh/CodeMirror2/issues/670
if(CodeMirror.getMode(1,'text/plain').indent === undefined ){
console.log('patching CM for undefined indent');
CodeMirror.modes.null = function() {
return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}};
};
}
CodeMirror.patchedGetMode = function(config, mode){
var cmmode = CodeMirror.getMode(config, mode);
if(cmmode.indent === null) {
console.log('patch mode "' , mode, '" on the fly');
cmmode.indent = function(){return 0;};
}
return cmmode;
};
// end monkey patching CodeMirror
IPython.mathjaxutils.init();
$('#ipython-main-app').addClass('border-box-sizing');
$('div#notebook_panel').addClass('border-box-sizing');
var opts = {
base_url : IPython.utils.get_body_data("baseUrl"),
notebook_path : IPython.utils.get_body_data("notebookPath"),
notebook_name : IPython.utils.get_body_data('notebookName')
var common_options = {
base_url : utils.get_body_data("baseUrl"),
notebook_path : utils.get_body_data("notebookPath"),
notebook_name : utils.get_body_data('notebookName')
};
IPython.page = new IPython.Page();
IPython.layout_manager = new IPython.LayoutManager();
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
IPython.quick_help = new IPython.QuickHelp();
try {
IPython.tour = new IPython.NotebookTour();
} catch (e) {
console.log("Failed to instantiate Notebook Tour", e);
}
IPython.login_widget = new IPython.LoginWidget('span#login_widget', opts);
IPython.notebook = new IPython.Notebook('div#notebook', opts);
IPython.keyboard_manager = new IPython.KeyboardManager();
IPython.save_widget = new IPython.SaveWidget('span#save_widget');
IPython.menubar = new IPython.MenuBar('#menubar', opts);
IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container');
IPython.tooltip = new IPython.Tooltip();
IPython.notification_area = new IPython.NotificationArea('#notification_area');
IPython.notification_area.init_notification_widgets();
IPython.layout_manager.do_resize();
var user_config = $.extend({}, config.default_config);
var page = new page.Page();
var layout_manager = new layoutmanager.LayoutManager();
var events = $([new events.Events()]);
var pager = new pager.Pager('div#pager', 'div#pager_splitter', {
layout_manager: layout_manager,
events: events});
var keyboard_manager = new keyboardmanager.KeyboardManager({
pager: pager,
events: events});
var save_widget = new savewidget.SaveWidget('span#save_widget', {
events: events,
keyboard_manager: keyboard_manager});
var notebook = new notebook.Notebook('div#notebook', $.extend({
events: events,
keyboard_manager: keyboard_manager,
save_widget: save_widget,
config: user_config},
common_options));
var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options);
var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', {
notebook: notebook,
events: events});
var quick_help = new quickhelp.QuickHelp({
keyboard_manager: keyboard_manager,
events: events,
notebook: notebook});
var menubar = new menubar.MenuBar('#menubar', $.extend({
notebook: notebook,
layout_manager: layout_manager,
events: events,
save_widget: save_widget,
quick_help: quick_help},
common_options));
var notification_area = new notificationarea.NotificationArea(
'#notification_area', {
events: events,
save_widget: save_widget,
notebook: notebook,
keyboard_manager: keyboard_manager});
notification_area.init_notification_widgets();
$('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+
'<span id="test2" style="font-weight: bold;">x</span>'+
@ -85,43 +100,37 @@ function (marked) {
}
$('#fonttest').remove();
IPython.page.show();
page.show();
IPython.layout_manager.do_resize();
layout_manager.do_resize();
var first_load = function () {
IPython.layout_manager.do_resize();
layout_manager.do_resize();
var hash = document.location.hash;
if (hash) {
document.location.hash = '';
document.location.hash = hash;
}
IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval);
notebook.set_autosave_interval(notebook.minimum_autosave_interval);
// only do this once
$([IPython.events]).off('notebook_loaded.Notebook', first_load);
events.off('notebook_loaded.Notebook', first_load);
};
$([IPython.events]).on('notebook_loaded.Notebook', first_load);
$([IPython.events]).trigger('app_initialized.NotebookApp');
IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path);
events.on('notebook_loaded.Notebook', first_load);
events.trigger('app_initialized.NotebookApp');
notebook.load_notebook(common_options.notebook_name, common_options.notebook_path);
if (marked) {
marked.setOptions({
gfm : true,
tables: true,
langPrefix: "language-",
highlight: function(code, lang) {
if (!lang) {
// no language, no highlight
return code;
}
var highlighted;
try {
highlighted = hljs.highlight(lang, code, false);
} catch(err) {
highlighted = hljs.highlightAuto(code);
}
return highlighted.value;
}
});
}
IPython.page = page;
IPython.layout_manager = layout_manager;
IPython.notebook = notebook;
IPython.pager = pager;
IPython.quick_help = quick_help;
IPython.login_widget = login_widget;
IPython.menubar = menubar;
IPython.toolbar = toolbar;
IPython.notification_area = notification_area;
IPython.events = events;
IPython.keyboard_manager = keyboard_manager;
IPython.save_widget = save_widget;
IPython.config = user_config;
IPython.tooltip = notebook.tooltip;
});

@ -1,35 +1,43 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
//============================================================================
// ToolBar
//============================================================================
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'notebook/js/toolbar',
'notebook/js/celltoolbar',
], function(IPython, $, toolbar, celltoolbar) {
"use strict";
var MainToolBar = function (selector) {
IPython.ToolBar.apply(this, arguments);
var MainToolBar = function (selector, options) {
// Constructor
//
// Parameters:
// selector: string
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// notebook: Notebook instance
toolbar.ToolBar.apply(this, arguments);
this.events = options.events;
this.notebook = options.notebook;
this.construct();
this.add_celltype_list();
this.add_celltoolbar_list();
this.bind_events();
};
MainToolBar.prototype = new IPython.ToolBar();
MainToolBar.prototype = new toolbar.ToolBar();
MainToolBar.prototype.construct = function () {
var that = this;
this.add_buttons_group([
{
id : 'save_b',
label : 'Save and Checkpoint',
icon : 'icon-save',
callback : function () {
IPython.notebook.save_checkpoint();
that.notebook.save_checkpoint();
}
}
]);
@ -40,9 +48,9 @@ var IPython = (function (IPython) {
label : 'Insert Cell Below',
icon : 'icon-plus-sign',
callback : function () {
IPython.notebook.insert_cell_below('code');
IPython.notebook.select_next();
IPython.notebook.focus_cell();
that.notebook.insert_cell_below('code');
that.notebook.select_next();
that.notebook.focus_cell();
}
}
],'insert_above_below');
@ -53,7 +61,7 @@ var IPython = (function (IPython) {
label : 'Cut Cell',
icon : 'icon-cut',
callback : function () {
IPython.notebook.cut_cell();
that.notebook.cut_cell();
}
},
{
@ -61,7 +69,7 @@ var IPython = (function (IPython) {
label : 'Copy Cell',
icon : 'icon-copy',
callback : function () {
IPython.notebook.copy_cell();
that.notebook.copy_cell();
}
},
{
@ -69,7 +77,7 @@ var IPython = (function (IPython) {
label : 'Paste Cell Below',
icon : 'icon-paste',
callback : function () {
IPython.notebook.paste_cell_below();
that.notebook.paste_cell_below();
}
}
],'cut_copy_paste');
@ -80,7 +88,7 @@ var IPython = (function (IPython) {
label : 'Move Cell Up',
icon : 'icon-arrow-up',
callback : function () {
IPython.notebook.move_cell_up();
that.notebook.move_cell_up();
}
},
{
@ -88,7 +96,7 @@ var IPython = (function (IPython) {
label : 'Move Cell Down',
icon : 'icon-arrow-down',
callback : function () {
IPython.notebook.move_cell_down();
that.notebook.move_cell_down();
}
}
],'move_up_down');
@ -101,7 +109,7 @@ var IPython = (function (IPython) {
icon : 'icon-play',
callback : function () {
// emulate default shift-enter behavior
IPython.notebook.execute_cell_and_select_below();
that.notebook.execute_cell_and_select_below();
}
},
{
@ -109,7 +117,7 @@ var IPython = (function (IPython) {
label : 'Interrupt',
icon : 'icon-stop',
callback : function () {
IPython.notebook.session.interrupt_kernel();
that.notebook.session.interrupt_kernel();
}
},
{
@ -117,7 +125,7 @@ var IPython = (function (IPython) {
label : 'Restart Kernel',
icon : 'icon-repeat',
callback : function () {
IPython.notebook.restart_kernel();
that.notebook.restart_kernel();
}
}
],'run_int');
@ -150,30 +158,31 @@ var IPython = (function (IPython) {
.addClass('form-control select-xs')
.append($('<option/>').attr('value', '').text('None'));
this.element.append(label).append(select);
var that = this;
select.change(function() {
var val = $(this).val()
if (val =='') {
IPython.CellToolbar.global_hide();
delete IPython.notebook.metadata.celltoolbar;
var val = $(this).val();
if (val ==='') {
celltoolbar.CellToolbar.global_hide();
delete that.notebook.metadata.celltoolbar;
} else {
IPython.CellToolbar.global_show();
IPython.CellToolbar.activate_preset(val);
IPython.notebook.metadata.celltoolbar = val;
celltoolbar.CellToolbar.global_show();
celltoolbar.CellToolbar.activate_preset(val, that.events);
that.notebook.metadata.celltoolbar = val;
}
});
// Setup the currently registered presets.
var presets = IPython.CellToolbar.list_presets();
var presets = celltoolbar.CellToolbar.list_presets();
for (var i=0; i<presets.length; i++) {
var name = presets[i];
select.append($('<option/>').attr('value', name).text(name));
}
// Setup future preset registrations.
$([IPython.events]).on('preset_added.CellToolbar', function (event, data) {
this.events.on('preset_added.CellToolbar', function (event, data) {
var name = data.name;
select.append($('<option/>').attr('value', name).text(name));
});
// Update select value when a preset is activated.
$([IPython.events]).on('preset_activated.CellToolbar', function (event, data) {
this.events.on('preset_activated.CellToolbar', function (event, data) {
if (select.val() !== data.name)
select.val(data.name);
});
@ -186,26 +195,26 @@ var IPython = (function (IPython) {
this.element.find('#cell_type').change(function () {
var cell_type = $(this).val();
if (cell_type === 'code') {
IPython.notebook.to_code();
that.notebook.to_code();
} else if (cell_type === 'markdown') {
IPython.notebook.to_markdown();
that.notebook.to_markdown();
} else if (cell_type === 'raw') {
IPython.notebook.to_raw();
that.notebook.to_raw();
} else if (cell_type === 'heading1') {
IPython.notebook.to_heading(undefined, 1);
that.notebook.to_heading(undefined, 1);
} else if (cell_type === 'heading2') {
IPython.notebook.to_heading(undefined, 2);
that.notebook.to_heading(undefined, 2);
} else if (cell_type === 'heading3') {
IPython.notebook.to_heading(undefined, 3);
that.notebook.to_heading(undefined, 3);
} else if (cell_type === 'heading4') {
IPython.notebook.to_heading(undefined, 4);
that.notebook.to_heading(undefined, 4);
} else if (cell_type === 'heading5') {
IPython.notebook.to_heading(undefined, 5);
that.notebook.to_heading(undefined, 5);
} else if (cell_type === 'heading6') {
IPython.notebook.to_heading(undefined, 6);
that.notebook.to_heading(undefined, 6);
}
});
$([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) {
this.events.on('selected_cell_type_changed.Notebook', function (event, data) {
if (data.cell_type === 'heading') {
that.element.find('#cell_type').val(data.cell_type+data.level);
} else {
@ -214,8 +223,8 @@ var IPython = (function (IPython) {
});
};
// Backwards compatability.
IPython.MainToolBar = MainToolBar;
return IPython;
}(IPython));
return {'MainToolBar': MainToolBar};
});

@ -1,18 +1,12 @@
//----------------------------------------------------------------------------
// Copyright (C) 2008-2012 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.
//----------------------------------------------------------------------------
//============================================================================
// MathJax utility functions
//============================================================================
IPython.namespace('IPython.mathjaxutils');
IPython.mathjaxutils = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/dialog',
], function(IPython, $, utils, dialog) {
"use strict";
var init = function () {
@ -75,7 +69,7 @@ IPython.mathjaxutils = (function (IPython) {
"which will prevent this dialog from appearing."
)
);
IPython.dialog.modal({
dialog.modal({
title : "Failed to retrieve MathJax from '" + window.mathjax_url + "'",
body : message,
buttons : {
@ -110,7 +104,7 @@ IPython.mathjaxutils = (function (IPython) {
.replace(/</g, "&lt;") // use HTML entity for <
.replace(/>/g, "&gt;") // use HTML entity for >
;
if (IPython.utils.browser === 'msie') {
if (utils.browser === 'msie') {
block = block.replace(/(%[^\n]*)\n/g, "$1<br/>\n");
}
while (j > i) {
@ -159,7 +153,7 @@ IPython.mathjaxutils = (function (IPython) {
de_tilde = function (text) { return text; };
}
var blocks = IPython.utils.regex_split(text.replace(/\r\n?/g, "\n"),MATHSPLIT);
var blocks = utils.regex_split(text.replace(/\r\n?/g, "\n"),MATHSPLIT);
for (var i = 1, m = blocks.length; i < m; i += 2) {
var block = blocks[i];
@ -242,10 +236,13 @@ IPython.mathjaxutils = (function (IPython) {
return text;
};
return {
var mathjaxutils = {
init : init,
remove_math : remove_math,
replace_math : replace_math
};
}(IPython));
IPython.mathjaxutils = mathjaxutils;
return mathjaxutils;
});

@ -1,40 +1,48 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// MenuBar
//============================================================================
/**
* @module IPython
* @namespace IPython
* @submodule MenuBar
*/
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'notebook/js/tour',
'components/bootstrap/js/bootstrap.min',
], function(IPython, $, utils, tour) {
"use strict";
var utils = IPython.utils;
/**
* A MenuBar Class to generate the menubar of IPython notebook
* @Class MenuBar
*
* @constructor
*
*
* @param selector {string} selector for the menubar element in DOM
* @param {object} [options]
* @param [options.base_url] {String} String to use for the
* base project url. Default is to inspect
* $('body').data('baseUrl');
* does not support change for now is set through this option
*/
var MenuBar = function (selector, options) {
// Constructor
//
// A MenuBar Class to generate the menubar of IPython notebook
//
// Parameters:
// selector: string
// options: dictionary
// Dictionary of keyword arguments.
// notebook: Notebook instance
// layout_manager: LayoutManager instance
// events: $(Events) instance
// save_widget: SaveWidget instance
// quick_help: QuickHelp instance
// base_url : string
// notebook_path : string
// notebook_name : string
options = options || {};
this.base_url = options.base_url || IPython.utils.get_body_data("baseUrl");
this.base_url = options.base_url || utils.get_body_data("baseUrl");
this.selector = selector;
this.notebook = options.notebook;
this.layout_manager = options.layout_manager;
this.events = options.events;
this.save_widget = options.save_widget;
this.quick_help = options.quick_help;
try {
this.tour = new tour.Tour(this.notebook, this.events);
} catch (e) {
this.tour = undefined;
console.log("Failed to instantiate Notebook Tour", e);
}
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
@ -43,22 +51,23 @@ var IPython = (function (IPython) {
};
MenuBar.prototype.style = function () {
var that = this;
this.element.addClass('border-box-sizing');
this.element.find("li").click(function (event, ui) {
// The selected cell loses focus when the menu is entered, so we
// re-select it upon selection.
var i = IPython.notebook.get_selected_index();
IPython.notebook.select(i);
var i = that.notebook.get_selected_index();
that.notebook.select(i);
}
);
};
MenuBar.prototype._nbconvert = function (format, download) {
download = download || false;
var notebook_path = IPython.notebook.notebook_path;
var notebook_name = IPython.notebook.notebook_name;
if (IPython.notebook.dirty) {
IPython.notebook.save_notebook({async : false});
var notebook_path = this.notebook.notebook_path;
var notebook_name = this.notebook.notebook_name;
if (this.notebook.dirty) {
this.notebook.save_notebook({async : false});
}
var url = utils.url_join_encode(
this.base_url,
@ -75,25 +84,25 @@ var IPython = (function (IPython) {
// File
var that = this;
this.element.find('#new_notebook').click(function () {
IPython.notebook.new_notebook();
that.notebook.new_notebook();
});
this.element.find('#open_notebook').click(function () {
window.open(utils.url_join_encode(
IPython.notebook.base_url,
that.notebook.base_url,
'tree',
IPython.notebook.notebook_path
that.notebook.notebook_path
));
});
this.element.find('#copy_notebook').click(function () {
IPython.notebook.copy_notebook();
that.notebook.copy_notebook();
return false;
});
this.element.find('#download_ipynb').click(function () {
var base_url = IPython.notebook.base_url;
var notebook_path = IPython.notebook.notebook_path;
var notebook_name = IPython.notebook.notebook_name;
if (IPython.notebook.dirty) {
IPython.notebook.save_notebook({async : false});
var base_url = that.notebook.base_url;
var notebook_path = that.notebook.notebook_path;
var notebook_name = that.notebook.notebook_name;
if (that.notebook.dirty) {
that.notebook.save_notebook({async : false});
}
var url = utils.url_join_encode(
@ -126,17 +135,17 @@ var IPython = (function (IPython) {
});
this.element.find('#rename_notebook').click(function () {
IPython.save_widget.rename_notebook();
that.save_widget.rename_notebook({notebook: that.notebook});
});
this.element.find('#save_checkpoint').click(function () {
IPython.notebook.save_checkpoint();
that.notebook.save_checkpoint();
});
this.element.find('#restore_checkpoint').click(function () {
});
this.element.find('#trust_notebook').click(function () {
IPython.notebook.trust_notebook();
that.notebook.trust_notebook();
});
$([IPython.events]).on('trust_changed.Notebook', function (event, trusted) {
this.events.on('trust_changed.Notebook', function (event, trusted) {
if (trusted) {
that.element.find('#trust_notebook')
.addClass("disabled")
@ -148,7 +157,7 @@ var IPython = (function (IPython) {
}
});
this.element.find('#kill_and_exit').click(function () {
IPython.notebook.session.delete();
that.notebook.session.delete();
setTimeout(function(){
// allow closing of new tabs in Chromium, impossible in FF
window.open('', '_self', '');
@ -157,148 +166,150 @@ var IPython = (function (IPython) {
});
// Edit
this.element.find('#cut_cell').click(function () {
IPython.notebook.cut_cell();
that.notebook.cut_cell();
});
this.element.find('#copy_cell').click(function () {
IPython.notebook.copy_cell();
that.notebook.copy_cell();
});
this.element.find('#delete_cell').click(function () {
IPython.notebook.delete_cell();
that.notebook.delete_cell();
});
this.element.find('#undelete_cell').click(function () {
IPython.notebook.undelete_cell();
that.notebook.undelete_cell();
});
this.element.find('#split_cell').click(function () {
IPython.notebook.split_cell();
that.notebook.split_cell();
});
this.element.find('#merge_cell_above').click(function () {
IPython.notebook.merge_cell_above();
that.notebook.merge_cell_above();
});
this.element.find('#merge_cell_below').click(function () {
IPython.notebook.merge_cell_below();
that.notebook.merge_cell_below();
});
this.element.find('#move_cell_up').click(function () {
IPython.notebook.move_cell_up();
that.notebook.move_cell_up();
});
this.element.find('#move_cell_down').click(function () {
IPython.notebook.move_cell_down();
that.notebook.move_cell_down();
});
this.element.find('#edit_nb_metadata').click(function () {
IPython.notebook.edit_metadata();
that.notebook.edit_metadata({
notebook: that.notebook,
keyboard_manager: that.notebook.keyboard_manager});
});
// View
this.element.find('#toggle_header').click(function () {
$('div#header').toggle();
IPython.layout_manager.do_resize();
that.layout_manager.do_resize();
});
this.element.find('#toggle_toolbar').click(function () {
$('div#maintoolbar').toggle();
IPython.layout_manager.do_resize();
that.layout_manager.do_resize();
});
// Insert
this.element.find('#insert_cell_above').click(function () {
IPython.notebook.insert_cell_above('code');
IPython.notebook.select_prev();
that.notebook.insert_cell_above('code');
that.notebook.select_prev();
});
this.element.find('#insert_cell_below').click(function () {
IPython.notebook.insert_cell_below('code');
IPython.notebook.select_next();
that.notebook.insert_cell_below('code');
that.notebook.select_next();
});
// Cell
this.element.find('#run_cell').click(function () {
IPython.notebook.execute_cell();
that.notebook.execute_cell();
});
this.element.find('#run_cell_select_below').click(function () {
IPython.notebook.execute_cell_and_select_below();
that.notebook.execute_cell_and_select_below();
});
this.element.find('#run_cell_insert_below').click(function () {
IPython.notebook.execute_cell_and_insert_below();
that.notebook.execute_cell_and_insert_below();
});
this.element.find('#run_all_cells').click(function () {
IPython.notebook.execute_all_cells();
that.notebook.execute_all_cells();
});
this.element.find('#run_all_cells_above').click(function () {
IPython.notebook.execute_cells_above();
that.notebook.execute_cells_above();
});
this.element.find('#run_all_cells_below').click(function () {
IPython.notebook.execute_cells_below();
that.notebook.execute_cells_below();
});
this.element.find('#to_code').click(function () {
IPython.notebook.to_code();
that.notebook.to_code();
});
this.element.find('#to_markdown').click(function () {
IPython.notebook.to_markdown();
that.notebook.to_markdown();
});
this.element.find('#to_raw').click(function () {
IPython.notebook.to_raw();
that.notebook.to_raw();
});
this.element.find('#to_heading1').click(function () {
IPython.notebook.to_heading(undefined, 1);
that.notebook.to_heading(undefined, 1);
});
this.element.find('#to_heading2').click(function () {
IPython.notebook.to_heading(undefined, 2);
that.notebook.to_heading(undefined, 2);
});
this.element.find('#to_heading3').click(function () {
IPython.notebook.to_heading(undefined, 3);
that.notebook.to_heading(undefined, 3);
});
this.element.find('#to_heading4').click(function () {
IPython.notebook.to_heading(undefined, 4);
that.notebook.to_heading(undefined, 4);
});
this.element.find('#to_heading5').click(function () {
IPython.notebook.to_heading(undefined, 5);
that.notebook.to_heading(undefined, 5);
});
this.element.find('#to_heading6').click(function () {
IPython.notebook.to_heading(undefined, 6);
that.notebook.to_heading(undefined, 6);
});
this.element.find('#toggle_current_output').click(function () {
IPython.notebook.toggle_output();
that.notebook.toggle_output();
});
this.element.find('#toggle_current_output_scroll').click(function () {
IPython.notebook.toggle_output_scroll();
that.notebook.toggle_output_scroll();
});
this.element.find('#clear_current_output').click(function () {
IPython.notebook.clear_output();
that.notebook.clear_output();
});
this.element.find('#toggle_all_output').click(function () {
IPython.notebook.toggle_all_output();
that.notebook.toggle_all_output();
});
this.element.find('#toggle_all_output_scroll').click(function () {
IPython.notebook.toggle_all_output_scroll();
that.notebook.toggle_all_output_scroll();
});
this.element.find('#clear_all_output').click(function () {
IPython.notebook.clear_all_output();
that.notebook.clear_all_output();
});
// Kernel
this.element.find('#int_kernel').click(function () {
IPython.notebook.session.interrupt_kernel();
that.notebook.session.interrupt_kernel();
});
this.element.find('#restart_kernel').click(function () {
IPython.notebook.restart_kernel();
that.notebook.restart_kernel();
});
// Help
if (IPython.tour) {
if (this.tour) {
this.element.find('#notebook_tour').click(function () {
IPython.tour.start();
that.tour.start();
});
} else {
this.element.find('#notebook_tour').addClass("disabled");
}
this.element.find('#keyboard_shortcuts').click(function () {
IPython.quick_help.show_keyboard_shortcuts();
that.quick_help.show_keyboard_shortcuts();
});
this.update_restore_checkpoint(null);
$([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
that.update_restore_checkpoint(IPython.notebook.checkpoints);
this.events.on('checkpoints_listed.Notebook', function (event, data) {
that.update_restore_checkpoint(that.notebook.checkpoints);
});
$([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
that.update_restore_checkpoint(IPython.notebook.checkpoints);
this.events.on('checkpoint_created.Notebook', function (event, data) {
that.update_restore_checkpoint(that.notebook.checkpoints);
});
};
@ -317,6 +328,7 @@ var IPython = (function (IPython) {
return;
}
var that = this;
checkpoints.map(function (checkpoint) {
var d = new Date(checkpoint.last_modified);
ul.append(
@ -325,15 +337,15 @@ var IPython = (function (IPython) {
.attr("href", "#")
.text(d.format("mmm dd HH:MM:ss"))
.click(function () {
IPython.notebook.restore_checkpoint_dialog(checkpoint);
that.notebook.restore_checkpoint_dialog(checkpoint);
})
)
);
});
};
// Backwards compatability.
IPython.MenuBar = MenuBar;
return IPython;
}(IPython));
return {'MenuBar': MenuBar};
});

@ -1,32 +1,92 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/dialog',
'notebook/js/textcell',
'notebook/js/codecell',
'services/sessions/js/session',
'notebook/js/celltoolbar',
'components/marked/lib/marked',
'notebook/js/mathjaxutils',
'base/js/keyboard',
'notebook/js/tooltip',
'notebook/js/celltoolbarpresets/default',
'notebook/js/celltoolbarpresets/rawcell',
'notebook/js/celltoolbarpresets/slideshow',
], function (
IPython,
$,
utils,
dialog,
textcell,
codecell,
session,
celltoolbar,
marked,
mathjaxutils,
keyboard,
tooltip,
default_celltoolbar,
rawcell_celltoolbar,
slideshow_celltoolbar
) {
//============================================================================
// Notebook
//============================================================================
var IPython = (function (IPython) {
"use strict";
var utils = IPython.utils;
/**
* A notebook contains and manages cells.
*
* @class Notebook
* @constructor
* @param {String} selector A jQuery selector for the notebook's DOM element
* @param {Object} [options] A config object
*/
var Notebook = function (selector, options) {
this.options = options = options || {};
// Constructor
//
// A notebook contains and manages cells.
//
// Parameters:
// selector: string
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// keyboard_manager: KeyboardManager instance
// save_widget: SaveWidget instance
// config: dictionary
// base_url : string
// notebook_path : string
// notebook_name : string
this.config = options.config || {};
this.base_url = options.base_url;
this.notebook_path = options.notebook_path;
this.notebook_name = options.notebook_name;
this.events = options.events;
this.keyboard_manager = options.keyboard_manager;
this.save_widget = options.save_widget;
this.tooltip = new tooltip.Tooltip(this.events);
// TODO: This code smells (and the other `= this` line a couple lines down)
// We need a better way to deal with circular instance references.
this.keyboard_manager.notebook = this;
this.save_widget.notebook = this;
mathjaxutils.init();
if (marked) {
marked.setOptions({
gfm : true,
tables: true,
langPrefix: "language-",
highlight: function(code, lang) {
if (!lang) {
// no language, no highlight
return code;
}
var highlighted;
try {
highlighted = hljs.highlight(lang, code, false);
} catch(err) {
highlighted = hljs.highlightAuto(code);
}
return highlighted.value;
}
});
}
this.element = $(selector);
this.element.scroll();
this.element.data("notebook", this);
@ -61,6 +121,11 @@ var IPython = (function (IPython) {
this.save_notebook = function() { // don't allow save until notebook_loaded
this.save_notebook_error(null, null, "Load failed, save is disabled");
};
// Trigger cell toolbar registration.
default_celltoolbar.register(this, options.events);
rawcell_celltoolbar.register(this, options.events);
slideshow_celltoolbar.register(this, options.events);
};
/**
@ -102,36 +167,38 @@ var IPython = (function (IPython) {
Notebook.prototype.bind_events = function () {
var that = this;
$([IPython.events]).on('set_next_input.Notebook', function (event, data) {
this.events.on('set_next_input.Notebook', function (event, data) {
var index = that.find_cell_index(data.cell);
var new_cell = that.insert_cell_below('code',index);
new_cell.set_text(data.text);
that.dirty = true;
});
$([IPython.events]).on('set_dirty.Notebook', function (event, data) {
this.events.on('set_dirty.Notebook', function (event, data) {
that.dirty = data.value;
});
$([IPython.events]).on('trust_changed.Notebook', function (event, data) {
this.events.on('trust_changed.Notebook', function (event, data) {
that.trusted = data.value;
});
$([IPython.events]).on('select.Cell', function (event, data) {
this.events.on('select.Cell', function (event, data) {
var index = that.find_cell_index(data.cell);
that.select(index);
});
$([IPython.events]).on('edit_mode.Cell', function (event, data) {
this.events.on('edit_mode.Cell', function (event, data) {
that.handle_edit_mode(data.cell);
});
$([IPython.events]).on('command_mode.Cell', function (event, data) {
this.events.on('command_mode.Cell', function (event, data) {
that.handle_command_mode(data.cell);
});
$([IPython.events]).on('status_autorestarting.Kernel', function () {
IPython.dialog.modal({
this.events.on('status_autorestarting.Kernel', function () {
dialog.modal({
notebook: that,
keyboard_manager: that.keyboard_manager,
title: "Kernel Restarting",
body: "The kernel appears to have died. It will restart automatically.",
buttons: {
@ -211,7 +278,7 @@ var IPython = (function (IPython) {
if (this.dirty == value) {
return;
}
$([IPython.events]).trigger('set_dirty.Notebook', {value: value});
this.events.trigger('set_dirty.Notebook', {value: value});
};
/**
@ -254,9 +321,14 @@ var IPython = (function (IPython) {
Notebook.prototype.edit_metadata = function () {
var that = this;
IPython.dialog.edit_metadata(this.metadata, function (md) {
that.metadata = md;
}, 'Notebook');
dialog.edit_metadata({
md: this.metadata,
callback: function (md) {
that.metadata = md;
},
name: 'Notebook',
notebook: this,
keyboard_manager: this.keyboard_manager});
};
// Cell indexing, retrieval, etc.
@ -295,7 +367,7 @@ var IPython = (function (IPython) {
* @return {Cell} Cell or null if no cell was found.
*/
Notebook.prototype.get_msg_cell = function (msg_id) {
return IPython.CodeCell.msg_cells[msg_id] || null;
return codecell.CodeCell.msg_cells[msg_id] || null;
};
/**
@ -474,11 +546,11 @@ var IPython = (function (IPython) {
var cell = this.get_cell(index);
cell.select();
if (cell.cell_type === 'heading') {
$([IPython.events]).trigger('selected_cell_type_changed.Notebook',
this.events.trigger('selected_cell_type_changed.Notebook',
{'cell_type':cell.cell_type,level:cell.level}
);
} else {
$([IPython.events]).trigger('selected_cell_type_changed.Notebook',
this.events.trigger('selected_cell_type_changed.Notebook',
{'cell_type':cell.cell_type}
);
}
@ -540,8 +612,8 @@ var IPython = (function (IPython) {
if (this.mode !== 'command') {
cell.command_mode();
this.mode = 'command';
$([IPython.events]).trigger('command_mode.Notebook');
IPython.keyboard_manager.command_mode();
this.events.trigger('command_mode.Notebook');
this.keyboard_manager.command_mode();
}
};
@ -570,8 +642,8 @@ var IPython = (function (IPython) {
if (cell && this.mode !== 'edit') {
cell.edit_mode();
this.mode = 'edit';
$([IPython.events]).trigger('edit_mode.Notebook');
IPython.keyboard_manager.edit_mode();
this.events.trigger('edit_mode.Notebook');
this.keyboard_manager.edit_mode();
}
};
@ -686,7 +758,7 @@ var IPython = (function (IPython) {
this.undelete_index = i;
this.undelete_below = false;
}
$([IPython.events]).trigger('delete.Cell', {'cell': cell, 'index': i});
this.events.trigger('delete.Cell', {'cell': cell, 'index': i});
this.set_dirty(true);
}
return this;
@ -753,20 +825,27 @@ var IPython = (function (IPython) {
type = type || this.get_selected_cell().cell_type;
if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
var cell_options = {
events: this.events,
config: this.config,
keyboard_manager: this.keyboard_manager,
notebook: this,
tooltip: this.tooltip,
};
if (type === 'code') {
cell = new IPython.CodeCell(this.kernel);
cell = new codecell.CodeCell(this.kernel, cell_options);
cell.set_input_prompt();
} else if (type === 'markdown') {
cell = new IPython.MarkdownCell();
cell = new textcell.MarkdownCell(cell_options);
} else if (type === 'raw') {
cell = new IPython.RawCell();
cell = new textcell.RawCell(cell_options);
} else if (type === 'heading') {
cell = new IPython.HeadingCell();
cell = new textcell.HeadingCell(cell_options);
}
if(this._insert_element_at_index(cell.element,index)) {
cell.render();
$([IPython.events]).trigger('create.Cell', {'cell': cell, 'index': index});
this.events.trigger('create.Cell', {'cell': cell, 'index': index});
cell.refresh();
// We used to select the cell after we refresh it, but there
// are now cases were this method is called where select is
@ -876,7 +955,7 @@ var IPython = (function (IPython) {
if (this.is_valid_cell_index(i)) {
var source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
if (!(source_cell instanceof IPython.CodeCell)) {
if (!(source_cell instanceof codecell.CodeCell)) {
var target_cell = this.insert_cell_below('code',i);
var text = source_cell.get_text();
if (text === source_cell.placeholder) {
@ -906,7 +985,7 @@ var IPython = (function (IPython) {
if (this.is_valid_cell_index(i)) {
var source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
if (!(source_cell instanceof IPython.MarkdownCell)) {
if (!(source_cell instanceof textcell.MarkdownCell)) {
var target_cell = this.insert_cell_below('markdown',i);
var text = source_cell.get_text();
if (text === source_cell.placeholder) {
@ -920,7 +999,7 @@ var IPython = (function (IPython) {
target_cell.code_mirror.clearHistory();
source_element.remove();
this.select(i);
if ((source_cell instanceof IPython.TextCell) && source_cell.rendered) {
if ((source_cell instanceof textcell.TextCell) && source_cell.rendered) {
target_cell.render();
}
var cursor = source_cell.code_mirror.getCursor();
@ -942,7 +1021,7 @@ var IPython = (function (IPython) {
var source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
var target_cell = null;
if (!(source_cell instanceof IPython.RawCell)) {
if (!(source_cell instanceof textcell.RawCell)) {
target_cell = this.insert_cell_below('raw',i);
var text = source_cell.get_text();
if (text === source_cell.placeholder) {
@ -977,7 +1056,7 @@ var IPython = (function (IPython) {
var source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
var target_cell = null;
if (source_cell instanceof IPython.HeadingCell) {
if (source_cell instanceof textcell.HeadingCell) {
source_cell.set_level(level);
} else {
target_cell = this.insert_cell_below('heading',i);
@ -996,12 +1075,12 @@ var IPython = (function (IPython) {
this.select(i);
var cursor = source_cell.code_mirror.getCursor();
target_cell.code_mirror.setCursor(cursor);
if ((source_cell instanceof IPython.TextCell) && source_cell.rendered) {
if ((source_cell instanceof textcell.TextCell) && source_cell.rendered) {
target_cell.render();
}
}
this.set_dirty(true);
$([IPython.events]).trigger('selected_cell_type_changed.Notebook',
this.events.trigger('selected_cell_type_changed.Notebook',
{'cell_type':'heading',level:level}
);
}
@ -1115,13 +1194,13 @@ var IPython = (function (IPython) {
* @method split_cell
*/
Notebook.prototype.split_cell = function () {
var mdc = IPython.MarkdownCell;
var rc = IPython.RawCell;
var mdc = textcell.MarkdownCell;
var rc = textcell.RawCell;
var cell = this.get_selected_cell();
if (cell.is_splittable()) {
var texta = cell.get_pre_cursor();
var textb = cell.get_post_cursor();
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
// In this case the operations keep the notebook in its existing mode
// so we don't need to do any post-op mode changes.
cell.set_text(textb);
@ -1144,8 +1223,8 @@ var IPython = (function (IPython) {
* @method merge_cell_above
*/
Notebook.prototype.merge_cell_above = function () {
var mdc = IPython.MarkdownCell;
var rc = IPython.RawCell;
var mdc = textcell.MarkdownCell;
var rc = textcell.RawCell;
var index = this.get_selected_index();
var cell = this.get_cell(index);
var render = cell.rendered;
@ -1159,7 +1238,7 @@ var IPython = (function (IPython) {
}
var upper_text = upper_cell.get_text();
var text = cell.get_text();
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.set_text(upper_text+'\n'+text);
} else if ((cell instanceof mdc) || (cell instanceof rc)) {
cell.unrender(); // Must unrender before we set_text.
@ -1181,8 +1260,8 @@ var IPython = (function (IPython) {
* @method merge_cell_below
*/
Notebook.prototype.merge_cell_below = function () {
var mdc = IPython.MarkdownCell;
var rc = IPython.RawCell;
var mdc = textcell.MarkdownCell;
var rc = textcell.RawCell;
var index = this.get_selected_index();
var cell = this.get_cell(index);
var render = cell.rendered;
@ -1196,7 +1275,7 @@ var IPython = (function (IPython) {
}
var lower_text = lower_cell.get_text();
var text = cell.get_text();
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.set_text(text+'\n'+lower_text);
} else if ((cell instanceof mdc) || (cell instanceof rc)) {
cell.unrender(); // Must unrender before we set_text.
@ -1224,7 +1303,7 @@ var IPython = (function (IPython) {
Notebook.prototype.collapse_output = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
if (cell !== null && (cell instanceof codecell.CodeCell)) {
cell.collapse_output();
this.set_dirty(true);
}
@ -1237,7 +1316,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.collapse_all_output = function () {
$.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.collapse_output();
}
});
@ -1254,7 +1333,7 @@ var IPython = (function (IPython) {
Notebook.prototype.expand_output = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
if (cell !== null && (cell instanceof codecell.CodeCell)) {
cell.expand_output();
this.set_dirty(true);
}
@ -1267,7 +1346,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.expand_all_output = function () {
$.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.expand_output();
}
});
@ -1284,7 +1363,7 @@ var IPython = (function (IPython) {
Notebook.prototype.clear_output = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
if (cell !== null && (cell instanceof codecell.CodeCell)) {
cell.clear_output();
this.set_dirty(true);
}
@ -1297,7 +1376,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.clear_all_output = function () {
$.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.clear_output();
}
});
@ -1313,7 +1392,7 @@ var IPython = (function (IPython) {
Notebook.prototype.scroll_output = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
if (cell !== null && (cell instanceof codecell.CodeCell)) {
cell.scroll_output();
this.set_dirty(true);
}
@ -1326,7 +1405,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.scroll_all_output = function () {
$.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.scroll_output();
}
});
@ -1342,7 +1421,7 @@ var IPython = (function (IPython) {
Notebook.prototype.toggle_output = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
if (cell !== null && (cell instanceof codecell.CodeCell)) {
cell.toggle_output();
this.set_dirty(true);
}
@ -1355,7 +1434,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.toggle_all_output = function () {
$.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.toggle_output();
}
});
@ -1372,7 +1451,7 @@ var IPython = (function (IPython) {
Notebook.prototype.toggle_output_scroll = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
if (cell !== null && (cell instanceof codecell.CodeCell)) {
cell.toggle_output_scroll();
this.set_dirty(true);
}
@ -1385,7 +1464,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.toggle_all_output_scroll = function () {
$.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.toggle_output_scroll();
}
});
@ -1412,7 +1491,11 @@ var IPython = (function (IPython) {
* @method start_session
*/
Notebook.prototype.start_session = function () {
this.session = new IPython.Session(this, this.options);
this.session = new session.Session({
base_url: this.base_url,
notebook_path: this.notebook_path,
notebook_name: this.notebook_name,
notebook: this});
this.session.start($.proxy(this._session_started, this));
};
@ -1427,7 +1510,7 @@ var IPython = (function (IPython) {
var ncells = this.ncells();
for (var i=0; i<ncells; i++) {
var cell = this.get_cell(i);
if (cell instanceof IPython.CodeCell) {
if (cell instanceof codecell.CodeCell) {
cell.set_kernel(this.session.kernel);
}
}
@ -1440,7 +1523,9 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.restart_kernel = function () {
var that = this;
IPython.dialog.modal({
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title : "Restart kernel or continue running?",
body : $("<p/>").text(
'Do you want to restart the current kernel? You will lose all variables defined in it.'
@ -1660,10 +1745,12 @@ var IPython = (function (IPython) {
}
if (trusted != this.trusted) {
this.trusted = trusted;
$([IPython.events]).trigger("trust_changed.Notebook", trusted);
this.events.trigger("trust_changed.Notebook", trusted);
}
if (content.worksheets.length > 1) {
IPython.dialog.modal({
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title : "Multiple worksheets",
body : "This notebook has " + data.worksheets.length + " worksheets, " +
"but this version of IPython can only handle the first. " +
@ -1705,7 +1792,7 @@ var IPython = (function (IPython) {
};
if (trusted != this.trusted) {
this.trusted = trusted;
$([IPython.events]).trigger("trust_changed.Notebook", trusted);
this.events.trigger("trust_changed.Notebook", trusted);
}
return data;
};
@ -1730,10 +1817,10 @@ var IPython = (function (IPython) {
that.save_notebook();
}
}, interval);
$([IPython.events]).trigger("autosave_enabled.Notebook", interval);
this.events.trigger("autosave_enabled.Notebook", interval);
} else {
this.autosave_timer = null;
$([IPython.events]).trigger("autosave_disabled.Notebook");
this.events.trigger("autosave_disabled.Notebook");
}
};
@ -1768,7 +1855,7 @@ var IPython = (function (IPython) {
settings[key] = extra_settings[key];
}
}
$([IPython.events]).trigger('notebook_saving.Notebook');
this.events.trigger('notebook_saving.Notebook');
var url = utils.url_join_encode(
this.base_url,
'api/notebooks',
@ -1789,7 +1876,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.save_notebook_success = function (start, data, status, xhr) {
this.set_dirty(false);
$([IPython.events]).trigger('notebook_saved.Notebook');
this.events.trigger('notebook_saved.Notebook');
this._update_autosave_interval(start);
if (this._checkpoint_after_save) {
this.create_checkpoint();
@ -1826,7 +1913,7 @@ var IPython = (function (IPython) {
* @param {String} error HTTP error message
*/
Notebook.prototype.save_notebook_error = function (xhr, status, error) {
$([IPython.events]).trigger('notebook_save_failed.Notebook', [xhr, status, error]);
this.events.trigger('notebook_save_failed.Notebook', [xhr, status, error]);
};
/**
@ -1851,7 +1938,9 @@ var IPython = (function (IPython) {
);
var nb = this;
IPython.dialog.modal({
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title: "Trust this notebook?",
body: body,
@ -1867,7 +1956,7 @@ var IPython = (function (IPython) {
cell.output_area.trusted = true;
}
}
$([IPython.events]).on('notebook_saved.Notebook', function () {
this.events.on('notebook_saved.Notebook', function () {
window.location.reload();
});
nb.save_notebook();
@ -1953,7 +2042,7 @@ var IPython = (function (IPython) {
success : $.proxy(that.rename_success, this),
error : $.proxy(that.rename_error, this)
};
$([IPython.events]).trigger('rename_notebook.Notebook', data);
this.events.trigger('rename_notebook.Notebook', data);
var url = utils.url_join_encode(
this.base_url,
'api/notebooks',
@ -1986,32 +2075,34 @@ var IPython = (function (IPython) {
var name = this.notebook_name = json.name;
var path = json.path;
this.session.rename_notebook(name, path);
$([IPython.events]).trigger('notebook_renamed.Notebook', json);
this.events.trigger('notebook_renamed.Notebook', json);
};
Notebook.prototype.rename_error = function (xhr, status, error) {
var that = this;
var dialog = $('<div/>').append(
var dialog_body = $('<div/>').append(
$("<p/>").addClass("rename-message")
.text('This notebook name already exists.')
);
$([IPython.events]).trigger('notebook_rename_failed.Notebook', [xhr, status, error]);
IPython.dialog.modal({
this.events.trigger('notebook_rename_failed.Notebook', [xhr, status, error]);
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title: "Notebook Rename Error!",
body: dialog,
body: dialog_body,
buttons : {
"Cancel": {},
"OK": {
class: "btn-primary",
click: function () {
IPython.save_widget.rename_notebook();
this.save_widget.rename_notebook({notebook:that});
}}
},
open : function (event, ui) {
var that = $(this);
// Upon ENTER, click the OK button.
that.find('input[type="text"]').keydown(function (event, ui) {
if (event.which === IPython.keyboard.keycodes.enter) {
if (event.which === this.keyboard.keycodes.enter) {
that.find('.btn-primary').first().click();
}
});
@ -2039,7 +2130,7 @@ var IPython = (function (IPython) {
success : $.proxy(this.load_notebook_success,this),
error : $.proxy(this.load_notebook_error,this),
};
$([IPython.events]).trigger('notebook_loading.Notebook');
this.events.trigger('notebook_loading.Notebook');
var url = utils.url_join_encode(
this.base_url,
'api/notebooks',
@ -2077,7 +2168,9 @@ var IPython = (function (IPython) {
"newer notebook format will be used and older versions of IPython " +
"may not be able to read it. To keep the older version, close the " +
"notebook without saving it.";
IPython.dialog.modal({
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title : "Notebook converted",
body : msg,
buttons : {
@ -2094,7 +2187,9 @@ var IPython = (function (IPython) {
this_vs + ". You can still work with this notebook, but some features " +
"introduced in later notebook versions may not be available.";
IPython.dialog.modal({
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title : "Newer Notebook",
body : msg,
buttons : {
@ -2116,15 +2211,15 @@ var IPython = (function (IPython) {
// load toolbar state
if (this.metadata.celltoolbar) {
IPython.CellToolbar.global_show();
IPython.CellToolbar.activate_preset(this.metadata.celltoolbar);
celltoolbar.CellToolbar.global_show();
celltoolbar.CellToolbar.activate_preset(this.metadata.celltoolbar, this.events);
} else {
IPython.CellToolbar.global_hide();
celltoolbar.CellToolbar.global_hide();
}
// now that we're fully loaded, it is safe to restore save functionality
delete(this.save_notebook);
$([IPython.events]).trigger('notebook_loaded.Notebook');
this.events.trigger('notebook_loaded.Notebook');
};
/**
@ -2136,7 +2231,7 @@ var IPython = (function (IPython) {
* @param {String} error HTTP error message
*/
Notebook.prototype.load_notebook_error = function (xhr, status, error) {
$([IPython.events]).trigger('notebook_load_failed.Notebook', [xhr, status, error]);
this.events.trigger('notebook_load_failed.Notebook', [xhr, status, error]);
var msg;
if (xhr.status === 400) {
msg = error;
@ -2145,7 +2240,9 @@ var IPython = (function (IPython) {
"This version can load notebook formats " +
"v" + this.nbformat + " or earlier.";
}
IPython.dialog.modal({
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title: "Error loading notebook",
body : msg,
buttons : {
@ -2224,7 +2321,7 @@ var IPython = (function (IPython) {
} else {
this.last_checkpoint = null;
}
$([IPython.events]).trigger('checkpoints_listed.Notebook', [data]);
this.events.trigger('checkpoints_listed.Notebook', [data]);
};
/**
@ -2236,7 +2333,7 @@ var IPython = (function (IPython) {
* @param {String} error_msg HTTP error message
*/
Notebook.prototype.list_checkpoints_error = function (xhr, status, error_msg) {
$([IPython.events]).trigger('list_checkpoints_failed.Notebook');
this.events.trigger('list_checkpoints_failed.Notebook');
};
/**
@ -2270,7 +2367,7 @@ var IPython = (function (IPython) {
Notebook.prototype.create_checkpoint_success = function (data, status, xhr) {
data = $.parseJSON(data);
this.add_checkpoint(data);
$([IPython.events]).trigger('checkpoint_created.Notebook', data);
this.events.trigger('checkpoint_created.Notebook', data);
};
/**
@ -2282,7 +2379,7 @@ var IPython = (function (IPython) {
* @param {String} error_msg HTTP error message
*/
Notebook.prototype.create_checkpoint_error = function (xhr, status, error_msg) {
$([IPython.events]).trigger('checkpoint_failed.Notebook');
this.events.trigger('checkpoint_failed.Notebook');
};
Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) {
@ -2309,7 +2406,9 @@ var IPython = (function (IPython) {
).css("text-align", "center")
);
IPython.dialog.modal({
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title : "Revert notebook to checkpoint",
body : body,
buttons : {
@ -2331,7 +2430,7 @@ var IPython = (function (IPython) {
* @param {String} checkpoint ID
*/
Notebook.prototype.restore_checkpoint = function (checkpoint) {
$([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
this.events.trigger('notebook_restoring.Notebook', checkpoint);
var url = utils.url_join_encode(
this.base_url,
'api/notebooks',
@ -2356,7 +2455,7 @@ var IPython = (function (IPython) {
* @param {jqXHR} xhr jQuery Ajax object
*/
Notebook.prototype.restore_checkpoint_success = function (data, status, xhr) {
$([IPython.events]).trigger('checkpoint_restored.Notebook');
this.events.trigger('checkpoint_restored.Notebook');
this.load_notebook(this.notebook_name, this.notebook_path);
};
@ -2369,7 +2468,7 @@ var IPython = (function (IPython) {
* @param {String} error_msg HTTP error message
*/
Notebook.prototype.restore_checkpoint_error = function (xhr, status, error_msg) {
$([IPython.events]).trigger('checkpoint_restore_failed.Notebook');
this.events.trigger('checkpoint_restore_failed.Notebook');
};
/**
@ -2379,7 +2478,7 @@ var IPython = (function (IPython) {
* @param {String} checkpoint ID
*/
Notebook.prototype.delete_checkpoint = function (checkpoint) {
$([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
this.events.trigger('notebook_restoring.Notebook', checkpoint);
var url = utils.url_join_encode(
this.base_url,
'api/notebooks',
@ -2404,7 +2503,7 @@ var IPython = (function (IPython) {
* @param {jqXHR} xhr jQuery Ajax object
*/
Notebook.prototype.delete_checkpoint_success = function (data, status, xhr) {
$([IPython.events]).trigger('checkpoint_deleted.Notebook', data);
this.events.trigger('checkpoint_deleted.Notebook', data);
this.load_notebook(this.notebook_name, this.notebook_path);
};
@ -2417,14 +2516,12 @@ var IPython = (function (IPython) {
* @param {String} error_msg HTTP error message
*/
Notebook.prototype.delete_checkpoint_error = function (xhr, status, error_msg) {
$([IPython.events]).trigger('checkpoint_delete_failed.Notebook');
this.events.trigger('checkpoint_delete_failed.Notebook');
};
// For backwards compatability.
IPython.Notebook = Notebook;
return IPython;
}(IPython));
return {'Notebook': Notebook};
});

@ -1,21 +1,30 @@
//----------------------------------------------------------------------------
// Copyright (C) 2012 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.
//----------------------------------------------------------------------------
//============================================================================
// Notification widget
//============================================================================
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/dialog',
'notebook/js/notificationwidget',
], function(IPython, $, utils, dialog, notificationwidget) {
"use strict";
var utils = IPython.utils;
var NotificationArea = function (selector) {
var NotificationArea = function (selector, options) {
// Constructor
//
// Parameters:
// selector: string
// options: dictionary
// Dictionary of keyword arguments.
// notebook: Notebook instance
// events: $(Events) instance
// save_widget: SaveWidget instance
this.selector = selector;
this.events = options.events;
this.save_widget = options.save_widget;
this.notebook = options.notebook;
this.keyboard_manager = options.keyboard_manager;
if (this.selector !== undefined) {
this.element = $(selector);
}
@ -63,23 +72,24 @@ var IPython = (function (IPython) {
}
var div = $('<div/>').attr('id','notification_'+name);
$(this.selector).append(div);
this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name);
this.widget_dict[name] = new notificationwidget.NotificationWidget('#notification_'+name);
return this.widget_dict[name];
};
NotificationArea.prototype.init_notification_widgets = function() {
var that = this;
var knw = this.new_notification_widget('kernel');
var $kernel_ind_icon = $("#kernel_indicator_icon");
var $modal_ind_icon = $("#modal_indicator_icon");
// Command/Edit mode
$([IPython.events]).on('edit_mode.Notebook',function () {
IPython.save_widget.update_document_title();
this.events.on('edit_mode.Notebook',function () {
that.save_widget.update_document_title();
$modal_ind_icon.attr('class','edit_mode_icon').attr('title','Edit Mode');
});
$([IPython.events]).on('command_mode.Notebook',function () {
IPython.save_widget.update_document_title();
this.events.on('command_mode.Notebook',function () {
that.save_widget.update_document_title();
$modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
});
@ -87,22 +97,22 @@ var IPython = (function (IPython) {
$modal_ind_icon.attr('class','command-mode_icon').attr('title','Command Mode');
// Kernel events
$([IPython.events]).on('status_idle.Kernel',function () {
IPython.save_widget.update_document_title();
this.events.on('status_idle.Kernel',function () {
that.save_widget.update_document_title();
$kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
});
$([IPython.events]).on('status_busy.Kernel',function () {
this.events.on('status_busy.Kernel',function () {
window.document.title='(Busy) '+window.document.title;
$kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
});
$([IPython.events]).on('status_restarting.Kernel',function () {
IPython.save_widget.update_document_title();
this.events.on('status_restarting.Kernel',function () {
that.save_widget.update_document_title();
knw.set_message("Restarting kernel", 2000);
});
$([IPython.events]).on('status_interrupting.Kernel',function () {
this.events.on('status_interrupting.Kernel',function () {
knw.set_message("Interrupting kernel", 2000);
});
@ -110,28 +120,30 @@ var IPython = (function (IPython) {
// When the kernel_info reply arrives, the kernel is idle.
$kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
$([IPython.events]).on('status_started.Kernel', function (evt, data) {
this.events.on('status_started.Kernel', function (evt, data) {
data.kernel.kernel_info(function () {
$([IPython.events]).trigger('status_idle.Kernel');
that.events.trigger('status_idle.Kernel');
});
});
$([IPython.events]).on('status_dead.Kernel',function () {
this.events.on('status_dead.Kernel',function () {
var msg = 'The kernel has died, and the automatic restart has failed.' +
' It is possible the kernel cannot be restarted.' +
' If you are not able to restart the kernel, you will still be able to save' +
' the notebook, but running code will no longer work until the notebook' +
' is reopened.';
IPython.dialog.modal({
dialog.modal({
title: "Dead kernel",
body : msg,
keyboard_manager: that.keyboard_manager,
notebook: that.notebook,
buttons : {
"Manual Restart": {
class: "btn-danger",
click: function () {
$([IPython.events]).trigger('status_restarting.Kernel');
IPython.notebook.start_kernel();
that.events.trigger('status_restarting.Kernel');
that.notebook.start_kernel();
}
},
"Don't restart": {}
@ -139,7 +151,7 @@ var IPython = (function (IPython) {
});
});
$([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
this.events.on('websocket_closed.Kernel', function (event, data) {
var kernel = data.kernel;
var ws_url = data.ws_url;
var early = data.early;
@ -155,9 +167,11 @@ var IPython = (function (IPython) {
msg = "A WebSocket connection could not be established." +
" You will NOT be able to run code. Check your" +
" network connection or notebook server configuration.";
IPython.dialog.modal({
dialog.modal({
title: "WebSocket connection failed",
body: msg,
keyboard_manager: that.keyboard_manager,
notebook: that.notebook,
buttons : {
"OK": {},
"Reconnect": {
@ -176,24 +190,24 @@ var IPython = (function (IPython) {
var nnw = this.new_notification_widget('notebook');
// Notebook events
$([IPython.events]).on('notebook_loading.Notebook', function () {
this.events.on('notebook_loading.Notebook', function () {
nnw.set_message("Loading notebook",500);
});
$([IPython.events]).on('notebook_loaded.Notebook', function () {
this.events.on('notebook_loaded.Notebook', function () {
nnw.set_message("Notebook loaded",500);
});
$([IPython.events]).on('notebook_saving.Notebook', function () {
this.events.on('notebook_saving.Notebook', function () {
nnw.set_message("Saving notebook",500);
});
$([IPython.events]).on('notebook_saved.Notebook', function () {
this.events.on('notebook_saved.Notebook', function () {
nnw.set_message("Notebook saved",2000);
});
$([IPython.events]).on('notebook_save_failed.Notebook', function (evt, xhr, status, data) {
this.events.on('notebook_save_failed.Notebook', function (evt, xhr, status, data) {
nnw.set_message(data || "Notebook save failed");
});
// Checkpoint events
$([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
this.events.on('checkpoint_created.Notebook', function (evt, data) {
var msg = "Checkpoint created";
if (data.last_modified) {
var d = new Date(data.last_modified);
@ -201,27 +215,27 @@ var IPython = (function (IPython) {
}
nnw.set_message(msg, 2000);
});
$([IPython.events]).on('checkpoint_failed.Notebook', function () {
this.events.on('checkpoint_failed.Notebook', function () {
nnw.set_message("Checkpoint failed");
});
$([IPython.events]).on('checkpoint_deleted.Notebook', function () {
this.events.on('checkpoint_deleted.Notebook', function () {
nnw.set_message("Checkpoint deleted", 500);
});
$([IPython.events]).on('checkpoint_delete_failed.Notebook', function () {
this.events.on('checkpoint_delete_failed.Notebook', function () {
nnw.set_message("Checkpoint delete failed");
});
$([IPython.events]).on('checkpoint_restoring.Notebook', function () {
this.events.on('checkpoint_restoring.Notebook', function () {
nnw.set_message("Restoring to checkpoint...", 500);
});
$([IPython.events]).on('checkpoint_restore_failed.Notebook', function () {
this.events.on('checkpoint_restore_failed.Notebook', function () {
nnw.set_message("Checkpoint restore failed");
});
// Autosave events
$([IPython.events]).on('autosave_disabled.Notebook', function () {
this.events.on('autosave_disabled.Notebook', function () {
nnw.set_message("Autosave disabled", 2000);
});
$([IPython.events]).on('autosave_enabled.Notebook', function (evt, interval) {
this.events.on('autosave_enabled.Notebook', function (evt, interval) {
nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
});
@ -229,7 +243,5 @@ var IPython = (function (IPython) {
IPython.NotificationArea = NotificationArea;
return IPython;
}(IPython));
return {'NotificationArea': NotificationArea};
});

@ -1,18 +1,11 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Notification widget
//============================================================================
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
], function(IPython, $) {
"use strict";
var utils = IPython.utils;
var NotificationWidget = function (selector) {
this.selector = selector;
@ -31,7 +24,6 @@ var IPython = (function (IPython) {
};
NotificationWidget.prototype.style = function () {
this.element.addClass('notification_widget pull-right');
this.element.addClass('border-box-sizing');
@ -43,12 +35,12 @@ var IPython = (function (IPython) {
// if timeout <= 0
// click_callback : function called if user click on notification
// could return false to prevent the notification to be dismissed
NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, opts) {
var opts = opts || {};
NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) {
options = options || {};
var callback = click_callback || function() {return false;};
var that = this;
this.inner.attr('class', opts.icon);
this.inner.attr('title', opts.title);
this.inner.attr('class', options.icon);
this.inner.attr('title', options.title);
this.inner.text(msg);
this.element.fadeIn(100);
if (this.timeout !== null) {
@ -62,7 +54,7 @@ var IPython = (function (IPython) {
}, timeout);
} else {
this.element.click(function() {
if( callback() != false ) {
if( callback() !== false ) {
that.element.fadeOut(100, function () {that.inner.text('');});
that.element.unbind('click');
}
@ -74,15 +66,12 @@ var IPython = (function (IPython) {
}
};
NotificationWidget.prototype.get_message = function () {
return this.inner.html();
};
// For backwards compatability.
IPython.NotificationWidget = NotificationWidget;
return IPython;
}(IPython));
return {'NotificationWidget': NotificationWidget};
});

@ -1,38 +1,36 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// OutputArea
//============================================================================
/**
* @module IPython
* @namespace IPython
* @submodule OutputArea
*/
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jqueryui',
'base/js/utils',
'base/js/security',
'base/js/keyboard',
'notebook/js/mathjaxutils',
], function(IPython, $, utils, security, keyboard, mathjaxutils) {
"use strict";
var utils = IPython.utils;
/**
* @class OutputArea
*
* @constructor
*/
var OutputArea = function (selector, prompt_area) {
this.selector = selector;
this.wrapper = $(selector);
var OutputArea = function (options) {
this.selector = options.selector;
this.events = options.events;
this.keyboard_manager = options.keyboard_manager;
this.wrapper = $(options.selector);
this.outputs = [];
this.collapsed = false;
this.scrolled = false;
this.trusted = true;
this.clear_queued = null;
if (prompt_area === undefined) {
if (options.prompt_area === undefined) {
this.prompt_area = true;
} else {
this.prompt_area = prompt_area;
this.prompt_area = options.prompt_area;
}
this.create_elements();
this.style();
@ -101,7 +99,7 @@ var IPython = (function (IPython) {
this.element.resize(function () {
// FIXME: Firefox on Linux misbehaves, so automatic scrolling is disabled
if ( IPython.utils.browser[0] === "Firefox" ) {
if ( utils.browser[0] === "Firefox" ) {
return;
}
// maybe scroll output,
@ -515,7 +513,7 @@ var IPython = (function (IPython) {
if (!this.trusted && !OutputArea.safe_outputs[type]) {
// not trusted, sanitize HTML
if (type==='text/html' || type==='text/svg') {
value = IPython.security.sanitize_html(value);
value = security.sanitize_html(value);
} else {
// don't display if we don't know how to sanitize it
console.log("Ignoring untrusted " + type + " output.");
@ -531,7 +529,7 @@ var IPython = (function (IPython) {
if (['image/png', 'image/jpeg'].indexOf(type) < 0 && handle_inserted !== undefined) {
setTimeout(handle_inserted, 0);
}
$([IPython.events]).trigger('output_appended.OutputArea', [type, value, md, toinsert]);
this.events.trigger('output_appended.OutputArea', [type, value, md, toinsert]);
return toinsert;
}
}
@ -542,7 +540,7 @@ var IPython = (function (IPython) {
var append_html = function (html, md, element) {
var type = 'text/html';
var toinsert = this.create_output_subarea(md, "output_html rendered_html", type);
IPython.keyboard_manager.register_events(toinsert);
this.keyboard_manager.register_events(toinsert);
toinsert.append(html);
element.append(toinsert);
return toinsert;
@ -552,11 +550,11 @@ var IPython = (function (IPython) {
var append_markdown = function(markdown, md, element) {
var type = 'text/markdown';
var toinsert = this.create_output_subarea(md, "output_markdown", type);
var text_and_math = IPython.mathjaxutils.remove_math(markdown);
var text_and_math = mathjaxutils.remove_math(markdown);
var text = text_and_math[0];
var math = text_and_math[1];
var html = marked.parser(marked.lexer(text));
html = IPython.mathjaxutils.replace_math(html, math);
html = mathjaxutils.replace_math(html, math);
toinsert.append(html);
element.append(toinsert);
return toinsert;
@ -567,7 +565,7 @@ var IPython = (function (IPython) {
// We just eval the JS code, element appears in the local scope.
var type = 'application/javascript';
var toinsert = this.create_output_subarea(md, "output_javascript", type);
IPython.keyboard_manager.register_events(toinsert);
this.keyboard_manager.register_events(toinsert);
element.append(toinsert);
// Fix for ipython/issues/5293, make sure `element` is the area which
@ -758,7 +756,7 @@ var IPython = (function (IPython) {
.keydown(function (event, ui) {
// make sure we submit on enter,
// and don't re-execute the *cell* on shift-enter
if (event.which === IPython.keyboard.keycodes.enter) {
if (event.which === keyboard.keycodes.enter) {
that._submit_raw_input();
return false;
}
@ -770,7 +768,7 @@ var IPython = (function (IPython) {
var raw_input = area.find('input.raw_input');
// Register events that enable/disable the keyboard manager while raw
// input is focused.
IPython.keyboard_manager.register_events(raw_input);
this.keyboard_manager.register_events(raw_input);
// Note, the following line used to read raw_input.focus().focus().
// This seemed to be needed otherwise only the cell would be focused.
// But with the modal UI, this seems to work fine with one call to focus().
@ -796,7 +794,7 @@ var IPython = (function (IPython) {
container.parent().remove();
// replace with plaintext version in stdout
this.append_output(content, false);
$([IPython.events]).trigger('send_input_reply.Kernel', value);
this.events.trigger('send_input_reply.Kernel', value);
}
@ -987,8 +985,8 @@ var IPython = (function (IPython) {
"application/pdf" : append_pdf
};
// For backwards compatability.
IPython.OutputArea = OutputArea;
return IPython;
}(IPython));
return {'OutputArea': OutputArea};
});

@ -1,20 +1,29 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Pager
//============================================================================
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jqueryui',
'base/js/utils',
], function(IPython, $, utils) {
"use strict";
var utils = IPython.utils;
var Pager = function (pager_selector, pager_splitter_selector) {
var Pager = function (pager_selector, pager_splitter_selector, options) {
// Constructor
//
// Parameters:
// pager_selector: string
// pager_splitter_selector: string
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// layout_manager: LayoutManager instance
this.events = options.events;
this.pager_element = $(pager_selector);
this.pager_button_area = $('#pager_button_area');
var that = this;
this.percentage_height = 0.40;
options.layout_manager.pager = this;
this.pager_splitter_element = $(pager_splitter_selector)
.draggable({
containment: 'window',
@ -23,7 +32,7 @@ var IPython = (function (IPython) {
drag: function(event, ui) {
// recalculate the amount of space the pager should take
var pheight = ($(document.body).height()-event.clientY-4);
var downprct = pheight/IPython.layout_manager.app_height();
var downprct = pheight/options.layout_manager.app_height();
downprct = Math.min(0.9, downprct);
if (downprct < 0.1) {
that.percentage_height = 0.1;
@ -32,7 +41,7 @@ var IPython = (function (IPython) {
that.percentage_height = downprct;
that.expand({'duration':0});
}
IPython.layout_manager.do_resize();
options.layout_manager.do_resize();
}
});
this.expanded = false;
@ -47,22 +56,22 @@ var IPython = (function (IPython) {
$('<a>').attr('role', "button")
.attr('title',"Open the pager in an external window")
.addClass('ui-button')
.click(function(){that.detach()})
.click(function(){that.detach();})
.attr('style','position: absolute; right: 20px;')
.append(
$('<span>').addClass("ui-icon ui-icon-extlink")
)
)
);
this.pager_button_area.append(
$('<a>').attr('role', "button")
.attr('title',"Close the pager")
.addClass('ui-button')
.click(function(){that.collapse()})
.click(function(){that.collapse();})
.attr('style','position: absolute; right: 5px;')
.append(
$('<span>').addClass("ui-icon ui-icon-close")
)
)
);
};
Pager.prototype.style = function () {
@ -105,7 +114,7 @@ var IPython = (function (IPython) {
that.toggle();
});
$([IPython.events]).on('open_with_text.Pager', function (event, payload) {
this.events.on('open_with_text.Pager', function (event, payload) {
// FIXME: support other mime types
if (payload.data['text/plain'] && payload.data['text/plain'] !== "") {
that.clear();
@ -171,10 +180,8 @@ var IPython = (function (IPython) {
this.pager_element.find(".container").append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
};
// Backwards compatability.
IPython.Pager = Pager;
return IPython;
}(IPython));
return {'Pager': Pager};
});

@ -1,16 +1,28 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// QuickHelp button
//============================================================================
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/dialog',
], function(IPython, $, utils, dialog) {
"use strict";
var platform = IPython.utils.platform;
var QuickHelp = function (selector) {
var platform = utils.platform;
var QuickHelp = function (options) {
// Constructor
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// keyboard_manager: KeyboardManager instance
// notebook: Notebook instance
this.keyboard_manager = options.keyboard_manager;
this.notebook = options.notebook;
this.keyboard_manager.quick_help = this;
this.events = options.events;
};
var cmd_ctrl = 'Ctrl-';
@ -70,8 +82,8 @@ var IPython = (function (IPython) {
$(this.shortcut_dialog).modal("toggle");
return;
}
var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
var command_shortcuts = this.keyboard_manager.command_shortcuts.help();
var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help();
var help, shortcut;
var i, half, n;
var element = $('<div/>');
@ -96,21 +108,23 @@ var IPython = (function (IPython) {
var edit_div = this.build_edit_help(cm_shortcuts);
element.append(edit_div);
this.shortcut_dialog = IPython.dialog.modal({
this.shortcut_dialog = dialog.modal({
title : "Keyboard shortcuts",
body : element,
destroy : false,
buttons : {
Close : {}
}
},
notebook: this.notebook,
keyboard_manager: this.keyboard_manager,
});
this.shortcut_dialog.addClass("modal_stretch");
$([IPython.events]).on('rebuild.QuickHelp', function() { that.force_rebuild = true;});
this.events.on('rebuild.QuickHelp', function() { that.force_rebuild = true;});
};
QuickHelp.prototype.build_command_help = function () {
var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
var command_shortcuts = this.keyboard_manager.command_shortcuts.help();
return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
};
@ -134,7 +148,7 @@ var IPython = (function (IPython) {
};
QuickHelp.prototype.build_edit_help = function (cm_shortcuts) {
var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help();
jQuery.merge(cm_shortcuts, edit_shortcuts);
return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', cm_shortcuts);
};
@ -163,9 +177,8 @@ var IPython = (function (IPython) {
return div;
};
// Set module variables
// Backwards compatability.
IPython.QuickHelp = QuickHelp;
return IPython;
}(IPython));
return {'QuickHelp': QuickHelp};
});

@ -1,21 +1,22 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// SaveWidget
//============================================================================
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/dialog',
'base/js/keyboard',
'dateformat',
], function(IPython, $, utils, dialog, keyboard) {
"use strict";
var utils = IPython.utils;
var SaveWidget = function (selector) {
var SaveWidget = function (selector, options) {
// TODO: Remove circulat ref.
this.notebook = undefined;
this.selector = selector;
this.events = options.events;
this.keyboard_manager = options.keyboard_manager;
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
@ -23,7 +24,6 @@ var IPython = (function (IPython) {
}
};
SaveWidget.prototype.style = function () {
};
@ -38,56 +38,59 @@ var IPython = (function (IPython) {
}, function () {
$(this).removeClass("ui-state-hover");
});
$([IPython.events]).on('notebook_loaded.Notebook', function () {
this.events.on('notebook_loaded.Notebook', function () {
that.update_notebook_name();
that.update_document_title();
});
$([IPython.events]).on('notebook_saved.Notebook', function () {
this.events.on('notebook_saved.Notebook', function () {
that.update_notebook_name();
that.update_document_title();
});
$([IPython.events]).on('notebook_renamed.Notebook', function () {
this.events.on('notebook_renamed.Notebook', function () {
that.update_notebook_name();
that.update_document_title();
that.update_address_bar();
});
$([IPython.events]).on('notebook_save_failed.Notebook', function () {
this.events.on('notebook_save_failed.Notebook', function () {
that.set_save_status('Autosave Failed!');
});
$([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
this.events.on('checkpoints_listed.Notebook', function (event, data) {
that.set_last_checkpoint(data[0]);
});
$([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
this.events.on('checkpoint_created.Notebook', function (event, data) {
that.set_last_checkpoint(data);
});
$([IPython.events]).on('set_dirty.Notebook', function (event, data) {
this.events.on('set_dirty.Notebook', function (event, data) {
that.set_autosaved(data.value);
});
};
SaveWidget.prototype.rename_notebook = function () {
SaveWidget.prototype.rename_notebook = function (options) {
options = options || {};
var that = this;
var dialog = $('<div/>').append(
var dialog_body = $('<div/>').append(
$("<p/>").addClass("rename-message")
.text('Enter a new notebook name:')
).append(
$("<br/>")
).append(
$('<input/>').attr('type','text').attr('size','25').addClass('form-control')
.val(IPython.notebook.get_notebook_name())
.val(that.notebook.get_notebook_name())
);
IPython.dialog.modal({
dialog.modal({
title: "Rename Notebook",
body: dialog,
body: dialog_body,
notebook: options.notebook,
keyboard_manager: this.keyboard_manager,
buttons : {
"Cancel": {},
"OK": {
class: "btn-primary",
click: function () {
var new_name = $(this).find('input').val();
if (!IPython.notebook.test_notebook_name(new_name)) {
if (!that.notebook.test_notebook_name(new_name)) {
$(this).find('.rename-message').text(
"Invalid notebook name. Notebook names must "+
"have 1 or more characters and can contain any characters " +
@ -95,7 +98,7 @@ var IPython = (function (IPython) {
);
return false;
} else {
IPython.notebook.rename(new_name);
that.notebook.rename(new_name);
}
}}
},
@ -103,7 +106,7 @@ var IPython = (function (IPython) {
var that = $(this);
// Upon ENTER, click the OK button.
that.find('input[type="text"]').keydown(function (event, ui) {
if (event.which === IPython.keyboard.keycodes.enter) {
if (event.which === keyboard.keycodes.enter) {
that.find('.btn-primary').first().click();
return false;
}
@ -111,24 +114,24 @@ var IPython = (function (IPython) {
that.find('input[type="text"]').focus().select();
}
});
}
};
SaveWidget.prototype.update_notebook_name = function () {
var nbname = IPython.notebook.get_notebook_name();
var nbname = this.notebook.get_notebook_name();
this.element.find('span#notebook_name').text(nbname);
};
SaveWidget.prototype.update_document_title = function () {
var nbname = IPython.notebook.get_notebook_name();
var nbname = this.notebook.get_notebook_name();
document.title = nbname;
};
SaveWidget.prototype.update_address_bar = function(){
var base_url = IPython.notebook.base_url;
var nbname = IPython.notebook.notebook_name;
var path = IPython.notebook.notebook_path;
var base_url = this.notebook.base_url;
var nbname = this.notebook.notebook_name;
var path = this.notebook.notebook_path;
var state = {path : path, name: nbname};
window.history.replaceState(state, "", utils.url_join_encode(
base_url,
@ -141,11 +144,11 @@ var IPython = (function (IPython) {
SaveWidget.prototype.set_save_status = function (msg) {
this.element.find('span#autosave_status').text(msg);
}
};
SaveWidget.prototype.set_checkpoint_status = function (msg) {
this.element.find('span#checkpoint_status').text(msg);
}
};
SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
if (!checkpoint) {
@ -156,7 +159,7 @@ var IPython = (function (IPython) {
this.set_checkpoint_status(
"Last Checkpoint: " + d.format('mmm dd HH:MM')
);
}
};
SaveWidget.prototype.set_autosaved = function (dirty) {
if (dirty) {
@ -166,10 +169,9 @@ var IPython = (function (IPython) {
}
};
// Backwards compatability.
IPython.SaveWidget = SaveWidget;
return IPython;
}(IPython));
return {'SaveWidget': SaveWidget};
});

@ -1,60 +1,57 @@
//----------------------------------------------------------------------------
// Copyright (C) 2008-2012 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.
//----------------------------------------------------------------------------
//============================================================================
// TextCell
//============================================================================
/**
A module that allow to create different type of Text Cell
@module IPython
@namespace IPython
*/
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'notebook/js/cell',
'base/js/security',
'notebook/js/mathjaxutils',
'notebook/js/celltoolbar',
'components/marked/lib/marked',
], function(IPython, $, cell, security, mathjaxutils, celltoolbar, marked) {
"use strict";
var Cell = cell.Cell;
// TextCell base class
var keycodes = IPython.keyboard.keycodes;
var security = IPython.security;
/**
* 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
* @param {object|undefined} [options]
* @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config
* @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass)
*/
var TextCell = function (options) {
// Constructor
//
// Construct a new TextCell, codemirror mode is by default 'htmlmixed',
// and cell type is 'text' cell start as not redered.
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// config: dictionary
// keyboard_manager: KeyboardManager instance
// notebook: Notebook instance
options = options || {};
// in all TextCell/Cell subclasses
// do not assign most of members here, just pass it down
// in the options dict potentially overwriting what you wish.
// they will be assigned in the base class.
this.notebook = options.notebook;
this.events = options.events;
this.config = options.config;
// we cannot put this as a class key as it has handle to "this".
var cm_overwrite_options = {
onKeyEvent: $.proxy(this.handle_keyevent,this)
};
options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options});
var config = this.mergeopt(TextCell, this.config, {cm_config:cm_overwrite_options});
Cell.apply(this, [{
config: config,
keyboard_manager: options.keyboard_manager,
events: this.events}]);
this.cell_type = this.cell_type || 'text';
IPython.Cell.apply(this, [options]);
mathjaxutils = mathjaxutils;
this.rendered = false;
};
TextCell.prototype = new IPython.Cell();
TextCell.prototype = new Cell();
TextCell.options_default = {
cm_config : {
@ -71,7 +68,7 @@ var IPython = (function (IPython) {
* @private
*/
TextCell.prototype.create_element = function () {
IPython.Cell.prototype.create_element.apply(this, arguments);
Cell.prototype.create_element.apply(this, arguments);
var cell = $("<div>").addClass('cell text_cell border-box-sizing');
cell.attr('tabindex','2');
@ -79,7 +76,10 @@ var IPython = (function (IPython) {
var prompt = $('<div/>').addClass('prompt input_prompt');
cell.append(prompt);
var inner_cell = $('<div/>').addClass('inner_cell');
this.celltoolbar = new IPython.CellToolbar(this);
this.celltoolbar = new celltoolbar.CellToolbar({
cell: this,
events: this.events,
notebook: this.notebook});
inner_cell.append(this.celltoolbar.element);
var input_area = $('<div/>').addClass('input_area');
this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
@ -99,12 +99,12 @@ var IPython = (function (IPython) {
* @method bind_event
*/
TextCell.prototype.bind_events = function () {
IPython.Cell.prototype.bind_events.apply(this);
Cell.prototype.bind_events.apply(this);
var that = this;
this.element.dblclick(function () {
if (that.selected === false) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
this.events.trigger('select.Cell', {'cell':that});
}
var cont = that.unrender();
if (cont) {
@ -116,7 +116,7 @@ var IPython = (function (IPython) {
// Cell level actions
TextCell.prototype.select = function () {
var cont = IPython.Cell.prototype.select.apply(this);
var cont = Cell.prototype.select.apply(this);
if (cont) {
if (this.mode === 'edit') {
this.code_mirror.refresh();
@ -127,7 +127,7 @@ var IPython = (function (IPython) {
TextCell.prototype.unrender = function () {
if (this.read_only) return;
var cont = IPython.Cell.prototype.unrender.apply(this);
var cont = Cell.prototype.unrender.apply(this);
if (cont) {
var text_cell = this.element;
var output = text_cell.find("div.text_cell_render");
@ -170,7 +170,6 @@ var IPython = (function (IPython) {
/**
* 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();
@ -191,7 +190,7 @@ var IPython = (function (IPython) {
* @method fromJSON
*/
TextCell.prototype.fromJSON = function (data) {
IPython.Cell.prototype.fromJSON.apply(this, arguments);
Cell.prototype.fromJSON.apply(this, arguments);
if (data.cell_type === this.cell_type) {
if (data.source !== undefined) {
this.set_text(data.source);
@ -211,7 +210,7 @@ var IPython = (function (IPython) {
* @return {object} cell data serialised to json
*/
TextCell.prototype.toJSON = function () {
var data = IPython.Cell.prototype.toJSON.apply(this);
var data = Cell.prototype.toJSON.apply(this);
data.source = this.get_text();
if (data.source == this.placeholder) {
data.source = "";
@ -220,16 +219,21 @@ var IPython = (function (IPython) {
};
/**
* @class MarkdownCell
* @constructor MarkdownCell
* @extends IPython.HTMLCell
*/
var MarkdownCell = function (options) {
options = this.mergeopt(MarkdownCell, options);
// Constructor
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// config: dictionary
// keyboard_manager: KeyboardManager instance
// notebook: Notebook instance
options = options || {};
var config = this.mergeopt(MarkdownCell, options.config);
TextCell.apply(this, [$.extend({}, options, {config: config})]);
this.cell_type = 'markdown';
TextCell.apply(this, [options]);
};
MarkdownCell.options_default = {
@ -245,16 +249,16 @@ var IPython = (function (IPython) {
* @method render
*/
MarkdownCell.prototype.render = function () {
var cont = IPython.TextCell.prototype.render.apply(this);
var cont = TextCell.prototype.render.apply(this);
if (cont) {
var text = this.get_text();
var math = null;
if (text === "") { text = this.placeholder; }
var text_and_math = IPython.mathjaxutils.remove_math(text);
var text_and_math = mathjaxutils.remove_math(text);
text = text_and_math[0];
math = text_and_math[1];
var html = marked.parser(marked.lexer(text));
html = IPython.mathjaxutils.replace_math(html, math);
html = mathjaxutils.replace_math(html, math);
html = security.sanitize_html(html);
html = $($.parseHTML(html));
// links in markdown cells should open in new tabs
@ -268,20 +272,23 @@ var IPython = (function (IPython) {
};
// RawCell
/**
* @class RawCell
* @constructor RawCell
* @extends IPython.TextCell
*/
var RawCell = function (options) {
// Constructor
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// config: dictionary
// keyboard_manager: KeyboardManager instance
// notebook: Notebook instance
options = options || {};
var config = this.mergeopt(RawCell, options.config);
TextCell.apply(this, [$.extend({}, options, {config: config})]);
options = this.mergeopt(RawCell,options);
TextCell.apply(this, [options]);
this.cell_type = 'raw';
// RawCell should always hide its rendered div
this.element.find('div.text_cell_render').hide();
this.cell_type = 'raw';
};
RawCell.options_default = {
@ -309,12 +316,12 @@ var IPython = (function (IPython) {
* @method auto_highlight
*/
RawCell.prototype.auto_highlight = function () {
this._auto_highlight(IPython.config.raw_cell_highlight);
this._auto_highlight(this.config.raw_cell_highlight);
};
/** @method render **/
RawCell.prototype.render = function () {
var cont = IPython.TextCell.prototype.render.apply(this);
var cont = TextCell.prototype.render.apply(this);
if (cont){
var text = this.get_text();
if (text === "") { text = this.placeholder; }
@ -325,26 +332,22 @@ var IPython = (function (IPython) {
};
/**
* @class HeadingCell
* @extends IPython.TextCell
*/
/**
* @constructor HeadingCell
* @extends IPython.TextCell
*/
var HeadingCell = function (options) {
options = this.mergeopt(HeadingCell, options);
// Constructor
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// config: dictionary
// keyboard_manager: KeyboardManager instance
// notebook: Notebook instance
options = options || {};
var config = this.mergeopt(HeadingCell, options.config);
TextCell.apply(this, [$.extend({}, options, {config: config})]);
this.level = 1;
this.cell_type = 'heading';
TextCell.apply(this, [options]);
/**
* heading level of the cell, use getter and setter to access
* @property level
*/
};
HeadingCell.options_default = {
@ -412,21 +415,20 @@ var IPython = (function (IPython) {
return r.children().first().html();
};
HeadingCell.prototype.render = function () {
var cont = IPython.TextCell.prototype.render.apply(this);
var cont = TextCell.prototype.render.apply(this);
if (cont) {
var text = this.get_text();
var math = null;
// Markdown headings must be a single line
text = text.replace(/\n/g, ' ');
if (text === "") { text = this.placeholder; }
text = Array(this.level + 1).join("#") + " " + text;
var text_and_math = IPython.mathjaxutils.remove_math(text);
text = new Array(this.level + 1).join("#") + " " + text;
var text_and_math = mathjaxutils.remove_math(text);
text = text_and_math[0];
math = text_and_math[1];
var html = marked.parser(marked.lexer(text));
html = IPython.mathjaxutils.replace_math(html, math);
html = mathjaxutils.replace_math(html, math);
html = security.sanitize_html(html);
var h = $($.parseHTML(html));
// add id and linkback anchor
@ -446,13 +448,17 @@ var IPython = (function (IPython) {
return cont;
};
// Backwards compatability.
IPython.TextCell = TextCell;
IPython.MarkdownCell = MarkdownCell;
IPython.RawCell = RawCell;
IPython.HeadingCell = HeadingCell;
return IPython;
}(IPython));
var textcell = {
'TextCell': TextCell,
'MarkdownCell': MarkdownCell,
'RawCell': RawCell,
'HeadingCell': HeadingCell,
};
return textcell;
});

@ -1,20 +1,10 @@
//----------------------------------------------------------------------------
// Copyright (C) 2008 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// ToolBar
//============================================================================
/**
* @module IPython
* @namespace IPython
* @submodule ToolBar
*/
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
], function(IPython, $) {
"use strict";
/**
@ -23,8 +13,9 @@ var IPython = (function (IPython) {
* @constructor
* @param {Dom object} selector
*/
var ToolBar = function (selector) {
var ToolBar = function (selector, layout_manager) {
this.selector = selector;
this.layout_manager = layout_manager;
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
@ -98,14 +89,13 @@ var IPython = (function (IPython) {
*/
ToolBar.prototype.toggle = function () {
this.element.toggle();
if (IPython.layout_manager !== undefined) {
IPython.layout_manager.do_resize();
if (this.layout_manager !== undefined) {
this.layout_manager.do_resize();
}
};
// Backwards compatability.
IPython.ToolBar = ToolBar;
return IPython;
}(IPython));
return {'ToolBar': ToolBar};
});

@ -1,125 +1,115 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Tooltip
//============================================================================
//
// you can set the autocall time by setting `IPython.tooltip.time_before_tooltip` in ms
//
// you can configure the differents action of pressing shift-tab several times in a row by
// setting/appending different fonction in the array
// IPython.tooltip.tabs_functions
//
// eg :
// IPython.tooltip.tabs_functions[4] = function (){console.log('this is the action of the 4th tab pressing')}
//
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
], function(IPython, $, utils) {
"use strict";
var utils = IPython.utils;
// tooltip constructor
var Tooltip = function () {
var that = this;
this.time_before_tooltip = 1200;
// handle to html
this.tooltip = $('#tooltip');
this._hidden = true;
// variable for consecutive call
this._old_cell = null;
this._old_request = null;
this._consecutive_counter = 0;
// 'sticky ?'
this._sticky = false;
// display tooltip if the docstring is empty?
this._hide_if_no_docstring = false;
var Tooltip = function (events) {
var that = this;
this.events = events;
this.time_before_tooltip = 1200;
// contain the button in the upper right corner
this.buttons = $('<div/>').addClass('tooltipbuttons');
// handle to html
this.tooltip = $('#tooltip');
this._hidden = true;
// will contain the docstring
this.text = $('<div/>').addClass('tooltiptext').addClass('smalltooltip');
// variable for consecutive call
this._old_cell = null;
this._old_request = null;
this._consecutive_counter = 0;
// build the buttons menu on the upper right
// expand the tooltip to see more
var expandlink = $('<a/>').attr('href', "#").addClass("ui-corner-all") //rounded corner
.attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press shift-tab twice)').click(function () {
that.expand();
}).append(
$('<span/>').text('Expand').addClass('ui-icon').addClass('ui-icon-plus'));
// 'sticky ?'
this._sticky = false;
// open in pager
var morelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button').attr('title', 'show the current docstring in pager (press shift-tab 4 times)');
var morespan = $('<span/>').text('Open in Pager').addClass('ui-icon').addClass('ui-icon-arrowstop-l-n');
morelink.append(morespan);
morelink.click(function () {
that.showInPager(that._old_cell);
});
// display tooltip if the docstring is empty?
this._hide_if_no_docstring = false;
// contain the button in the upper right corner
this.buttons = $('<div/>').addClass('tooltipbuttons');
// will contain the docstring
this.text = $('<div/>').addClass('tooltiptext').addClass('smalltooltip');
// build the buttons menu on the upper right
// expand the tooltip to see more
var expandlink = $('<a/>').attr('href', "#").addClass("ui-corner-all") //rounded corner
.attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press shift-tab twice)').click(function () {
that.expand();
}).append(
$('<span/>').text('Expand').addClass('ui-icon').addClass('ui-icon-plus'));
// open in pager
var morelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button').attr('title', 'show the current docstring in pager (press shift-tab 4 times)');
var morespan = $('<span/>').text('Open in Pager').addClass('ui-icon').addClass('ui-icon-arrowstop-l-n');
morelink.append(morespan);
morelink.click(function () {
that.showInPager(that._old_cell);
});
// close the tooltip
var closelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button');
var closespan = $('<span/>').text('Close').addClass('ui-icon').addClass('ui-icon-close');
closelink.append(closespan);
closelink.click(function () {
that.remove_and_cancel_tooltip(true);
});
// close the tooltip
var closelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button');
var closespan = $('<span/>').text('Close').addClass('ui-icon').addClass('ui-icon-close');
closelink.append(closespan);
closelink.click(function () {
that.remove_and_cancel_tooltip(true);
});
this._clocklink = $('<a/>').attr('href', "#");
this._clocklink.attr('role', "button");
this._clocklink.addClass('ui-button');
this._clocklink.attr('title', 'Tootip is not dismissed while typing for 10 seconds');
var clockspan = $('<span/>').text('Close');
clockspan.addClass('ui-icon');
clockspan.addClass('ui-icon-clock');
this._clocklink.append(clockspan);
this._clocklink.click(function () {
that.cancel_stick();
});
this._clocklink = $('<a/>').attr('href', "#");
this._clocklink.attr('role', "button");
this._clocklink.addClass('ui-button');
this._clocklink.attr('title', 'Tootip is not dismissed while typing for 10 seconds');
var clockspan = $('<span/>').text('Close');
clockspan.addClass('ui-icon');
clockspan.addClass('ui-icon-clock');
this._clocklink.append(clockspan);
this._clocklink.click(function () {
that.cancel_stick();
});
//construct the tooltip
// add in the reverse order you want them to appear
this.buttons.append(closelink);
this.buttons.append(expandlink);
this.buttons.append(morelink);
this.buttons.append(this._clocklink);
this._clocklink.hide();
// we need a phony element to make the small arrow
// of the tooltip in css
// we will move the arrow later
this.arrow = $('<div/>').addClass('pretooltiparrow');
this.tooltip.append(this.buttons);
this.tooltip.append(this.arrow);
this.tooltip.append(this.text);
// function that will be called if you press tab 1, 2, 3... times in a row
this.tabs_functions = [function (cell, text, cursor) {
that._request_tooltip(cell, text, cursor);
}, function () {
that.expand();
}, function () {
that.stick();
}, function (cell) {
that.cancel_stick();
that.showInPager(cell);
}];
// call after all the tabs function above have bee call to clean their effects
// if necessary
this.reset_tabs_function = function (cell, text) {
this._old_cell = (cell) ? cell : null;
this._old_request = (text) ? text : null;
this._consecutive_counter = 0;
};
//construct the tooltip
// add in the reverse order you want them to appear
this.buttons.append(closelink);
this.buttons.append(expandlink);
this.buttons.append(morelink);
this.buttons.append(this._clocklink);
this._clocklink.hide();
// we need a phony element to make the small arrow
// of the tooltip in css
// we will move the arrow later
this.arrow = $('<div/>').addClass('pretooltiparrow');
this.tooltip.append(this.buttons);
this.tooltip.append(this.arrow);
this.tooltip.append(this.text);
// function that will be called if you press tab 1, 2, 3... times in a row
this.tabs_functions = [function (cell, text, cursor) {
that._request_tooltip(cell, text, cursor);
}, function () {
that.expand();
}, function () {
that.stick();
}, function (cell) {
that.cancel_stick();
that.showInPager(cell);
}];
// call after all the tabs function above have bee call to clean their effects
// if necessary
this.reset_tabs_function = function (cell, text) {
this._old_cell = (cell) ? cell : null;
this._old_request = (text) ? text : null;
this._consecutive_counter = 0;
};
};
Tooltip.prototype.is_visible = function () {
return !this._hidden;
@ -131,7 +121,7 @@ var IPython = (function (IPython) {
var payload = {};
payload.text = that._reply.content.data['text/plain'];
$([IPython.events]).trigger('open_with_text.Pager', payload);
this.events.trigger('open_with_text.Pager', payload);
this.remove_and_cancel_tooltip();
};
@ -338,8 +328,8 @@ var IPython = (function (IPython) {
this.text.scrollTop(0);
};
// Backwards compatability.
IPython.Tooltip = Tooltip;
return IPython;
}(IPython));
return {'Tooltip': Tooltip};
});

@ -1,135 +1,124 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Tour of IPython Notebok UI (with Bootstrap Tour)
//============================================================================
define([
'base/js/namespace',
'jquery',
'bootstraptour',
], function(IPython, $, Tour) {
"use strict";
var tour_steps = [
{
title: "Welcome to the Notebook Tour",
placement: 'bottom',
orphan: true,
content: "This tour will take 2 minutes.",
}, {
element: "#notebook_name",
title: "Filename",
placement: 'bottom',
content: "Click here to change the filename for this notebook."
}, {
element: $("#menus").parent(),
placement: 'bottom',
backdrop: true,
title: "Notebook Menubar",
content: "The menubar has menus for actions on the notebook, its cells, and the kernel it communicates with."
}, {
element: "#maintoolbar",
placement: 'bottom',
backdrop: true,
title: "Notebook Toolbar",
content: "The toolbar has buttons for the most common actions. Hover your mouse over each button for more information."
}, {
element: "#modal_indicator",
title: "Mode Indicator",
placement: 'bottom',
content: "The Notebook has two modes: Edit Mode and Command Mode. In this area, an indicator can appear to tell you which mode you are in.",
onShow: function(tour) { command_icon_hack(); }
}, {
element: "#modal_indicator",
title: "Command Mode",
placement: 'bottom',
onShow: function(tour) { IPython.notebook.command_mode(); command_icon_hack(); },
onNext: function(tour) { edit_mode(); },
content: "Right now you are in Command Mode, and many keyboard shortcuts are available. In this mode, no icon is displayed in the indicator area."
}, {
element: "#modal_indicator",
title: "Edit Mode",
placement: 'bottom',
onShow: function(tour) { edit_mode(); },
content: "Pressing <code>Enter</code> or clicking in the input text area of the cell switches to Edit Mode."
}, {
element: '.selected',
title: "Edit Mode",
placement: 'bottom',
onShow: function(tour) { edit_mode(); },
content: "Notice that the border around the currently active cell changed color. Typing will insert text into the currently active cell."
}, {
element: '.selected',
title: "Back to Command Mode",
placement: 'bottom',
onShow: function(tour) { IPython.notebook.command_mode(); },
onHide: function(tour) { $('#help_menu').parent().children('a').click(); },
content: "Pressing <code>Esc</code> or clicking outside of the input text area takes you back to Command Mode."
}, {
element: '#keyboard_shortcuts',
title: "Keyboard Shortcuts",
placement: 'bottom',
onHide: function(tour) { $('#help_menu').parent().children('a').click(); },
content: "You can click here to get a list of all of the keyboard shortcuts."
}, {
element: "#kernel_indicator",
title: "Kernel Indicator",
placement: 'bottom',
onShow: function(tour) { $([IPython.events]).trigger('status_idle.Kernel');},
content: "This is the Kernel indicator. It looks like this when the Kernel is idle.",
}, {
element: "#kernel_indicator",
title: "Kernel Indicator",
placement: 'bottom',
onShow: function(tour) { $([IPython.events]).trigger('status_busy.Kernel'); },
content: "The Kernel indicator looks like this when the Kernel is busy.",
}, {
element: ".icon-stop",
placement: 'bottom',
title: "Interrupting the Kernel",
onHide: function(tour) { $([IPython.events]).trigger('status_idle.Kernel'); },
content: "To cancel a computation in progress, you can click here."
}, {
element: "#notification_kernel",
placement: 'bottom',
onShow: function(tour) { $('.icon-stop').click(); },
title: "Notification Area",
content: "Messages in response to user actions (Save, Interrupt, etc) appear here."
}, {
title: "Fin.",
placement: 'bottom',
orphan: true,
content: "This concludes the IPython Notebook User Interface Tour. Happy hacking!",
}
];
var tour_style = "<div class='popover tour'>\n" +
"<div class='arrow'></div>\n" +
"<div style='position:absolute; top:7px; right:7px'>\n" +
"<button class='btn btn-default btn-sm icon-remove' data-role='end'></button>\n" +
"</div><h3 class='popover-title'></h3>\n" +
"<div class='popover-content'></div>\n" +
"<div class='popover-navigation'>\n" +
"<button class='btn btn-default icon-step-backward' data-role='prev'></button>\n" +
"<button class='btn btn-default icon-step-forward pull-right' data-role='next'></button>\n" +
"<button id='tour-pause' class='btn btn-sm btn-default icon-pause' data-resume-text='' data-pause-text='' data-role='pause-resume'></button>\n" +
"</div>\n" +
"</div>";
var tour_style = "<div class='popover tour'>\
<div class='arrow'></div>\
<div style='position:absolute; top:7px; right:7px'>\
<button class='btn btn-default btn-sm icon-remove' data-role='end'></button></div>\
<h3 class='popover-title'></h3>\
<div class='popover-content'></div>\
<div class='popover-navigation'>\
<button class='btn btn-default icon-step-backward' data-role='prev'></button>\
<button class='btn btn-default icon-step-forward pull-right' data-role='next'></button>\
<button id='tour-pause' class='btn btn-sm btn-default icon-pause' data-resume-text='' data-pause-text='' data-role='pause-resume'></button>\
</div>\
</div>";
var command_icon_hack = function() {$('#modal_indicator').css('min-height', 20);}
var toggle_pause_play = function () { $('#tour-pause').toggleClass('icon-pause icon-play'); };
var edit_mode = function() {
IPython.notebook.focus_cell();
IPython.notebook.edit_mode();
;}
IPython = (function (IPython) {
"use strict";
var NotebookTour = function () {
var NotebookTour = function (notebook, events) {
var that = this;
this.notebook = notebook;
this.step_duration = 0;
this.tour_steps = tour_steps ;
this.tour_steps[0].content = "You can use the left and right arrow keys to go backwards and forwards.";
this.events = events;
this.tour_steps = [
{
title: "Welcome to the Notebook Tour",
placement: 'bottom',
orphan: true,
content: "You can use the left and right arrow keys to go backwards and forwards.",
}, {
element: "#notebook_name",
title: "Filename",
placement: 'bottom',
content: "Click here to change the filename for this notebook."
}, {
element: $("#menus").parent(),
placement: 'bottom',
backdrop: true,
title: "Notebook Menubar",
content: "The menubar has menus for actions on the notebook, its cells, and the kernel it communicates with."
}, {
element: "#maintoolbar",
placement: 'bottom',
backdrop: true,
title: "Notebook Toolbar",
content: "The toolbar has buttons for the most common actions. Hover your mouse over each button for more information."
}, {
element: "#modal_indicator",
title: "Mode Indicator",
placement: 'bottom',
content: "The Notebook has two modes: Edit Mode and Command Mode. In this area, an indicator can appear to tell you which mode you are in.",
onShow: function(tour) { that.command_icon_hack(); }
}, {
element: "#modal_indicator",
title: "Command Mode",
placement: 'bottom',
onShow: function(tour) { notebook.command_mode(); that.command_icon_hack(); },
onNext: function(tour) { that.edit_mode(); },
content: "Right now you are in Command Mode, and many keyboard shortcuts are available. In this mode, no icon is displayed in the indicator area."
}, {
element: "#modal_indicator",
title: "Edit Mode",
placement: 'bottom',
onShow: function(tour) { that.edit_mode(); },
content: "Pressing <code>Enter</code> or clicking in the input text area of the cell switches to Edit Mode."
}, {
element: '.selected',
title: "Edit Mode",
placement: 'bottom',
onShow: function(tour) { that.edit_mode(); },
content: "Notice that the border around the currently active cell changed color. Typing will insert text into the currently active cell."
}, {
element: '.selected',
title: "Back to Command Mode",
placement: 'bottom',
onShow: function(tour) { notebook.command_mode(); },
onHide: function(tour) { $('#help_menu').parent().children('a').click(); },
content: "Pressing <code>Esc</code> or clicking outside of the input text area takes you back to Command Mode."
}, {
element: '#keyboard_shortcuts',
title: "Keyboard Shortcuts",
placement: 'bottom',
onHide: function(tour) { $('#help_menu').parent().children('a').click(); },
content: "You can click here to get a list of all of the keyboard shortcuts."
}, {
element: "#kernel_indicator",
title: "Kernel Indicator",
placement: 'bottom',
onShow: function(tour) { events.trigger('status_idle.Kernel');},
content: "This is the Kernel indicator. It looks like this when the Kernel is idle.",
}, {
element: "#kernel_indicator",
title: "Kernel Indicator",
placement: 'bottom',
onShow: function(tour) { events.trigger('status_busy.Kernel'); },
content: "The Kernel indicator looks like this when the Kernel is busy.",
}, {
element: ".icon-stop",
placement: 'bottom',
title: "Interrupting the Kernel",
onHide: function(tour) { events.trigger('status_idle.Kernel'); },
content: "To cancel a computation in progress, you can click here."
}, {
element: "#notification_kernel",
placement: 'bottom',
onShow: function(tour) { $('.icon-stop').click(); },
title: "Notification Area",
content: "Messages in response to user actions (Save, Interrupt, etc) appear here."
}, {
title: "Fin.",
placement: 'bottom',
orphan: true,
content: "This concludes the IPython Notebook User Interface tour.Tour. Happy hacking!",
}
];
this.tour = new Tour({
//orphan: true,
storage: false, // start tour from beginning every time
@ -143,8 +132,8 @@ IPython = (function (IPython) {
// TODO: remove the onPause/onResume logic once pi's patch has been
// merged upstream to make this work via data-resume-class and
// data-resume-text attributes.
onPause: toggle_pause_play,
onResume: toggle_pause_play,
onPause: this.toggle_pause_play,
onResume: this.toggle_pause_play,
steps: this.tour_steps,
template: tour_style,
orphan: true
@ -162,9 +151,23 @@ IPython = (function (IPython) {
}
};
// Set module variables
NotebookTour.prototype.command_icon_hack = function() {
$('#modal_indicator').css('min-height', 20);
};
NotebookTour.prototype.toggle_pause_play = function () {
$('#tour-pause').toggleClass('icon-pause icon-play');
};
NotebookTour.prototype.edit_mode = function() {
this.notebook.focus_cell();
this.notebook.edit_mode();
};
// For backwards compatability.
IPython.NotebookTour = NotebookTour;
return IPython;
return {'Tour': NotebookTour};
});
}(IPython));

@ -1,21 +1,11 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Comm and CommManager bases
//============================================================================
/**
* Base Comm classes
* @module IPython
* @namespace IPython
* @submodule comm
*/
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
], function(IPython, $, utils) {
"use strict";
//-----------------------------------------------------------------------
@ -125,7 +115,7 @@ var IPython = (function (IPython) {
var Comm = function (target_name, comm_id) {
this.target_name = target_name;
this.comm_id = comm_id || IPython.utils.uuid();
this.comm_id = comm_id || utils.uuid();
this._msg_callback = this._close_callback = null;
};
@ -189,10 +179,12 @@ var IPython = (function (IPython) {
this._maybe_callback('close', msg);
};
// For backwards compatability.
IPython.CommManager = CommManager;
IPython.Comm = Comm;
return IPython;
}(IPython));
return {
'CommManager': CommManager,
'Comm': Comm
};
});

@ -1,27 +1,22 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Kernel
//============================================================================
/**
* @module IPython
* @namespace IPython
* @submodule Kernel
*/
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'services/kernels/js/comm',
'widgets/js/init',
], function(IPython, $, utils, comm, widgetmanager) {
"use strict";
var utils = IPython.utils;
// Initialization and connection.
/**
* A Kernel Class to communicate with the Python kernel
* @Class Kernel
*/
var Kernel = function (kernel_service_url) {
var Kernel = function (kernel_service_url, notebook) {
this.events = notebook.events;
this.kernel_id = null;
this.shell_channel = null;
this.iopub_channel = null;
@ -43,8 +38,8 @@ var IPython = (function (IPython) {
this.bind_events();
this.init_iopub_handlers();
this.comm_manager = new IPython.CommManager(this);
this.widget_manager = new IPython.WidgetManager(this.comm_manager);
this.comm_manager = new comm.CommManager(this);
this.widget_manager = new widgetmanager.WidgetManager(this.comm_manager, notebook);
this.last_msg_id = null;
this.last_msg_callbacks = {};
@ -69,7 +64,7 @@ var IPython = (function (IPython) {
Kernel.prototype.bind_events = function () {
var that = this;
$([IPython.events]).on('send_input_reply.Kernel', function(evt, data) {
this.events.on('send_input_reply.Kernel', function(evt, data) {
that.send_input_reply(data);
});
};
@ -111,7 +106,7 @@ var IPython = (function (IPython) {
* @method restart
*/
Kernel.prototype.restart = function () {
$([IPython.events]).trigger('status_restarting.Kernel', {kernel: this});
this.events.trigger('status_restarting.Kernel', {kernel: this});
if (this.running) {
this.stop_channels();
this.post(utils.url_join_encode(this.kernel_url, "restart"),
@ -135,7 +130,7 @@ var IPython = (function (IPython) {
Kernel.prototype._websocket_closed = function(ws_url, early) {
this.stop_channels();
$([IPython.events]).trigger('websocket_closed.Kernel',
this.events.trigger('websocket_closed.Kernel',
{ws_url: ws_url, kernel: this, early: early}
);
};
@ -215,7 +210,7 @@ var IPython = (function (IPython) {
if ( !channels[i].readyState ) return;
}
// all events ready, trigger started event.
$([IPython.events]).trigger('status_started.Kernel', {kernel: this});
this.events.trigger('status_started.Kernel', {kernel: this});
};
/**
@ -348,7 +343,7 @@ var IPython = (function (IPython) {
content.allow_stdin = true;
}
$.extend(true, content, options);
$([IPython.events]).trigger('execution_request.Kernel', {kernel: this, content:content});
this.events.trigger('execution_request.Kernel', {kernel: this, content:content});
return this.send_shell_message("execute_request", content, callbacks);
};
@ -380,7 +375,7 @@ var IPython = (function (IPython) {
Kernel.prototype.interrupt = function () {
if (this.running) {
$([IPython.events]).trigger('status_interrupting.Kernel', {kernel: this});
this.events.trigger('status_interrupting.Kernel', {kernel: this});
this.post(utils.url_join_encode(this.kernel_url, "interrupt"));
}
};
@ -402,7 +397,7 @@ var IPython = (function (IPython) {
var content = {
value : input,
};
$([IPython.events]).trigger('input_reply.Kernel', {kernel: this, content:content});
this.events.trigger('input_reply.Kernel', {kernel: this, content:content});
var msg = this._get_msg("input_reply", content);
this.stdin_channel.send(JSON.stringify(msg));
return msg.header.msg_id;
@ -482,7 +477,7 @@ var IPython = (function (IPython) {
Kernel.prototype._handle_shell_reply = function (e) {
var reply = $.parseJSON(e.data);
$([IPython.events]).trigger('shell_reply.Kernel', {kernel: this, reply:reply});
this.events.trigger('shell_reply.Kernel', {kernel: this, reply:reply});
var content = reply.content;
var metadata = reply.metadata;
var parent_id = reply.parent_header.msg_id;
@ -532,7 +527,7 @@ var IPython = (function (IPython) {
}
if (execution_state === 'busy') {
$([IPython.events]).trigger('status_busy.Kernel', {kernel: this});
this.events.trigger('status_busy.Kernel', {kernel: this});
} else if (execution_state === 'idle') {
// signal that iopub callbacks are (probably) done
// async output may still arrive,
@ -540,17 +535,17 @@ var IPython = (function (IPython) {
this._finish_iopub(parent_id);
// trigger status_idle event
$([IPython.events]).trigger('status_idle.Kernel', {kernel: this});
this.events.trigger('status_idle.Kernel', {kernel: this});
} else if (execution_state === 'restarting') {
// autorestarting is distinct from restarting,
// in that it means the kernel died and the server is restarting it.
// status_restarting sets the notification widget,
// autorestart shows the more prominent dialog.
$([IPython.events]).trigger('status_autorestarting.Kernel', {kernel: this});
$([IPython.events]).trigger('status_restarting.Kernel', {kernel: this});
this.events.trigger('status_autorestarting.Kernel', {kernel: this});
this.events.trigger('status_restarting.Kernel', {kernel: this});
} else if (execution_state === 'dead') {
this.stop_channels();
$([IPython.events]).trigger('status_dead.Kernel', {kernel: this});
this.events.trigger('status_dead.Kernel', {kernel: this});
}
};
@ -610,10 +605,8 @@ var IPython = (function (IPython) {
}
};
// Backwards compatability.
IPython.Kernel = Kernel;
return IPython;
}(IPython));
return {'Kernel': Kernel};
});

@ -1,26 +1,21 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Notebook
//============================================================================
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'services/kernels/js/kernel',
], function(IPython, $, utils, kernel) {
"use strict";
var utils = IPython.utils;
var Session = function(notebook, options){
var Session = function(options){
this.kernel = null;
this.id = null;
this.notebook = notebook;
this.name = notebook.notebook_name;
this.path = notebook.notebook_path;
this.base_url = notebook.base_url;
this.notebook = options.notebook;
this.name = options.notebook_name;
this.path = options.notebook_path;
this.base_url = options.base_url;
};
Session.prototype.start = function(callback) {
@ -92,7 +87,7 @@ var IPython = (function (IPython) {
Session.prototype._handle_start_success = function (data, status, xhr) {
this.id = data.id;
var kernel_service_url = utils.url_path_join(this.base_url, "api/kernels");
this.kernel = new IPython.Kernel(kernel_service_url);
this.kernel = new kernel.Kernel(kernel_service_url, this.notebook);
this.kernel._kernel_started(data.kernel);
};
@ -114,8 +109,8 @@ var IPython = (function (IPython) {
this.kernel.kill();
};
// For backwards compatability.
IPython.Session = Session;
return IPython;
}(IPython));
return {'Session': Session};
});

@ -1,18 +1,12 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
//============================================================================
// NotebookList
//============================================================================
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
], function(IPython, $, utils) {
"use strict";
var utils = IPython.utils;
var ClusterList = function (selector, options) {
this.selector = selector;
@ -188,11 +182,12 @@ var IPython = (function (IPython) {
});
};
// For backwards compatability.
IPython.ClusterList = ClusterList;
IPython.ClusterItem = ClusterItem;
return IPython;
}(IPython));
return {
'ClusterList': ClusterList,
'ClusterItem': ClusterItem,
};
});

@ -1,24 +1,29 @@
//----------------------------------------------------------------------------
// Copyright (C) 2014 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.
//----------------------------------------------------------------------------
//============================================================================
// Running Kernels List
//============================================================================
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'tree/js/notebooklist',
], function(IPython, $, notebooklist) {
"use strict";
var utils = IPython.utils;
var KernelList = function (selector, options) {
IPython.NotebookList.call(this, selector, options, 'running');
// Constructor
//
// Parameters:
// selector: string
// options: dictionary
// Dictionary of keyword arguments.
// session_list: SessionList instance
// base_url: string
// notebook_path: string
notebooklist.NotebookList.call(this, selector, $.extend({
element_name: 'running'},
options));
};
KernelList.prototype = Object.create(IPython.NotebookList.prototype);
KernelList.prototype = Object.create(notebooklist.NotebookList.prototype);
KernelList.prototype.sessions_loaded = function (d) {
this.sessions = d;
@ -31,10 +36,10 @@ var IPython = (function (IPython) {
}
$('#running_list_header').toggle($.isEmptyObject(d));
}
};
// Backwards compatability.
IPython.KernelList = KernelList;
return IPython;
}(IPython));
return {'KernelList': KernelList};
});

@ -1,32 +1,53 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// On document ready
//============================================================================
$(document).ready(function () {
IPython.page = new IPython.Page();
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
require([
'base/js/namespace',
'jquery',
'base/js/events',
'base/js/page',
'base/js/utils',
'tree/js/notebooklist',
'tree/js/clusterlist',
'tree/js/sessionlist',
'tree/js/kernellist',
'auth/js/loginwidget',
'components/jquery-ui/ui/minified/jquery-ui.min',
'components/bootstrap/js/bootstrap.min',
], function(
IPython,
$,
events,
page,
utils,
notebooklist,
clusterlist,
sesssionlist,
kernellist,
loginwidget){
page = new page.Page();
var common_options = {
base_url: utils.get_body_data("baseUrl"),
notebook_path: utils.get_body_data("notebookPath"),
};
events = $([new events.Events()]);
session_list = new sesssionlist.SesssionList($.extend({
events: events},
common_options));
notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
session_list: session_list},
common_options));
cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
kernel_list = new kernellist.KernelList('#running_list', $.extend({
session_list: session_list},
common_options));
login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
$('#new_notebook').button().click(function (e) {
IPython.notebook_list.new_notebook()
notebook_list.new_notebook();
});
var opts = {
base_url : IPython.utils.get_body_data("baseUrl"),
notebook_path : IPython.utils.get_body_data("notebookPath"),
};
IPython.session_list = new IPython.SesssionList(opts);
IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts);
IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts);
IPython.kernel_list = new IPython.KernelList('#running_list', opts);
IPython.login_widget = new IPython.LoginWidget('#login_widget', opts);
var interval_id=0;
// auto refresh every xx secondes, no need to be fast,
@ -35,31 +56,31 @@ $(document).ready(function () {
var enable_autorefresh = function(){
//refresh immediately , then start interval
if($('.upload_button').length == 0)
if($('.upload_button').length === 0)
{
IPython.session_list.load_sessions();
IPython.cluster_list.load_list();
session_list.load_sessions();
cluster_list.load_list();
}
if (!interval_id){
interval_id = setInterval(function(){
if($('.upload_button').length == 0)
if($('.upload_button').length === 0)
{
IPython.session_list.load_sessions();
IPython.cluster_list.load_list();
session_list.load_sessions();
cluster_list.load_list();
}
}, time_refresh*1000);
}
}
};
var disable_autorefresh = function(){
clearInterval(interval_id);
interval_id = 0;
}
};
// stop autorefresh when page lose focus
$(window).blur(function() {
disable_autorefresh();
})
});
//re-enable when page get focus back
$(window).focus(function() {
@ -69,24 +90,30 @@ $(document).ready(function () {
// finally start it, it will refresh immediately
enable_autorefresh();
IPython.page.show();
$([IPython.events]).trigger('app_initialized.DashboardApp');
page.show();
events.trigger('app_initialized.DashboardApp');
// bound the upload method to the on change of the file select list
$("#alternate_upload").change(function (event){
IPython.notebook_list.handleFilesUpload(event,'form');
notebook_list.handleFilesUpload(event,'form');
});
// set hash on tab click
$("#tabs").find("a").click(function() {
window.location.hash = $(this).attr("href");
})
});
// load tab if url hash
if (window.location.hash) {
$("#tabs").find("a[href=" + window.location.hash + "]").click();
}
// For backwards compatability.
IPython.page = page;
IPython.notebook_list = notebook_list;
IPython.cluster_list = cluster_list;
IPython.session_list = session_list;
IPython.kernel_list = kernel_list;
IPython.login_widget = login_widget;
IPython.events = events;
});

@ -1,23 +1,29 @@
//----------------------------------------------------------------------------
// Copyright (C) 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.
//----------------------------------------------------------------------------
//============================================================================
// NotebookList
//============================================================================
var IPython = (function (IPython) {
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/dialog',
], function(IPython, $, utils, dialog) {
"use strict";
var utils = IPython.utils;
var NotebookList = function (selector, options, element_name) {
var that = this
var NotebookList = function (selector, options) {
// Constructor
//
// Parameters:
// selector: string
// options: dictionary
// Dictionary of keyword arguments.
// session_list: SessionList instance
// element_name: string
// base_url: string
// notebook_path: string
var that = this;
this.session_list = options.session_list;
// allow code re-use by just changing element_name in kernellist.js
this.element_name = element_name || 'notebook';
this.element_name = options.element_name || 'notebook';
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
@ -28,12 +34,14 @@ var IPython = (function (IPython) {
this.sessions = {};
this.base_url = options.base_url || utils.get_body_data("baseUrl");
this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath");
$([IPython.events]).on('sessions_loaded.Dashboard',
function(e, d) { that.sessions_loaded(d); });
if (this.session_list && this.session_list.events) {
this.session_list.events.on('sessions_loaded.Dashboard',
function(e, d) { that.sessions_loaded(d); });
}
};
NotebookList.prototype.style = function () {
var prefix = '#' + this.element_name
var prefix = '#' + this.element_name;
$(prefix + '_toolbar').addClass('list_toolbar');
$(prefix + '_list_info').addClass('toolbar_info');
$(prefix + '_buttons').addClass('toolbar_buttons');
@ -84,10 +92,10 @@ var IPython = (function (IPython) {
that.add_upload_button(nbitem);
};
} else {
var dialog = 'Uploaded notebooks must be .ipynb files';
IPython.dialog.modal({
var dialog_body = 'Uploaded notebooks must be .ipynb files';
dialog.modal({
title : 'Invalid file type',
body : dialog,
body : dialog_body,
buttons : {'OK' : {'class' : 'btn-primary'}}
});
}
@ -114,7 +122,7 @@ var IPython = (function (IPython) {
};
NotebookList.prototype.load_sessions = function(){
IPython.session_list.load_sessions();
this.session_list.load_sessions();
};
@ -301,7 +309,7 @@ var IPython = (function (IPython) {
var parent_item = that.parents('div.list_item');
var nbname = parent_item.data('nbname');
var message = 'Are you sure you want to permanently delete the notebook: ' + nbname + '?';
IPython.dialog.modal({
dialog.modal({
title : "Delete notebook",
body : message,
buttons : {
@ -426,16 +434,15 @@ var IPython = (function (IPython) {
} else {
msg = xhr.statusText;
}
IPython.dialog.modal({
dialog.modal({
title : 'Creating Notebook Failed',
body : "The error was: " + msg,
buttons : {'OK' : {'class' : 'btn-primary'}}
});
}
};
// Backwards compatability.
IPython.NotebookList = NotebookList;
return IPython;
}(IPython));
return {'NotebookList': NotebookList};
});

@ -1,20 +1,22 @@
//----------------------------------------------------------------------------
// Copyright (C) 2014 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Running Kernels List
//============================================================================
var IPython = (function (IPython) {
define([
'base/js/namespace',
'jquery',
'base/js/utils',
], function(IPython, $, utils) {
"use strict";
var utils = IPython.utils;
var SesssionList = function (options) {
// Constructor
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// base_url : string
this.events = options.events;
this.sessions = {};
this.base_url = options.base_url || utils.get_body_data("baseUrl");
};
@ -44,10 +46,11 @@ var IPython = (function (IPython) {
);
this.sessions[nb_path] = data[i].id;
}
$([IPython.events]).trigger('sessions_loaded.Dashboard', this.sessions);
this.events.trigger('sessions_loaded.Dashboard', this.sessions);
};
IPython.SesssionList = SesssionList;
return IPython;
// Backwards compatability.
IPython.SesssionList = SesssionList;
}(IPython));
return {'SesssionList': SesssionList};
});

@ -1,15 +1,8 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
//============================================================================
// Basic Widgets
//============================================================================
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
"widgets/js/manager",
"widgets/js/widget_bool",
"widgets/js/widget_button",
"widgets/js/widget_container",
@ -19,4 +12,16 @@ define([
"widgets/js/widget_selection",
"widgets/js/widget_selectioncontainer",
"widgets/js/widget_string",
], function(){ return true; });
], function(widgetmanager) {
// Register all of the loaded views with the widget manager.
for (var i = 1; i < arguments.length; i++) {
for (var target_name in arguments[i]) {
if (arguments[i].hasOwnProperty(target_name)) {
widgetmanager.WidgetManager.register_widget_view(target_name, arguments[i][target_name]);
}
}
}
return {'WidgetManager': widgetmanager.WidgetManager};
});

@ -1,214 +1,201 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
//============================================================================
// WidgetModel, WidgetView, and WidgetManager
//============================================================================
/**
* Base Widget classes
* @module IPython
* @namespace IPython
* @submodule widget
*/
(function () {
"use strict";
// Use require.js 'define' method so that require.js is intelligent enough to
// syncronously load everything within this file when it is being 'required'
// elsewhere.
define(["underscore",
"backbone",
], function (_, Backbone) {
//--------------------------------------------------------------------
// WidgetManager class
//--------------------------------------------------------------------
var WidgetManager = function (comm_manager) {
// Public constructor
WidgetManager._managers.push(this);
// Attach a comm manager to the
this.comm_manager = comm_manager;
this._models = {}; /* Dictionary of model ids and model instances */
// Register already-registered widget model types with the comm manager.
var that = this;
_.each(WidgetManager._model_types, function(model_type, model_name) {
that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that));
});
};
//--------------------------------------------------------------------
// Class level
//--------------------------------------------------------------------
WidgetManager._model_types = {}; /* Dictionary of model type names (target_name) and model types. */
WidgetManager._view_types = {}; /* Dictionary of view names and view types. */
WidgetManager._managers = []; /* List of widget managers */
WidgetManager.register_widget_model = function (model_name, model_type) {
// Registers a widget model by name.
WidgetManager._model_types[model_name] = model_type;
// Register the widget with the comm manager. Make sure to pass this object's context
// in so `this` works in the call back.
_.each(WidgetManager._managers, function(instance, i) {
if (instance.comm_manager !== null) {
instance.comm_manager.register_target(model_name, $.proxy(instance._handle_comm_open, instance));
}
});
};
WidgetManager.register_widget_view = function (view_name, view_type) {
// Registers a widget view by name.
WidgetManager._view_types[view_name] = view_type;
};
//--------------------------------------------------------------------
// Instance level
//--------------------------------------------------------------------
WidgetManager.prototype.display_view = function(msg, model) {
// Displays a view for a particular model.
var cell = this.get_msg_cell(msg.parent_header.msg_id);
if (cell === null) {
console.log("Could not determine where the display" +
" message was from. Widget will not be displayed");
} else {
var view = this.create_view(model, {cell: cell});
if (view === null) {
console.error("View creation failed", model);
}
if (cell.widget_subarea) {
cell.widget_area.show();
this._handle_display_view(view);
cell.widget_subarea.append(view.$el);
view.trigger('displayed');
}
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
"underscore",
"backbone",
"base/js/namespace"
], function (_, Backbone, IPython) {
//--------------------------------------------------------------------
// WidgetManager class
//--------------------------------------------------------------------
var WidgetManager = function (comm_manager, notebook) {
// Public constructor
WidgetManager._managers.push(this);
// Attach a comm manager to the
this.keyboard_manager = notebook.keyboard_manager;
this.notebook = notebook;
this.comm_manager = comm_manager;
this._models = {}; /* Dictionary of model ids and model instances */
// Register already-registered widget model types with the comm manager.
var that = this;
_.each(WidgetManager._model_types, function(model_type, model_name) {
that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that));
});
};
//--------------------------------------------------------------------
// Class level
//--------------------------------------------------------------------
WidgetManager._model_types = {}; /* Dictionary of model type names (target_name) and model types. */
WidgetManager._view_types = {}; /* Dictionary of view names and view types. */
WidgetManager._managers = []; /* List of widget managers */
WidgetManager.register_widget_model = function (model_name, model_type) {
// Registers a widget model by name.
WidgetManager._model_types[model_name] = model_type;
// Register the widget with the comm manager. Make sure to pass this object's context
// in so `this` works in the call back.
_.each(WidgetManager._managers, function(instance, i) {
if (instance.comm_manager !== null) {
instance.comm_manager.register_target(model_name, $.proxy(instance._handle_comm_open, instance));
}
};
WidgetManager.prototype._handle_display_view = function (view) {
// Have the IPython keyboard manager disable its event
// handling so the widget can capture keyboard input.
// Note, this is only done on the outer most widgets.
IPython.keyboard_manager.register_events(view.$el);
if (view.additional_elements) {
for (var i = 0; i < view.additional_elements.length; i++) {
IPython.keyboard_manager.register_events(view.additional_elements[i]);
}
}
};
WidgetManager.prototype.create_view = function(model, options, view) {
// Creates a view for a particular model.
var view_name = model.get('_view_name');
var ViewType = WidgetManager._view_types[view_name];
if (ViewType) {
// If a view is passed into the method, use that view's cell as
// the cell for the view that is created.
options = options || {};
if (view !== undefined) {
options.cell = view.options.cell;
}
// Create and render the view...
var parameters = {model: model, options: options};
view = new ViewType(parameters);
view.render();
model.on('destroy', view.remove, view);
return view;
});
};
WidgetManager.register_widget_view = function (view_name, view_type) {
// Registers a widget view by name.
WidgetManager._view_types[view_name] = view_type;
};
//--------------------------------------------------------------------
// Instance level
//--------------------------------------------------------------------
WidgetManager.prototype.display_view = function(msg, model) {
// Displays a view for a particular model.
var cell = this.get_msg_cell(msg.parent_header.msg_id);
if (cell === null) {
console.log("Could not determine where the display" +
" message was from. Widget will not be displayed");
} else {
var view = this.create_view(model, {cell: cell});
if (view === null) {
console.error("View creation failed", model);
}
return null;
};
WidgetManager.prototype.get_msg_cell = function (msg_id) {
var cell = null;
// First, check to see if the msg was triggered by cell execution.
if (IPython.notebook) {
cell = IPython.notebook.get_msg_cell(msg_id);
if (cell.widget_subarea) {
cell.widget_area.show();
this._handle_display_view(view);
cell.widget_subarea.append(view.$el);
view.trigger('displayed');
}
if (cell !== null) {
return cell;
}
};
WidgetManager.prototype._handle_display_view = function (view) {
// Have the IPython keyboard manager disable its event
// handling so the widget can capture keyboard input.
// Note, this is only done on the outer most widgets.
if (this.keyboard_manager) {
this.keyboard_manager.register_events(view.$el);
if (view.additional_elements) {
for (var i = 0; i < view.additional_elements.length; i++) {
this.keyboard_manager.register_events(view.additional_elements[i]);
}
// Second, check to see if a get_cell callback was defined
// for the message. get_cell callbacks are registered for
// widget messages, so this block is actually checking to see if the
// message was triggered by a widget.
var kernel = this.comm_manager.kernel;
if (kernel) {
var callbacks = kernel.get_callbacks_for_msg(msg_id);
if (callbacks && callbacks.iopub &&
callbacks.iopub.get_cell !== undefined) {
return callbacks.iopub.get_cell();
}
}
}
};
WidgetManager.prototype.create_view = function(model, options, view) {
// Creates a view for a particular model.
var view_name = model.get('_view_name');
var ViewType = WidgetManager._view_types[view_name];
if (ViewType) {
// If a view is passed into the method, use that view's cell as
// the cell for the view that is created.
options = options || {};
if (view !== undefined) {
options.cell = view.options.cell;
}
// Not triggered by a cell or widget (no get_cell callback
// exists).
return null;
};
WidgetManager.prototype.callbacks = function (view) {
// callback handlers specific a view
var callbacks = {};
if (view && view.options.cell) {
// Try to get output handlers
var cell = view.options.cell;
var handle_output = null;
var handle_clear_output = null;
if (cell.output_area) {
handle_output = $.proxy(cell.output_area.handle_output, cell.output_area);
handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area);
}
// Create callback dict using what is known
var that = this;
callbacks = {
iopub : {
output : handle_output,
clear_output : handle_clear_output,
// Special function only registered by widget messages.
// Allows us to get the cell for a message so we know
// where to add widgets if the code requires it.
get_cell : function () {
return cell;
},
},
};
// Create and render the view...
var parameters = {model: model, options: options};
view = new ViewType(parameters);
view.render();
model.on('destroy', view.remove, view);
return view;
}
return null;
};
WidgetManager.prototype.get_msg_cell = function (msg_id) {
var cell = null;
// First, check to see if the msg was triggered by cell execution.
if (this.notebook) {
cell = this.notebook.get_msg_cell(msg_id);
}
if (cell !== null) {
return cell;
}
// Second, check to see if a get_cell callback was defined
// for the message. get_cell callbacks are registered for
// widget messages, so this block is actually checking to see if the
// message was triggered by a widget.
var kernel = this.comm_manager.kernel;
if (kernel) {
var callbacks = kernel.get_callbacks_for_msg(msg_id);
if (callbacks && callbacks.iopub &&
callbacks.iopub.get_cell !== undefined) {
return callbacks.iopub.get_cell();
}
return callbacks;
};
WidgetManager.prototype.get_model = function (model_id) {
// Look-up a model instance by its id.
var model = this._models[model_id];
if (model !== undefined && model.id == model_id) {
return model;
}
// Not triggered by a cell or widget (no get_cell callback
// exists).
return null;
};
WidgetManager.prototype.callbacks = function (view) {
// callback handlers specific a view
var callbacks = {};
if (view && view.options.cell) {
// Try to get output handlers
var cell = view.options.cell;
var handle_output = null;
var handle_clear_output = null;
if (cell.output_area) {
handle_output = $.proxy(cell.output_area.handle_output, cell.output_area);
handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area);
}
return null;
};
WidgetManager.prototype._handle_comm_open = function (comm, msg) {
// Handle when a comm is opened.
// Create callback dict using what is known
var that = this;
var model_id = comm.comm_id;
var widget_type_name = msg.content.target_name;
var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm);
widget_model.on('comm:close', function () {
delete that._models[model_id];
});
this._models[model_id] = widget_model;
};
IPython.WidgetManager = WidgetManager;
return IPython.WidgetManager;
});
}());
callbacks = {
iopub : {
output : handle_output,
clear_output : handle_clear_output,
// Special function only registered by widget messages.
// Allows us to get the cell for a message so we know
// where to add widgets if the code requires it.
get_cell : function () {
return cell;
},
},
};
}
return callbacks;
};
WidgetManager.prototype.get_model = function (model_id) {
// Look-up a model instance by its id.
var model = this._models[model_id];
if (model !== undefined && model.id == model_id) {
return model;
}
return null;
};
WidgetManager.prototype._handle_comm_open = function (comm, msg) {
// Handle when a comm is opened.
var that = this;
var model_id = comm.comm_id;
var widget_type_name = msg.content.target_name;
var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm);
widget_model.on('comm:close', function () {
delete that._models[model_id];
});
this._models[model_id] = widget_model;
};
// Backwards compatability.
IPython.WidgetManager = WidgetManager;
return {'WidgetManager': WidgetManager};
});

@ -1,23 +1,12 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
//============================================================================
// Base Widget Model and View classes
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define(["widgets/js/manager",
"underscore",
"backbone"],
function(WidgetManager, _, Backbone){
"backbone",
"jquery",
"base/js/namespace",
], function(widgetmanager, _, Backbone, $, IPython){
var WidgetModel = Backbone.Model.extend({
constructor: function (widget_manager, model_id, comm) {
@ -221,20 +210,20 @@ function(WidgetManager, _, Backbone){
_pack_models: function(value) {
// Replace models with model ids recursively.
var that = this;
var packed;
if (value instanceof Backbone.Model) {
return value.id;
} else if ($.isArray(value)) {
var packed = [];
var that = this;
packed = [];
_.each(value, function(sub_value, key) {
packed.push(that._pack_models(sub_value));
});
return packed;
} else if (value instanceof Object) {
var packed = {};
var that = this;
packed = {};
_.each(value, function(sub_value, key) {
packed[key] = that._pack_models(sub_value);
});
@ -247,17 +236,17 @@ function(WidgetManager, _, Backbone){
_unpack_models: function(value) {
// Replace model ids with models recursively.
var that = this;
var unpacked;
if ($.isArray(value)) {
var unpacked = [];
var that = this;
unpacked = [];
_.each(value, function(sub_value, key) {
unpacked.push(that._unpack_models(sub_value));
});
return unpacked;
} else if (value instanceof Object) {
var unpacked = {};
var that = this;
unpacked = {};
_.each(value, function(sub_value, key) {
unpacked[key] = that._unpack_models(sub_value);
});
@ -274,7 +263,7 @@ function(WidgetManager, _, Backbone){
},
});
WidgetManager.register_widget_model('WidgetModel', WidgetModel);
widgetmanager.WidgetManager.register_widget_model('WidgetModel', WidgetModel);
var WidgetView = Backbone.View.extend({
@ -471,10 +460,14 @@ function(WidgetManager, _, Backbone){
},
});
IPython.WidgetModel = WidgetModel;
IPython.WidgetView = WidgetView;
IPython.DOMWidgetView = DOMWidgetView;
var widget = {
'WidgetModel': WidgetModel,
'WidgetView': WidgetView,
'DOMWidgetView': DOMWidgetView,
};
// For backwards compatability.
$.extend(IPython, widget);
// Pass through WidgetManager namespace.
return WidgetManager;
return widget;
});

@ -1,22 +1,13 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// BoolWidget
//============================================================================
define([
"widgets/js/widget",
"jquery",
"components/bootstrap/js/bootstrap.min",
], function(widget, $){
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget"], function(WidgetManager){
var CheckboxView = IPython.DOMWidgetView.extend({
var CheckboxView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.$el
@ -68,10 +59,9 @@ define(["widgets/js/widget"], function(WidgetManager){
},
});
WidgetManager.register_widget_view('CheckboxView', CheckboxView);
var ToggleButtonView = IPython.DOMWidgetView.extend({
var ToggleButtonView = widget.DOMWidgetView.extend({
render : function() {
// Called when view is rendered.
var that = this;
@ -122,5 +112,9 @@ define(["widgets/js/widget"], function(WidgetManager){
this.touch();
},
});
WidgetManager.register_widget_view('ToggleButtonView', ToggleButtonView);
return {
'CheckboxView': CheckboxView,
'ToggleButtonView': ToggleButtonView,
};
});

@ -1,22 +1,13 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// ButtonWidget
//============================================================================
define([
"widgets/js/widget",
"jquery",
"components/bootstrap/js/bootstrap.min",
], function(widget, $){
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget"], function(WidgetManager){
var ButtonView = IPython.DOMWidgetView.extend({
var ButtonView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.setElement($("<button />")
@ -56,5 +47,8 @@ define(["widgets/js/widget"], function(WidgetManager){
this.send({event: 'click'});
},
});
WidgetManager.register_widget_view('ButtonView', ButtonView);
return {
'ButtonView': ButtonView,
};
});

@ -1,22 +1,13 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// ContainerWidget
//============================================================================
define([
"widgets/js/widget",
"jqueryui",
"components/bootstrap/js/bootstrap.min",
], function(widget, $){
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget"], function(WidgetManager) {
var ContainerView = IPython.DOMWidgetView.extend({
var ContainerView = widget.DOMWidgetView.extend({
render: function(){
// Called when view is rendered.
this.$el.addClass('widget-container')
@ -73,9 +64,8 @@ define(["widgets/js/widget"], function(WidgetManager) {
},
});
WidgetManager.register_widget_view('ContainerView', ContainerView);
var PopupView = IPython.DOMWidgetView.extend({
var PopupView = widget.DOMWidgetView.extend({
render: function(){
// Called when view is rendered.
var that = this;
@ -317,5 +307,9 @@ define(["widgets/js/widget"], function(WidgetManager) {
}
},
});
WidgetManager.register_widget_view('PopupView', PopupView);
return {
'ContainerView': ContainerView,
'PopupView': PopupView,
};
});

@ -1,26 +1,12 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
//============================================================================
// FloatWidget
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget",
"widgets/js/widget_int"],
function(WidgetManager, int_widgets){
var IntSliderView = int_widgets[0];
var IntTextView = int_widgets[1];
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
"widgets/js/widget",
"widgets/js/widget_int",
], function(widget, int_widgets){
var IntSliderView = int_widgets.IntSliderView;
var IntTextView = int_widgets.IntTextView;
var FloatSliderView = IntSliderView.extend({
_validate_slide_value: function(x) {
@ -29,8 +15,6 @@ define(["widgets/js/widget",
return x;
},
});
WidgetManager.register_widget_view('FloatSliderView', FloatSliderView);
var FloatTextView = IntTextView.extend({
_parse_value: function(value) {
@ -38,5 +22,9 @@ define(["widgets/js/widget",
return parseFloat(value);
},
});
WidgetManager.register_widget_view('FloatTextView', FloatTextView);
return {
'FloatSliderView': FloatSliderView,
'FloatTextView': FloatTextView,
};
});

@ -1,22 +1,12 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// ImageWidget
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget"], function(WidgetManager){
var ImageView = IPython.DOMWidgetView.extend({
define([
"widgets/js/widget",
"jquery",
], function(widget, $){
var ImageView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.setElement($("<img />"));
@ -47,5 +37,8 @@ define(["widgets/js/widget"], function(WidgetManager){
return ImageView.__super__.update.apply(this);
},
});
WidgetManager.register_widget_view('ImageView', ImageView);
return {
'ImageView': ImageView,
};
});

@ -1,22 +1,13 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// IntWidget
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget"], function(WidgetManager){
var IntSliderView = IPython.DOMWidgetView.extend({
define([
"widgets/js/widget",
"jqueryui",
"components/bootstrap/js/bootstrap.min",
], function(widget, $){
var IntSliderView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.$el
@ -152,10 +143,9 @@ define(["widgets/js/widget"], function(WidgetManager){
return ~~x;
},
});
WidgetManager.register_widget_view('IntSliderView', IntSliderView);
var IntTextView = IPython.DOMWidgetView.extend({
var IntTextView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.$el
@ -257,10 +247,9 @@ define(["widgets/js/widget"], function(WidgetManager){
return parseInt(value);
},
});
WidgetManager.register_widget_view('IntTextView', IntTextView);
var ProgressView = IPython.DOMWidgetView.extend({
var ProgressView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.$el
@ -303,10 +292,10 @@ define(["widgets/js/widget"], function(WidgetManager){
return ProgressView.__super__.update.apply(this);
},
});
WidgetManager.register_widget_view('ProgressView', ProgressView);
// Return the slider and text views so they can be inheritted to create the
// float versions.
return [IntSliderView, IntTextView];
return {
'IntSliderView': IntSliderView,
'IntTextView': IntTextView,
'ProgressView': ProgressView,
};
});

@ -1,22 +1,14 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// SelectionWidget
//============================================================================
define([
"widgets/js/widget",
"base/js/utils",
"jquery",
"components/bootstrap/js/bootstrap.min",
], function(widget, utils, $){
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget"], function(WidgetManager){
var DropdownView = IPython.DOMWidgetView.extend({
var DropdownView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.$el
@ -113,10 +105,9 @@ define(["widgets/js/widget"], function(WidgetManager){
},
});
WidgetManager.register_widget_view('DropdownView', DropdownView);
var RadioButtonsView = IPython.DOMWidgetView.extend({
var RadioButtonsView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.$el
@ -204,10 +195,9 @@ define(["widgets/js/widget"], function(WidgetManager){
this.touch();
},
});
WidgetManager.register_widget_view('RadioButtonsView', RadioButtonsView);
var ToggleButtonsView = IPython.DOMWidgetView.extend({
var ToggleButtonsView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.$el
@ -239,7 +229,7 @@ define(["widgets/js/widget"], function(WidgetManager){
if (item.trim().length == 0) {
item_html = "&nbsp;";
} else {
item_html = IPython.utils.escape_html(item);
item_html = utils.escape_html(item);
}
var item_query = '[data-value="' + item + '"]';
var $item_element = that.$buttongroup.find(item_query);
@ -297,10 +287,9 @@ define(["widgets/js/widget"], function(WidgetManager){
this.touch();
},
});
WidgetManager.register_widget_view('ToggleButtonsView', ToggleButtonsView);
var SelectView = IPython.DOMWidgetView.extend({
var SelectView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.$el
@ -381,5 +370,11 @@ define(["widgets/js/widget"], function(WidgetManager){
this.touch();
},
});
WidgetManager.register_widget_view('SelectView', SelectView);
return {
'DropdownView': DropdownView,
'RadioButtonsView': RadioButtonsView,
'ToggleButtonsView': ToggleButtonsView,
'SelectView': SelectView,
};
});

@ -1,25 +1,17 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// SelectionContainerWidget
//============================================================================
define([
"widgets/js/widget",
"base/js/utils",
"jquery",
"components/bootstrap/js/bootstrap.min",
], function(widget, utils, $){
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget"], function(WidgetManager){
var AccordionView = IPython.DOMWidgetView.extend({
var AccordionView = widget.DOMWidgetView.extend({
render: function(){
// Called when view is rendered.
var guid = 'panel-group' + IPython.utils.uuid();
var guid = 'panel-group' + utils.uuid();
this.$el
.attr('id', guid)
.addClass('panel-group');
@ -99,7 +91,7 @@ define(["widgets/js/widget"], function(WidgetManager){
// Called when a child is added to children list.
var view = this.create_child_view(model);
var index = this.containers.length;
var uuid = IPython.utils.uuid();
var uuid = utils.uuid();
var accordion_group = $('<div />')
.addClass('panel panel-default')
.appendTo(this.$el);
@ -141,10 +133,9 @@ define(["widgets/js/widget"], function(WidgetManager){
}
},
});
WidgetManager.register_widget_view('AccordionView', AccordionView);
var TabView = IPython.DOMWidgetView.extend({
var TabView = widget.DOMWidgetView.extend({
initialize: function() {
// Public constructor.
this.containers = [];
@ -153,7 +144,7 @@ define(["widgets/js/widget"], function(WidgetManager){
render: function(){
// Called when view is rendered.
var uuid = 'tabs'+IPython.utils.uuid();
var uuid = 'tabs'+utils.uuid();
var that = this;
this.$tabs = $('<div />', {id: uuid})
.addClass('nav')
@ -201,7 +192,7 @@ define(["widgets/js/widget"], function(WidgetManager){
// Called when a child is added to children list.
var view = this.create_child_view(model);
var index = this.containers.length;
var uuid = IPython.utils.uuid();
var uuid = utils.uuid();
var that = this;
var tab = $('<li />')
@ -268,5 +259,9 @@ define(["widgets/js/widget"], function(WidgetManager){
this.containers[index].tab('show');
},
});
WidgetManager.register_widget_view('TabView', TabView);
return {
'AccordionView': AccordionView,
'TabView': TabView,
};
});

@ -1,22 +1,13 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 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.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// StringWidget
//============================================================================
define([
"widgets/js/widget",
"jquery",
"components/bootstrap/js/bootstrap.min",
], function(widget, $){
/**
* @module IPython
* @namespace IPython
**/
define(["widgets/js/widget"], function(WidgetManager){
var HTMLView = IPython.DOMWidgetView.extend({
var HTMLView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.update(); // Set defaults.
@ -31,10 +22,9 @@ define(["widgets/js/widget"], function(WidgetManager){
return HTMLView.__super__.update.apply(this);
},
});
WidgetManager.register_widget_view('HTMLView', HTMLView);
var LatexView = IPython.DOMWidgetView.extend({
var LatexView = widget.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.update(); // Set defaults.
@ -51,10 +41,9 @@ define(["widgets/js/widget"], function(WidgetManager){
return LatexView.__super__.update.apply(this);
},
});
WidgetManager.register_widget_view('LatexView', LatexView);
var TextareaView = IPython.DOMWidgetView.extend({
var TextareaView = widget.DOMWidgetView.extend({
render: function(){
// Called when view is rendered.
this.$el
@ -136,10 +125,9 @@ define(["widgets/js/widget"], function(WidgetManager){
this.touch();
},
});
WidgetManager.register_widget_view('TextareaView', TextareaView);
var TextView = IPython.DOMWidgetView.extend({
var TextView = widget.DOMWidgetView.extend({
render: function(){
// Called when view is rendered.
this.$el
@ -244,5 +232,11 @@ define(["widgets/js/widget"], function(WidgetManager){
}
},
});
WidgetManager.register_widget_view('TextView', TextView);
return {
'HTMLView': HTMLView,
'LatexView': LatexView,
'TextareaView': TextareaView,
'TextView': TextView,
};
});

@ -46,6 +46,7 @@
{% block script %}
{{super()}}
<script src="{{static_url("auth/js/loginmain.js") }}" type="text/javascript" charset="utf-8"></script>

@ -32,6 +32,7 @@
{% endblock %}
{% block script %}
{{super()}}
<script src="{{static_url("auth/js/logoutmain.js") }}" type="text/javascript" charset="utf-8"></script>

@ -293,10 +293,8 @@ class="notebook_app"
{% block script %}
{{super()}}
<script src="{{ static_url("components/google-caja/html-css-sanitizer-minified.js") }}" charset="utf-8"></script>
<script src="{{ static_url("components/codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
<script type="text/javascript">
CodeMirror.modeURL = "{{ static_url("components/codemirror/mode/%N/%N.js", include_version=False) }}";
@ -317,46 +315,6 @@ class="notebook_app"
<script src="{{ static_url("notebook/js/codemirror-ipython.js") }}" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/codemirror-ipythongfm.js") }}" charset="utf-8"></script>
<script src="{{ static_url("components/highlight.js/build/highlight.pack.js") }}" charset="utf-8"></script>
<script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
<script src="{{ static_url("base/js/events.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("base/js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("base/js/keyboard.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("base/js/security.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("base/js/dialog.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("services/kernels/js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("services/kernels/js/comm.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("services/sessions/js/session.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/layoutmanager.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/mathjaxutils.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/outputarea.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/celltoolbar.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/completer.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/quickhelp.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/pager.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/menubar.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/maintoolbar.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/keyboardmanager.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/notificationwidget.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/notificationarea.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/tooltip.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/tour.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/config.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/contexthint.js") }}" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/celltoolbarpresets/default.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/celltoolbarpresets/rawcell.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/celltoolbarpresets/slideshow.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("notebook/js/main.js") }}" charset="utf-8"></script>
{% endblock %}

@ -20,8 +20,12 @@
baseUrl: '{{static_url("", include_version=False)}}',
paths: {
nbextensions : '{{ base_url }}nbextensions',
underscore : '{{static_url("components/underscore/underscore-min.js")}}',
backbone : '{{static_url("components/backbone/backbone-min.js")}}',
underscore : 'components/underscore/underscore-min',
backbone : 'components/backbone/backbone-min',
jquery: 'components/jquery/jquery.min',
bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min',
dateformat: 'dateformat/date.format',
jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min',
},
shim: {
underscore: {
@ -30,6 +34,16 @@
backbone: {
deps: ["underscore", "jquery"],
exports: "Backbone"
},
bootstraptour: {
exports: "Tour"
},
dateformat: {
exports: "dateFormat"
},
jqueryui: {
deps: ["jquery"],
exports: "$"
}
}
});
@ -75,14 +89,8 @@
{% endblock %}
</div>
<script src="{{static_url("components/jquery/jquery.min.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("components/jquery-ui/ui/minified/jquery-ui.min.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("components/bootstrap/js/bootstrap.min.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("base/js/namespace.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("base/js/page.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("auth/js/loginwidget.js") }}" type="text/javascript" charset="utf-8"></script>
{% block script %}
<script src="{{static_url("base/js/pagemain.js") }}" type="text/javascript" charset="utf-8"></script>
{% endblock %}
<script src="{{static_url("custom/custom.js") }}" type="text/javascript" charset="utf-8"></script>

@ -111,11 +111,6 @@ data-notebook-path="{{notebook_path}}"
{% block script %}
{{super()}}
<script src="{{ static_url("base/js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("base/js/dialog.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("tree/js/sessionlist.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("tree/js/notebooklist.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("tree/js/kernellist.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("tree/js/clusterlist.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("tree/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("tree/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
{% endblock %}

@ -11,10 +11,10 @@ casper.notebook_test(function () {
this.evaluate(function (nbname) {
IPython.notebook.notebook_name = nbname;
IPython._save_success = IPython._save_failed = false;
$([IPython.events]).on('notebook_saved.Notebook', function () {
IPython.events.on('notebook_saved.Notebook', function () {
IPython._save_success = true;
});
$([IPython.events]).on('notebook_save_failed.Notebook',
IPython.events.on('notebook_save_failed.Notebook',
function (event, xhr, status, error) {
IPython._save_failed = "save failed with " + xhr.status + xhr.responseText;
});
@ -41,7 +41,7 @@ casper.notebook_test(function () {
});
this.thenEvaluate(function(){
$([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
IPython.events.on('checkpoint_created.Notebook', function (evt, data) {
IPython._checkpoint_created = true;
});
IPython._checkpoint_created = false;

@ -12,6 +12,7 @@ casper.open_new_notebook = function () {
// Create and open a new notebook.
var baseUrl = this.get_notebook_server();
this.start(baseUrl);
this.waitFor(this.page_loaded);
this.thenClick('button#new_notebook');
this.waitForPopup('');
@ -19,15 +20,16 @@ casper.open_new_notebook = function () {
this.then(function () {
this.open(this.popups[0].url);
});
this.waitFor(this.page_loaded);
// Make sure the kernel has started
this.waitFor( this.kernel_running );
this.waitFor(this.kernel_running);
// track the IPython busy/idle state
this.thenEvaluate(function () {
$([IPython.events]).on('status_idle.Kernel',function () {
IPython.events.on('status_idle.Kernel',function () {
IPython._status = 'idle';
});
$([IPython.events]).on('status_busy.Kernel',function () {
IPython.events.on('status_busy.Kernel',function () {
IPython._status = 'busy';
});
});
@ -42,9 +44,18 @@ casper.open_new_notebook = function () {
});
};
casper.kernel_running = function kernel_running() {
casper.page_loaded = function() {
// Return whether or not the kernel is running.
return this.evaluate(function kernel_running() {
return this.evaluate(function() {
return IPython !== undefined &&
IPython.page !== undefined &&
IPython.events !== undefined;
});
};
casper.kernel_running = function() {
// Return whether or not the kernel is running.
return this.evaluate(function() {
return IPython.notebook.kernel.running;
});
};
@ -503,6 +514,7 @@ casper.open_dashboard = function () {
// Start casper by opening the dashboard page.
var baseUrl = this.get_notebook_server();
this.start(baseUrl);
this.waitFor(this.page_loaded);
this.wait_for_dashboard();
};

Loading…
Cancel
Save