diff --git a/IPython/html/static/auth/js/loginmain.js b/IPython/html/static/auth/js/loginmain.js index d914bf7..b95d70a 100644 --- a/IPython/html/static/auth/js/loginmain.js +++ b/IPython/html/static/auth/js/loginmain.js @@ -1,21 +1,9 @@ -//---------------------------------------------------------------------------- -// 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(); +require(['base/js/namespace', 'base/js/page'], function(IPython, Page) { + IPython.page = new Page(); $('button#login_submit').addClass("btn btn-default"); IPython.page.show(); $('input#password_input').focus(); - }); - diff --git a/IPython/html/static/auth/js/logoutmain.js b/IPython/html/static/auth/js/logoutmain.js index df107c6..aa68082 100644 --- a/IPython/html/static/auth/js/logoutmain.js +++ b/IPython/html/static/auth/js/logoutmain.js @@ -1,20 +1,8 @@ -//---------------------------------------------------------------------------- -// 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(); +require(['base/js/namespace', 'base/js/page'], function(IPython, Page) { + IPython.page = new Page(); $('#ipython-main-app').addClass('border-box-sizing'); IPython.page.show(); - }); - diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index 5a481c5..202d72b 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -1,3 +1,22 @@ +"components/codemirror/lib/codemirror.js", +// 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", + //---------------------------------------------------------------------------- // Copyright (C) 2008-2011 The IPython Development Team // diff --git a/IPython/html/static/notebook/js/layoutmanager.js b/IPython/html/static/notebook/js/layoutmanager.js index 4706be4..5775540 100644 --- a/IPython/html/static/notebook/js/layoutmanager.js +++ b/IPython/html/static/notebook/js/layoutmanager.js @@ -1,19 +1,15 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// Layout -//============================================================================ - -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'components/jquery/jquery.min', +], function(IPython, $) { "use strict"; - var LayoutManager = function () { + var LayoutManager = function (pager) { this.bind_events(); + this.pager = pager; }; LayoutManager.prototype.bind_events = function () { @@ -44,18 +40,18 @@ var IPython = (function (IPython) { $('#ipython-main-app').height(app_height); // content+padding+border height - var pager_height = IPython.pager.percentage_height*app_height; + var pager_height = this.pager.percentage_height*app_height; var pager_splitter_height = $('div#pager_splitter').outerHeight(true); $('div#pager').outerHeight(pager_height); - if (IPython.pager.expanded) { + if (this.pager.expanded) { $('div#notebook').outerHeight(app_height-pager_height-pager_splitter_height); } else { $('div#notebook').outerHeight(app_height-pager_splitter_height); } }; + // Backwards compatability. IPython.LayoutManager = LayoutManager; - return IPython; - -}(IPython)); + return LayoutManager; +}); diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index d84c603..7332a1c 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -1,78 +1,57 @@ -//---------------------------------------------------------------------------- -// 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', + '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', +], function( + IPython, + Notebook, + Utils, + Page, + LayoutManager, + Events, + LoginWidget, + MainToolBar, + Pager, + QuickHelp, + MenuBar, + NotificationArea + ) { "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') + 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(); + page = new Page(); + pager = new Pager('div#pager', 'div#pager_splitter'); + layout_manager = new LayoutManager(pager); + notebook = new Notebook('div#notebook', opts); + login_widget = new LoginWidget('span#login_widget', opts); + toolbar = new MainToolBar('#maintoolbar-container'); + quick_help = new QuickHelp(); + menubar = new MenuBar('#menubar', opts); - IPython.layout_manager.do_resize(); + notification_area = new NotificationArea('#notification_area'); + notification_area.init_notification_widgets(); + + layout_manager.do_resize(); $('body').append('
x'+ 'x'+ @@ -85,43 +64,34 @@ 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(opts.notebook_name, opts.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; - } - }); - } + // Backwards compatability. + 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.notification_area = notification_area; }); diff --git a/IPython/html/static/notebook/js/maintoolbar.js b/IPython/html/static/notebook/js/maintoolbar.js index 01af262..95497e6 100644 --- a/IPython/html/static/notebook/js/maintoolbar.js +++ b/IPython/html/static/notebook/js/maintoolbar.js @@ -1,26 +1,23 @@ -//---------------------------------------------------------------------------- -// 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', + 'components/jquery/jquery.min', + 'notebook/js/toolbar', +], function(IPython, $, Toolbar) { "use strict"; - var MainToolBar = function (selector) { - IPython.ToolBar.apply(this, arguments); + var MainToolBar = function (selector, notebook) { + ToolBar.apply(this, arguments); + this.notebook = notebook; this.construct(); this.add_celltype_list(); this.add_celltoolbar_list(); this.bind_events(); }; - MainToolBar.prototype = new IPython.ToolBar(); + MainToolBar.prototype = new ToolBar(); MainToolBar.prototype.construct = function () { this.add_buttons_group([ @@ -29,7 +26,7 @@ var IPython = (function (IPython) { label : 'Save and Checkpoint', icon : 'icon-save', callback : function () { - IPython.notebook.save_checkpoint(); + this.notebook.save_checkpoint(); } } ]); @@ -40,9 +37,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(); + this.notebook.insert_cell_below('code'); + this.notebook.select_next(); + this.notebook.focus_cell(); } } ],'insert_above_below'); @@ -53,7 +50,7 @@ var IPython = (function (IPython) { label : 'Cut Cell', icon : 'icon-cut', callback : function () { - IPython.notebook.cut_cell(); + this.notebook.cut_cell(); } }, { @@ -61,7 +58,7 @@ var IPython = (function (IPython) { label : 'Copy Cell', icon : 'icon-copy', callback : function () { - IPython.notebook.copy_cell(); + this.notebook.copy_cell(); } }, { @@ -69,7 +66,7 @@ var IPython = (function (IPython) { label : 'Paste Cell Below', icon : 'icon-paste', callback : function () { - IPython.notebook.paste_cell_below(); + this.notebook.paste_cell_below(); } } ],'cut_copy_paste'); @@ -80,7 +77,7 @@ var IPython = (function (IPython) { label : 'Move Cell Up', icon : 'icon-arrow-up', callback : function () { - IPython.notebook.move_cell_up(); + this.notebook.move_cell_up(); } }, { @@ -88,7 +85,7 @@ var IPython = (function (IPython) { label : 'Move Cell Down', icon : 'icon-arrow-down', callback : function () { - IPython.notebook.move_cell_down(); + this.notebook.move_cell_down(); } } ],'move_up_down'); @@ -101,7 +98,7 @@ var IPython = (function (IPython) { icon : 'icon-play', callback : function () { // emulate default shift-enter behavior - IPython.notebook.execute_cell_and_select_below(); + this.notebook.execute_cell_and_select_below(); } }, { @@ -109,7 +106,7 @@ var IPython = (function (IPython) { label : 'Interrupt', icon : 'icon-stop', callback : function () { - IPython.notebook.session.interrupt_kernel(); + this.notebook.session.interrupt_kernel(); } }, { @@ -117,7 +114,7 @@ var IPython = (function (IPython) { label : 'Restart Kernel', icon : 'icon-repeat', callback : function () { - IPython.notebook.restart_kernel(); + this.notebook.restart_kernel(); } } ],'run_int'); @@ -151,14 +148,14 @@ var IPython = (function (IPython) { .append($('').attr('value', '').text('None')); this.element.append(label).append(select); select.change(function() { - var val = $(this).val() - if (val =='') { + var val = $(this).val(); + if (val ==='') { IPython.CellToolbar.global_hide(); - delete IPython.notebook.metadata.celltoolbar; + delete this.notebook.metadata.celltoolbar; } else { IPython.CellToolbar.global_show(); IPython.CellToolbar.activate_preset(val); - IPython.notebook.metadata.celltoolbar = val; + this.notebook.metadata.celltoolbar = val; } }); // Setup the currently registered presets. @@ -186,23 +183,23 @@ var IPython = (function (IPython) { this.element.find('#cell_type').change(function () { var cell_type = $(this).val(); if (cell_type === 'code') { - IPython.notebook.to_code(); + this.notebook.to_code(); } else if (cell_type === 'markdown') { - IPython.notebook.to_markdown(); + this.notebook.to_markdown(); } else if (cell_type === 'raw') { - IPython.notebook.to_raw(); + this.notebook.to_raw(); } else if (cell_type === 'heading1') { - IPython.notebook.to_heading(undefined, 1); + this.notebook.to_heading(undefined, 1); } else if (cell_type === 'heading2') { - IPython.notebook.to_heading(undefined, 2); + this.notebook.to_heading(undefined, 2); } else if (cell_type === 'heading3') { - IPython.notebook.to_heading(undefined, 3); + this.notebook.to_heading(undefined, 3); } else if (cell_type === 'heading4') { - IPython.notebook.to_heading(undefined, 4); + this.notebook.to_heading(undefined, 4); } else if (cell_type === 'heading5') { - IPython.notebook.to_heading(undefined, 5); + this.notebook.to_heading(undefined, 5); } else if (cell_type === 'heading6') { - IPython.notebook.to_heading(undefined, 6); + this.notebook.to_heading(undefined, 6); } }); $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) { @@ -214,8 +211,8 @@ var IPython = (function (IPython) { }); }; + // Backwards compatability. IPython.MainToolBar = MainToolBar; - return IPython; - -}(IPython)); + return MainToolBar; +}); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index c5b1dc3..2433252 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1,18 +1,135 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// Notebook -//============================================================================ - -var IPython = (function (IPython) { - "use strict"; - - var utils = IPython.utils; +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + + +"components/google-caja/html-css-sanitizer-minified", + +"components/highlight.js/build/highlight.pack", +"dateformat/date.format", +"base/js/security", +"services/kernels/js/kernel", +"services/kernels/js/comm", +"notebook/js/mathjaxutils", +"notebook/js/outputarea", +"notebook/js/cell", +"notebook/js/codecell", +"notebook/js/completer", +"notebook/js/notificationwidget", +"notebook/js/notificationarea", +"notebook/js/tooltip", +"notebook/js/config", +"notebook/js/main", +"notebook/js/contexthint", +"notebook/js/celltoolbarpresets/default", +"notebook/js/celltoolbarpresets/rawcell", +"notebook/js/celltoolbarpresets/slideshow" + +IPython.mathjaxutils.init(); + +'components/marked/lib/marked', +'widgets/js/init', +'components/bootstrap-tour/build/js/bootstrap-tour.min' + +window.marked = marked; + +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; + } + }); +} + +// 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 + + +"notebook/js/tour", + Tour, + + try { + tour = new Tour(); + } catch (e) { + tour = undefined; + console.log("Failed to instantiate Notebook Tour", e); + } + + IPython.tour = tour; + +"notebook/js/tooltip", + Tooltip, + tooltip = new Tooltip(); + IPython.tooltip = tooltip; + + +define([ + "base/js/namespace", + "components/jquery/jquery.min", + "base/js/utils", + "notebook/js/keyboardmanager", + "notebook/js/savewidget", + "base/js/events", + "base/js/dialog", + "notebook/js/textcell", + "notebook/js/codecell", + "services/sessions/js/session", + "notebook/js/celltoolbar", + "base/js/keyboard", + "components/jquery-ui/ui/minified/jquery-ui.min", + "components/bootstrap/js/bootstrap.min", +], function ( + IPython, + $, + Utils, + KeyboardManager, + SaveWidget, + Events, + Dialog, + Cells, + CodeCell, + Session, + CellToolbar, + Keyboard + ) { + + keyboard_manager = new KeyboardManager(); + save_widget = new SaveWidget('span#save_widget'); + keyboard = new Keyboard(); + + // Backwards compatability. + IPython.keyboard_manager = keyboard_manager; + IPython.save_widget = save_widget; + IPython.keyboard = keyboard; /** * A notebook contains and manages cells. @@ -102,36 +219,36 @@ var IPython = (function (IPython) { Notebook.prototype.bind_events = function () { var that = this; - $([IPython.events]).on('set_next_input.Notebook', function (event, data) { + $([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) { + $([Events]).on('set_dirty.Notebook', function (event, data) { that.dirty = data.value; }); - $([IPython.events]).on('trust_changed.Notebook', function (event, data) { + $([Events]).on('trust_changed.Notebook', function (event, data) { that.trusted = data.value; }); - $([IPython.events]).on('select.Cell', function (event, data) { + $([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) { + $([Events]).on('edit_mode.Cell', function (event, data) { that.handle_edit_mode(data.cell); }); - $([IPython.events]).on('command_mode.Cell', function (event, data) { + $([Events]).on('command_mode.Cell', function (event, data) { that.handle_command_mode(data.cell); }); - $([IPython.events]).on('status_autorestarting.Kernel', function () { - IPython.dialog.modal({ + $([Events]).on('status_autorestarting.Kernel', function () { + Dialog.modal({ title: "Kernel Restarting", body: "The kernel appears to have died. It will restart automatically.", buttons: { @@ -211,7 +328,7 @@ var IPython = (function (IPython) { if (this.dirty == value) { return; } - $([IPython.events]).trigger('set_dirty.Notebook', {value: value}); + $([Events]).trigger('set_dirty.Notebook', {value: value}); }; /** @@ -254,7 +371,7 @@ var IPython = (function (IPython) { Notebook.prototype.edit_metadata = function () { var that = this; - IPython.dialog.edit_metadata(this.metadata, function (md) { + Dialog.edit_metadata(this.metadata, function (md) { that.metadata = md; }, 'Notebook'); }; @@ -295,7 +412,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.msg_cells[msg_id] || null; }; /** @@ -474,11 +591,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', + $([Events]).trigger('selected_cell_type_changed.Notebook', {'cell_type':cell.cell_type,level:cell.level} ); } else { - $([IPython.events]).trigger('selected_cell_type_changed.Notebook', + $([Events]).trigger('selected_cell_type_changed.Notebook', {'cell_type':cell.cell_type} ); } @@ -540,8 +657,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(); + $([Events]).trigger('command_mode.Notebook'); + keyboard_manager.command_mode(); } }; @@ -570,8 +687,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(); + $([Events]).trigger('edit_mode.Notebook'); + keyboard_manager.edit_mode(); } }; @@ -686,7 +803,7 @@ var IPython = (function (IPython) { this.undelete_index = i; this.undelete_below = false; } - $([IPython.events]).trigger('delete.Cell', {'cell': cell, 'index': i}); + $([Events]).trigger('delete.Cell', {'cell': cell, 'index': i}); this.set_dirty(true); } return this; @@ -754,19 +871,19 @@ var IPython = (function (IPython) { if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { if (type === 'code') { - cell = new IPython.CodeCell(this.kernel); + cell = new CodeCell(this.kernel); cell.set_input_prompt(); } else if (type === 'markdown') { - cell = new IPython.MarkdownCell(); + cell = new Cells.MarkdownCell(); } else if (type === 'raw') { - cell = new IPython.RawCell(); + cell = new Cells.RawCell(); } else if (type === 'heading') { - cell = new IPython.HeadingCell(); + cell = new Cells.HeadingCell(); } if(this._insert_element_at_index(cell.element,index)) { cell.render(); - $([IPython.events]).trigger('create.Cell', {'cell': cell, 'index': index}); + $([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 +993,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)) { var target_cell = this.insert_cell_below('code',i); var text = source_cell.get_text(); if (text === source_cell.placeholder) { @@ -906,7 +1023,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 Cells.MarkdownCell)) { var target_cell = this.insert_cell_below('markdown',i); var text = source_cell.get_text(); if (text === source_cell.placeholder) { @@ -920,7 +1037,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 Cells.TextCell) && source_cell.rendered) { target_cell.render(); } var cursor = source_cell.code_mirror.getCursor(); @@ -942,7 +1059,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 Cells.RawCell)) { target_cell = this.insert_cell_below('raw',i); var text = source_cell.get_text(); if (text === source_cell.placeholder) { @@ -977,7 +1094,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 Cells.HeadingCell) { source_cell.set_level(level); } else { target_cell = this.insert_cell_below('heading',i); @@ -996,12 +1113,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 Cells.TextCell) && source_cell.rendered) { target_cell.render(); } } this.set_dirty(true); - $([IPython.events]).trigger('selected_cell_type_changed.Notebook', + $([Events]).trigger('selected_cell_type_changed.Notebook', {'cell_type':'heading',level:level} ); } @@ -1115,13 +1232,13 @@ var IPython = (function (IPython) { * @method split_cell */ Notebook.prototype.split_cell = function () { - var mdc = IPython.MarkdownCell; - var rc = IPython.RawCell; + var mdc = Cells.MarkdownCell; + var rc = Cells.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) { // 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 +1261,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 = Cells.MarkdownCell; + var rc = Cells.RawCell; var index = this.get_selected_index(); var cell = this.get_cell(index); var render = cell.rendered; @@ -1159,7 +1276,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) { 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 +1298,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 = Cells.MarkdownCell; + var rc = Cells.RawCell; var index = this.get_selected_index(); var cell = this.get_cell(index); var render = cell.rendered; @@ -1196,7 +1313,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) { 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 +1341,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)) { cell.collapse_output(); this.set_dirty(true); } @@ -1237,7 +1354,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) { cell.collapse_output(); } }); @@ -1254,7 +1371,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)) { cell.expand_output(); this.set_dirty(true); } @@ -1267,7 +1384,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) { cell.expand_output(); } }); @@ -1284,7 +1401,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)) { cell.clear_output(); this.set_dirty(true); } @@ -1297,7 +1414,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) { cell.clear_output(); } }); @@ -1313,7 +1430,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)) { cell.scroll_output(); this.set_dirty(true); } @@ -1326,7 +1443,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) { cell.scroll_output(); } }); @@ -1342,7 +1459,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)) { cell.toggle_output(); this.set_dirty(true); } @@ -1355,7 +1472,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) { cell.toggle_output(); } }); @@ -1372,7 +1489,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)) { cell.toggle_output_scroll(); this.set_dirty(true); } @@ -1385,7 +1502,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) { cell.toggle_output_scroll(); } }); @@ -1412,7 +1529,7 @@ var IPython = (function (IPython) { * @method start_session */ Notebook.prototype.start_session = function () { - this.session = new IPython.Session(this, this.options); + this.session = new Session(this, this.options); this.session.start($.proxy(this._session_started, this)); }; @@ -1427,7 +1544,7 @@ var IPython = (function (IPython) { var ncells = this.ncells(); for (var i=0; i").text( 'Do you want to restart the current kernel? You will lose all variables defined in it.' @@ -1660,10 +1777,10 @@ var IPython = (function (IPython) { } if (trusted != this.trusted) { this.trusted = trusted; - $([IPython.events]).trigger("trust_changed.Notebook", trusted); + $([Events]).trigger("trust_changed.Notebook", trusted); } if (content.worksheets.length > 1) { - IPython.dialog.modal({ + Dialog.modal({ title : "Multiple worksheets", body : "This notebook has " + data.worksheets.length + " worksheets, " + "but this version of IPython can only handle the first. " + @@ -1705,7 +1822,7 @@ var IPython = (function (IPython) { }; if (trusted != this.trusted) { this.trusted = trusted; - $([IPython.events]).trigger("trust_changed.Notebook", trusted); + $([Events]).trigger("trust_changed.Notebook", trusted); } return data; }; @@ -1730,10 +1847,10 @@ var IPython = (function (IPython) { that.save_notebook(); } }, interval); - $([IPython.events]).trigger("autosave_enabled.Notebook", interval); + $([Events]).trigger("autosave_enabled.Notebook", interval); } else { this.autosave_timer = null; - $([IPython.events]).trigger("autosave_disabled.Notebook"); + $([Events]).trigger("autosave_disabled.Notebook"); } }; @@ -1768,7 +1885,7 @@ var IPython = (function (IPython) { settings[key] = extra_settings[key]; } } - $([IPython.events]).trigger('notebook_saving.Notebook'); + $([Events]).trigger('notebook_saving.Notebook'); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -1789,7 +1906,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'); + $([Events]).trigger('notebook_saved.Notebook'); this._update_autosave_interval(start); if (this._checkpoint_after_save) { this.create_checkpoint(); @@ -1826,7 +1943,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]); + $([Events]).trigger('notebook_save_failed.Notebook', [xhr, status, error]); }; /** @@ -1851,7 +1968,7 @@ var IPython = (function (IPython) { ); var nb = this; - IPython.dialog.modal({ + Dialog.modal({ title: "Trust this notebook?", body: body, @@ -1867,7 +1984,7 @@ var IPython = (function (IPython) { cell.output_area.trusted = true; } } - $([IPython.events]).on('notebook_saved.Notebook', function () { + $([Events]).on('notebook_saved.Notebook', function () { window.location.reload(); }); nb.save_notebook(); @@ -1953,7 +2070,7 @@ var IPython = (function (IPython) { success : $.proxy(that.rename_success, this), error : $.proxy(that.rename_error, this) }; - $([IPython.events]).trigger('rename_notebook.Notebook', data); + $([Events]).trigger('rename_notebook.Notebook', data); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -1986,7 +2103,7 @@ 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); + $([Events]).trigger('notebook_renamed.Notebook', json); }; Notebook.prototype.rename_error = function (xhr, status, error) { @@ -1995,8 +2112,8 @@ var IPython = (function (IPython) { $("").addClass("rename-message") .text('This notebook name already exists.') ); - $([IPython.events]).trigger('notebook_rename_failed.Notebook', [xhr, status, error]); - IPython.dialog.modal({ + $([Events]).trigger('notebook_rename_failed.Notebook', [xhr, status, error]); + Dialog.modal({ title: "Notebook Rename Error!", body: dialog, buttons : { @@ -2004,14 +2121,14 @@ var IPython = (function (IPython) { "OK": { class: "btn-primary", click: function () { - IPython.save_widget.rename_notebook(); + save_widget.rename_notebook(); }} }, 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 === keyboard.keycodes.enter) { that.find('.btn-primary').first().click(); } }); @@ -2039,7 +2156,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'); + $([Events]).trigger('notebook_loading.Notebook'); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -2077,7 +2194,7 @@ 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({ title : "Notebook converted", body : msg, buttons : { @@ -2094,7 +2211,7 @@ 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({ title : "Newer Notebook", body : msg, buttons : { @@ -2116,15 +2233,15 @@ var IPython = (function (IPython) { // load toolbar state if (this.metadata.celltoolbar) { - IPython.CellToolbar.global_show(); - IPython.CellToolbar.activate_preset(this.metadata.celltoolbar); + CellToolbar.global_show(); + CellToolbar.activate_preset(this.metadata.celltoolbar); } else { - IPython.CellToolbar.global_hide(); + 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'); + $([Events]).trigger('notebook_loaded.Notebook'); }; /** @@ -2136,7 +2253,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]); + $([Events]).trigger('notebook_load_failed.Notebook', [xhr, status, error]); var msg; if (xhr.status === 400) { msg = error; @@ -2145,7 +2262,7 @@ var IPython = (function (IPython) { "This version can load notebook formats " + "v" + this.nbformat + " or earlier."; } - IPython.dialog.modal({ + Dialog.modal({ title: "Error loading notebook", body : msg, buttons : { @@ -2224,7 +2341,7 @@ var IPython = (function (IPython) { } else { this.last_checkpoint = null; } - $([IPython.events]).trigger('checkpoints_listed.Notebook', [data]); + $([Events]).trigger('checkpoints_listed.Notebook', [data]); }; /** @@ -2236,7 +2353,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'); + $([Events]).trigger('list_checkpoints_failed.Notebook'); }; /** @@ -2270,7 +2387,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); + $([Events]).trigger('checkpoint_created.Notebook', data); }; /** @@ -2282,7 +2399,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'); + $([Events]).trigger('checkpoint_failed.Notebook'); }; Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) { @@ -2309,7 +2426,7 @@ var IPython = (function (IPython) { ).css("text-align", "center") ); - IPython.dialog.modal({ + Dialog.modal({ title : "Revert notebook to checkpoint", body : body, buttons : { @@ -2331,7 +2448,7 @@ var IPython = (function (IPython) { * @param {String} checkpoint ID */ Notebook.prototype.restore_checkpoint = function (checkpoint) { - $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); + $([Events]).trigger('notebook_restoring.Notebook', checkpoint); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -2356,7 +2473,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'); + $([Events]).trigger('checkpoint_restored.Notebook'); this.load_notebook(this.notebook_name, this.notebook_path); }; @@ -2369,7 +2486,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'); + $([Events]).trigger('checkpoint_restore_failed.Notebook'); }; /** @@ -2379,7 +2496,7 @@ var IPython = (function (IPython) { * @param {String} checkpoint ID */ Notebook.prototype.delete_checkpoint = function (checkpoint) { - $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); + $([Events]).trigger('notebook_restoring.Notebook', checkpoint); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -2404,7 +2521,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); + $([Events]).trigger('checkpoint_deleted.Notebook', data); this.load_notebook(this.notebook_name, this.notebook_path); }; @@ -2417,14 +2534,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'); + $([Events]).trigger('checkpoint_delete_failed.Notebook'); }; + // For backwards compatability. IPython.Notebook = Notebook; - - return IPython; - -}(IPython)); - + return Notebook; +}); diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 0db7af8..3039fc7 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -446,6 +446,7 @@ var IPython = (function (IPython) { return cont; }; +// TODO: RETURN IN THIS NAMESPACE! IPython.TextCell = TextCell; IPython.MarkdownCell = MarkdownCell; IPython.RawCell = RawCell; diff --git a/IPython/html/templates/notebook.html b/IPython/html/templates/notebook.html index acd51b2..af54c86 100644 --- a/IPython/html/templates/notebook.html +++ b/IPython/html/templates/notebook.html @@ -294,69 +294,6 @@ class="notebook_app" {% block script %} -{{super()}} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {% endblock %}