mirror of
https://github.com/jupyter/notebook.git
synced 2025-04-24 14:20:54 +08:00
MWE,
Fixed LOTS of bugs
This commit is contained in:
parent
0da779d101
commit
0e9e1dd5a3
@ -4,7 +4,7 @@
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'base/js/utils',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
], function(IPython, utils, $){
|
||||
"use strict";
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
], function(IPython, $) {
|
||||
"use strict";
|
||||
|
||||
@ -146,7 +146,7 @@ define([
|
||||
modal.on('shown.bs.modal', function(){ editor.refresh(); });
|
||||
};
|
||||
|
||||
Dialog = {
|
||||
var Dialog = {
|
||||
modal : modal,
|
||||
edit_metadata : edit_metadata,
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
], function(IPython, $, utils) {
|
||||
"use strict";
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'components/jquery-ui/ui/minified/jquery-ui.min',
|
||||
'components/bootstrap/js/bootstrap.min',
|
||||
'auth/js/loginwidget'
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'components/google-caja/html-css-sanitizer-minified',
|
||||
], function(IPython, $) {
|
||||
"use strict";
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
], function(IPython, $){
|
||||
"use strict";
|
||||
|
||||
|
@ -3,35 +3,15 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'components/codemirror/lib/codemirror.js',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
|
||||
// Set codemirror version.
|
||||
// CodeMirror.modeURL = '{{ static_url("components/codemirror/mode/%N/%N.js", include_version=False) }}';
|
||||
'components/codemirror/addon/mode/loadmode.js',
|
||||
'components/codemirror/addon/mode/multiplex.js',
|
||||
'components/codemirror/addon/mode/overlay.js',
|
||||
'components/codemirror/addon/edit/matchbrackets.js',
|
||||
'components/codemirror/addon/edit/closebrackets.js',
|
||||
'components/codemirror/addon/comment/comment.js',
|
||||
'components/codemirror/mode/htmlmixed/htmlmixed.js',
|
||||
'components/codemirror/mode/xml/xml.js',
|
||||
'components/codemirror/mode/javascript/javascript.js',
|
||||
'components/codemirror/mode/css/css.js',
|
||||
'components/codemirror/mode/rst/rst.js',
|
||||
'components/codemirror/mode/markdown/markdown.js',
|
||||
'components/codemirror/mode/python/python.js',
|
||||
'notebook/js/codemirror-ipython.js',
|
||||
'notebook/js/codemirror-ipythongfm.js',
|
||||
], function(IPython, $, CodeMirror, utils) {
|
||||
], function(IPython, $, utils) {
|
||||
"use strict";
|
||||
|
||||
// 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;}};
|
||||
};
|
||||
@ -58,8 +38,9 @@ define([
|
||||
* @param {object|undefined} [options]
|
||||
* @param [options.cm_config] {object} config to pass to CodeMirror, will extend default parameters
|
||||
*/
|
||||
var Cell = function (keyboard_manager) {
|
||||
var Cell = function (options, keyboard_manager, events) {
|
||||
this.keyboard_manager = keyboard_manager;
|
||||
this.events = events;
|
||||
options = this.mergeopt(Cell, options);
|
||||
// superclass default overwrite our default
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'notebook/js/textcell',
|
||||
], function(IPython, $, TextCell) {
|
||||
"use strict";
|
||||
@ -220,7 +220,9 @@ define([
|
||||
CellToolbar.rebuild_all();
|
||||
}
|
||||
|
||||
this.events.trigger('preset_activated.CellToolbar', {name: preset_name});
|
||||
if (this.events) {
|
||||
this.events.trigger('preset_activated.CellToolbar', {name: preset_name});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -3,14 +3,15 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'notebook/js/tooltip',
|
||||
'base/js/keyboard',
|
||||
'notebook/js/cell',
|
||||
'notebook/js/outputarea',
|
||||
'notebook/js/completer',
|
||||
], function(IPython, $, utils, Tooltip, keyboard, Cell, OutputArea, Completer) {
|
||||
'notebook/js/celltoolbar',
|
||||
], function(IPython, $, utils, Tooltip, keyboard, Cell, OutputArea, Completer, CellToolbar) {
|
||||
"use strict";
|
||||
|
||||
/* local util for codemirror */
|
||||
@ -52,8 +53,9 @@ define([
|
||||
* @param {object|undefined} [options]
|
||||
* @param [options.cm_config] {object} config to pass to CodeMirror
|
||||
*/
|
||||
var CodeCell = function (kernel, options, events, config, keyboard_manager) {
|
||||
var CodeCell = function (kernel, options, events, config, keyboard_manager, notebook) {
|
||||
this.kernel = kernel || null;
|
||||
this.notebook = notebook;
|
||||
this.collapsed = false;
|
||||
this.tooltip = new Tooltip(events);
|
||||
this.events = events;
|
||||
@ -74,7 +76,7 @@ define([
|
||||
|
||||
options = this.mergeopt(CodeCell, options, {cm_config:cm_overwrite_options});
|
||||
|
||||
Cell.apply(this,[options, keyboard_manager]);
|
||||
Cell.apply(this,[options, keyboard_manager, events]);
|
||||
|
||||
// Attributes we want to override in this subclass.
|
||||
this.cell_type = "code";
|
||||
@ -123,7 +125,7 @@ define([
|
||||
var input = $('<div></div>').addClass('input');
|
||||
var prompt = $('<div/>').addClass('prompt input_prompt');
|
||||
var inner_cell = $('<div/>').addClass('inner_cell');
|
||||
this.celltoolbar = new CellToolbar(this);
|
||||
this.celltoolbar = new CellToolbar(this, this.events, 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);
|
||||
|
@ -3,9 +3,10 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/keyboard',
|
||||
'notebook/js/contexthint',
|
||||
], function(IPython, $, utils, keyboard) {
|
||||
"use strict";
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
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 CodeMirror.contextHint;
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/keyboard',
|
||||
], function(IPython, $, utils, keyboard) {
|
||||
@ -15,24 +15,24 @@ define([
|
||||
// Main keyboard manager for the notebook
|
||||
var keycodes = keyboard.keycodes;
|
||||
|
||||
var KeyboardManager = function (pager) {
|
||||
var KeyboardManager = function (pager, events) {
|
||||
this.mode = 'command';
|
||||
this.enabled = true;
|
||||
this.pager = pager;
|
||||
this.quick_help = undefined;
|
||||
this.notebook = undefined;
|
||||
this.bind_events();
|
||||
this.command_shortcuts = new keyboard.ShortcutManager();
|
||||
this.command_shortcuts = new keyboard.ShortcutManager(undefined, 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();
|
||||
this.edit_shortcuts = new keyboard.ShortcutManager(undefined, events);
|
||||
this.edit_shortcuts.add_shortcuts(this.get_default_common_shortcuts());
|
||||
this.edit_shortcuts.add_shortcuts(this.get_default_edit_shortcuts());
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.get_default_common_shortcuts = function() {
|
||||
var that = this;
|
||||
shortcuts = {
|
||||
var shortcuts = {
|
||||
'shift' : {
|
||||
help : '',
|
||||
help_index : '',
|
||||
|
@ -4,7 +4,7 @@
|
||||
var ipython = ipython || {};
|
||||
require([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'notebook/js/notebook',
|
||||
'base/js/utils',
|
||||
'base/js/page',
|
||||
@ -18,6 +18,7 @@ require([
|
||||
'notebook/js/notificationarea',
|
||||
'notebook/js/savewidget',
|
||||
'notebook/js/keyboardmanager',
|
||||
'notebook/js/config',
|
||||
], function(
|
||||
IPython,
|
||||
$,
|
||||
@ -33,32 +34,33 @@ require([
|
||||
MenuBar,
|
||||
NotificationArea,
|
||||
SaveWidget,
|
||||
KeyboardManager
|
||||
KeyboardManager,
|
||||
config
|
||||
) {
|
||||
"use strict";
|
||||
|
||||
$('#ipython-main-app').addClass('border-box-sizing');
|
||||
$('div#notebook_panel').addClass('border-box-sizing');
|
||||
|
||||
var opts = {
|
||||
var options = {
|
||||
base_url : utils.get_body_data("baseUrl"),
|
||||
notebook_path : utils.get_body_data("notebookPath"),
|
||||
notebook_name : utils.get_body_data('notebookName')
|
||||
};
|
||||
|
||||
page = new Page();
|
||||
layout_manager = new LayoutManager();
|
||||
events = $([new Events()]);
|
||||
pager = new Pager('div#pager', 'div#pager_splitter', layout_manager, events);
|
||||
keyboard_manager = new KeyboardManager(pager);
|
||||
save_widget = new SaveWidget('span#save_widget', events, keyboard);
|
||||
notebook = new Notebook('div#notebook', opts, events, keyboard_manager, save_widget, keyboard);
|
||||
login_widget = new LoginWidget('span#login_widget', opts);
|
||||
toolbar = new MainToolBar('#maintoolbar-container', notebook, events);
|
||||
quick_help = new QuickHelp(undefined, keyboard_manager, events);
|
||||
menubar = new MenuBar('#menubar', opts, notebook, layout_manager, events, save_widget, quick_help);
|
||||
|
||||
notification_area = new NotificationArea('#notification_area', events, save_widget, notebook);
|
||||
var user_config = $.extend({}, config.default_config);
|
||||
var page = new Page();
|
||||
var layout_manager = new LayoutManager();
|
||||
var events = $([new Events()]);
|
||||
var pager = new Pager('div#pager', 'div#pager_splitter', layout_manager, events);
|
||||
var keyboard_manager = new KeyboardManager(pager, events);
|
||||
var save_widget = new SaveWidget('span#save_widget', events);
|
||||
var notebook = new Notebook('div#notebook', options, events, keyboard_manager, save_widget, user_config);
|
||||
var login_widget = new LoginWidget('span#login_widget', options);
|
||||
var toolbar = new MainToolBar('#maintoolbar-container', layout_manager, notebook, events);
|
||||
var quick_help = new QuickHelp(undefined, keyboard_manager, events);
|
||||
var menubar = new MenuBar('#menubar', options, notebook, layout_manager, events, save_widget, quick_help);
|
||||
var notification_area = new NotificationArea('#notification_area', events, save_widget, notebook);
|
||||
notification_area.init_notification_widgets();
|
||||
|
||||
layout_manager.do_resize();
|
||||
@ -91,7 +93,7 @@ require([
|
||||
|
||||
events.on('notebook_loaded.Notebook', first_load);
|
||||
events.trigger('app_initialized.NotebookApp');
|
||||
notebook.load_notebook(opts.notebook_name, opts.notebook_path);
|
||||
notebook.load_notebook(options.notebook_name, options.notebook_path);
|
||||
|
||||
ipython.page = page;
|
||||
ipython.layout_manager = layout_manager;
|
||||
@ -105,5 +107,5 @@ require([
|
||||
ipython.events = events;
|
||||
ipython.keyboard_manager = keyboard_manager;
|
||||
ipython.save_widget = save_widget;
|
||||
ipython.keyboard = keyboard;
|
||||
ipython.config = user_config;
|
||||
});
|
||||
|
@ -3,14 +3,14 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'notebook/js/toolbar',
|
||||
'notebook/js/celltoolbar',
|
||||
], function(IPython, $, Toolbar, CellToolbar) {
|
||||
"use strict";
|
||||
|
||||
var MainToolBar = function (selector, layout_manager, notebook, events) {
|
||||
ToolBar.apply(this, arguments);
|
||||
Toolbar.apply(this, arguments);
|
||||
this.events = events;
|
||||
this.notebook = notebook;
|
||||
this.construct();
|
||||
@ -19,7 +19,7 @@ define([
|
||||
this.bind_events();
|
||||
};
|
||||
|
||||
MainToolBar.prototype = new ToolBar();
|
||||
MainToolBar.prototype = new Toolbar();
|
||||
|
||||
MainToolBar.prototype.construct = function () {
|
||||
this.add_buttons_group([
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
define([
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/dialog',
|
||||
], function($, utils, Dialog) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'notebook/js/tour',
|
||||
'components/bootstrap-tour/build/js/bootstrap-tour.min',
|
||||
@ -49,12 +49,13 @@ define([
|
||||
};
|
||||
|
||||
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 = this.notebook.get_selected_index();
|
||||
this.notebook.select(i);
|
||||
var i = that.notebook.get_selected_index();
|
||||
that.notebook.select(i);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/dialog',
|
||||
'notebook/js/textcell',
|
||||
@ -38,8 +38,8 @@ define([
|
||||
* @param {Object} [options] A config object
|
||||
* @param {Object} [events] An events object
|
||||
*/
|
||||
var Notebook = function (selector, options, events, keyboard_manager, save_widget) {
|
||||
this.config = undefined; // TODO
|
||||
var Notebook = function (selector, options, events, keyboard_manager, save_widget, config) {
|
||||
this.config = config;
|
||||
this.events = events;
|
||||
this.keyboard_manager = keyboard_manager;
|
||||
keyboard_manager.notebook = this;
|
||||
@ -807,14 +807,14 @@ define([
|
||||
|
||||
if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
|
||||
if (type === 'code') {
|
||||
cell = new CodeCell(this.kernel, undefined, this.events, this.config, this.keyboard_manager);
|
||||
cell = new CodeCell(this.kernel, this.options, this.events, this.config, this.keyboard_manager, this);
|
||||
cell.set_input_prompt();
|
||||
} else if (type === 'markdown') {
|
||||
cell = new Cells.MarkdownCell();
|
||||
cell = new Cells.MarkdownCell(this.options, this.events, this.config, this.keyboard_manager, this);
|
||||
} else if (type === 'raw') {
|
||||
cell = new Cells.RawCell();
|
||||
cell = new Cells.RawCell(this.options, this.events, this.config, this.keyboard_manager, this);
|
||||
} else if (type === 'heading') {
|
||||
cell = new Cells.HeadingCell();
|
||||
cell = new Cells.HeadingCell(this.options, this.events, this.config, this.keyboard_manager, this);
|
||||
}
|
||||
|
||||
if(this._insert_element_at_index(cell.element,index)) {
|
||||
|
@ -3,10 +3,11 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/dialog',
|
||||
], function(IPython, $, utils, Dialog) {
|
||||
'notebook/js/notificationwidget',
|
||||
], function(IPython, $, utils, Dialog, NotificationWidget) {
|
||||
"use strict";
|
||||
|
||||
var NotificationArea = function (selector, events, save_widget, notebook) {
|
||||
@ -61,7 +62,7 @@ define([
|
||||
}
|
||||
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('#notification_'+name);
|
||||
return this.widget_dict[name];
|
||||
};
|
||||
|
||||
@ -228,5 +229,5 @@ define([
|
||||
|
||||
IPython.NotificationArea = NotificationArea;
|
||||
|
||||
return IPython;
|
||||
return 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');
|
||||
@ -44,7 +36,7 @@ var IPython = (function (IPython) {
|
||||
// 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 || {};
|
||||
opts = opts || {};
|
||||
var callback = click_callback || function() {return false;};
|
||||
var that = this;
|
||||
this.inner.attr('class', opts.icon);
|
||||
@ -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;
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/security',
|
||||
'base/js/keyboard',
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
], function(IPython, $, utils) {
|
||||
"use strict";
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/dialog',
|
||||
], function(IPython, $, utils, Dialog) {
|
||||
|
@ -3,10 +3,11 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/dialog',
|
||||
'base/js/keyboard',
|
||||
'dateformat/date.format',
|
||||
], function(IPython, $, utils, Dialog, keyboard) {
|
||||
"use strict";
|
||||
|
||||
|
@ -3,10 +3,12 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'notebook/js/cell',
|
||||
'base/js/security',
|
||||
], function(IPython, $, Cell, Security) {
|
||||
'notebook/js/mathjaxutils',
|
||||
'notebook/js/celltoolbar',
|
||||
], function(IPython, $, Cell, Security, mathjaxutils, CellToolbar) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
@ -20,13 +22,15 @@ define([
|
||||
* @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, events, config, mathjaxutils) {
|
||||
// TODO: Config is IPython.config
|
||||
var TextCell = function (options, events, config, keyboard_manager, notebook) {
|
||||
// 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 = notebook;
|
||||
this.events = events;
|
||||
this.config = 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)
|
||||
@ -35,9 +39,9 @@ define([
|
||||
options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options});
|
||||
|
||||
this.cell_type = this.cell_type || 'text';
|
||||
this.mathjaxutils = mathjaxutils;
|
||||
mathjaxutils = mathjaxutils;
|
||||
|
||||
Cell.apply(this, [options], events);
|
||||
Cell.apply(this, [options, keyboard_manager, events]);
|
||||
|
||||
this.rendered = false;
|
||||
};
|
||||
@ -67,7 +71,7 @@ define([
|
||||
var prompt = $('<div/>').addClass('prompt input_prompt');
|
||||
cell.append(prompt);
|
||||
var inner_cell = $('<div/>').addClass('inner_cell');
|
||||
this.celltoolbar = new CellToolbar(this);
|
||||
this.celltoolbar = new CellToolbar(this, this.events, 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);
|
||||
@ -158,7 +162,6 @@ define([
|
||||
/**
|
||||
* 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();
|
||||
@ -213,11 +216,11 @@ define([
|
||||
* @constructor MarkdownCell
|
||||
* @extends IPython.HTMLCell
|
||||
*/
|
||||
var MarkdownCell = function (options) {
|
||||
var MarkdownCell = function (options, events, config, keyboard_manager) {
|
||||
options = this.mergeopt(MarkdownCell, options);
|
||||
|
||||
this.cell_type = 'markdown';
|
||||
TextCell.apply(this, [options]);
|
||||
TextCell.apply(this, [options, events, config, keyboard_manager]);
|
||||
};
|
||||
|
||||
MarkdownCell.options_default = {
|
||||
@ -238,11 +241,11 @@ define([
|
||||
var text = this.get_text();
|
||||
var math = null;
|
||||
if (text === "") { text = this.placeholder; }
|
||||
var text_and_math = this.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 = this.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
|
||||
@ -263,10 +266,10 @@ define([
|
||||
* @constructor RawCell
|
||||
* @extends TextCell
|
||||
*/
|
||||
var RawCell = function (options) {
|
||||
var RawCell = function (options, events, config, keyboard_manager) {
|
||||
|
||||
options = this.mergeopt(RawCell,options);
|
||||
TextCell.apply(this, [options]);
|
||||
TextCell.apply(this, [options, events, config, keyboard_manager]);
|
||||
this.cell_type = 'raw';
|
||||
// RawCell should always hide its rendered div
|
||||
this.element.find('div.text_cell_render').hide();
|
||||
@ -297,7 +300,7 @@ define([
|
||||
* @method auto_highlight
|
||||
*/
|
||||
RawCell.prototype.auto_highlight = function () {
|
||||
this._auto_highlight(config.raw_cell_highlight);
|
||||
this._auto_highlight(this.config.raw_cell_highlight);
|
||||
};
|
||||
|
||||
/** @method render **/
|
||||
@ -322,12 +325,12 @@ define([
|
||||
* @constructor HeadingCell
|
||||
* @extends TextCell
|
||||
*/
|
||||
var HeadingCell = function (options) {
|
||||
var HeadingCell = function (options, events, config, keyboard_manager) {
|
||||
options = this.mergeopt(HeadingCell, options);
|
||||
|
||||
this.level = 1;
|
||||
this.cell_type = 'heading';
|
||||
TextCell.apply(this, [options]);
|
||||
TextCell.apply(this, [options, events, config, keyboard_manager]);
|
||||
|
||||
/**
|
||||
* heading level of the cell, use getter and setter to access
|
||||
@ -409,11 +412,11 @@ define([
|
||||
text = text.replace(/\n/g, ' ');
|
||||
if (text === "") { text = this.placeholder; }
|
||||
text = new Array(this.level + 1).join("#") + " " + text;
|
||||
var text_and_math = this.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 = this.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
|
||||
@ -439,7 +442,7 @@ define([
|
||||
IPython.RawCell = RawCell;
|
||||
IPython.HeadingCell = HeadingCell;
|
||||
|
||||
Cells = {
|
||||
var Cells = {
|
||||
'TextCell': TextCell,
|
||||
'MarkdownCell': MarkdownCell,
|
||||
'RawCell': RawCell,
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
], function(IPython, $) {
|
||||
"use strict";
|
||||
|
||||
@ -97,5 +97,5 @@ define([
|
||||
// Backwards compatability.
|
||||
IPython.ToolBar = ToolBar;
|
||||
|
||||
return Toolbar;
|
||||
return ToolBar;
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
], function(IPython, $, utils) {
|
||||
"use strict";
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
], function(IPython, $) {
|
||||
"use strict";
|
||||
|
||||
@ -129,8 +129,8 @@ define([
|
||||
// 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
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
], function(IPython, $, utils) {
|
||||
"use strict";
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'services/kernels/js/comm',
|
||||
'widgets/js/init',
|
||||
@ -15,8 +15,8 @@ define([
|
||||
* A Kernel Class to communicate with the Python kernel
|
||||
* @Class Kernel
|
||||
*/
|
||||
var Kernel = function (kernel_service_url, events) {
|
||||
this.events = events;
|
||||
var Kernel = function (kernel_service_url, notebook) {
|
||||
this.events = notebook.events;
|
||||
this.kernel_id = null;
|
||||
this.shell_channel = null;
|
||||
this.iopub_channel = null;
|
||||
@ -39,7 +39,7 @@ define([
|
||||
this.bind_events();
|
||||
this.init_iopub_handlers();
|
||||
this.comm_manager = new comm.CommManager(this);
|
||||
this.widget_manager = new WidgetManager(this.comm_manager);
|
||||
this.widget_manager = new WidgetManager(this.comm_manager, notebook);
|
||||
|
||||
this.last_msg_id = null;
|
||||
this.last_msg_callbacks = {};
|
||||
@ -605,8 +605,8 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Backwards compatability.
|
||||
IPython.Kernel = Kernel;
|
||||
|
||||
return IPython;
|
||||
return Kernel;
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'services/kernels/js/kernel',
|
||||
], function(IPython, $, utils, Kernel) {
|
||||
@ -87,7 +87,7 @@ define([
|
||||
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 Kernel(kernel_service_url, notebook.events);
|
||||
this.kernel = new Kernel(kernel_service_url, this.notebook);
|
||||
this.kernel._kernel_started(data.kernel);
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
], function(IPython, $, utils) {
|
||||
"use strict";
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'tree/js/notebooklist',
|
||||
], function(IPython, $, NotebookList) {
|
||||
"use strict";
|
||||
|
@ -4,7 +4,7 @@
|
||||
var ipython = ipython || {};
|
||||
require([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/events',
|
||||
'base/js/page',
|
||||
'base/js/utils',
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/dialog',
|
||||
], function(IPython, $, utils, Dialog) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'components/jquery/jquery.min',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
], function(IPython, $, utils) {
|
||||
"use strict";
|
||||
|
@ -9,12 +9,12 @@ define([
|
||||
//--------------------------------------------------------------------
|
||||
// WidgetManager class
|
||||
//--------------------------------------------------------------------
|
||||
var WidgetManager = function (comm_manager, keyboard_manager, notebook) {
|
||||
var WidgetManager = function (comm_manager, notebook) {
|
||||
// Public constructor
|
||||
WidgetManager._managers.push(this);
|
||||
|
||||
// Attach a comm manager to the
|
||||
this.keyboard_manager = keyboard_manager;
|
||||
this.keyboard_manager = notebook.keyboard_manager;
|
||||
this.notebook = notebook;
|
||||
this.comm_manager = comm_manager;
|
||||
this._models = {}; /* Dictionary of model ids and model instances */
|
||||
|
@ -294,6 +294,26 @@ class="notebook_app"
|
||||
|
||||
{% block 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) }}";
|
||||
</script>
|
||||
<script src="{{ static_url("components/codemirror/addon/mode/loadmode.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/addon/mode/multiplex.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/addon/mode/overlay.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/addon/edit/matchbrackets.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/addon/edit/closebrackets.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/addon/comment/comment.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/mode/css/css.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
|
||||
<script src="{{ static_url("components/codemirror/mode/python/python.js") }}" charset="utf-8"></script>
|
||||
<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("notebook/js/main.js") }}" charset="utf-8"></script>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -22,6 +22,7 @@
|
||||
nbextensions : '{{ base_url }}nbextensions',
|
||||
underscore : 'components/underscore/underscore-min',
|
||||
backbone : 'components/backbone/backbone-min',
|
||||
jquery: 'components/jquery/jquery.min',
|
||||
},
|
||||
shim: {
|
||||
underscore: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user