main.js
162 lines
| 5.2 KiB
| application/javascript
|
JavascriptLexer
Jonathan Frederic
|
r17192 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
Brian E. Granger
|
r4349 | |||
Jonathan Frederic
|
r17192 | require([ | ||
'base/js/namespace', | ||||
Jonathan Frederic
|
r17200 | 'jquery', | ||
Jonathan Frederic
|
r17192 | 'notebook/js/notebook', | ||
Jeff Hemmelgarn
|
r18643 | 'contents', | ||
Thomas Kluyver
|
r19081 | 'services/config', | ||
Jonathan Frederic
|
r17192 | 'base/js/utils', | ||
'base/js/page', | ||||
'base/js/events', | ||||
'auth/js/loginwidget', | ||||
'notebook/js/maintoolbar', | ||||
'notebook/js/pager', | ||||
'notebook/js/quickhelp', | ||||
'notebook/js/menubar', | ||||
'notebook/js/notificationarea', | ||||
Jonathan Frederic
|
r17198 | 'notebook/js/savewidget', | ||
Matthias Bussonnier
|
r18390 | 'notebook/js/actions', | ||
Jonathan Frederic
|
r17197 | 'notebook/js/keyboardmanager', | ||
Thomas Kluyver
|
r17370 | 'notebook/js/kernelselector', | ||
Matthias BUSSONNIER
|
r18280 | 'codemirror/lib/codemirror', | ||
Matthias Bussonnier
|
r18359 | 'notebook/js/about', | ||
Matthias BUSSONNIER
|
r18280 | // only loaded, not used, please keep sure this is loaded last | ||
'custom/custom' | ||||
Jonathan Frederic
|
r17192 | ], function( | ||
IPython, | ||||
Jonathan Frederic
|
r17196 | $, | ||
Jonathan Frederic
|
r17203 | notebook, | ||
Jeff Hemmelgarn
|
r18643 | contents, | ||
Thomas Kluyver
|
r19081 | configmod, | ||
Jonathan Frederic
|
r17198 | utils, | ||
Jonathan Frederic
|
r17203 | page, | ||
events, | ||||
loginwidget, | ||||
maintoolbar, | ||||
pager, | ||||
quickhelp, | ||||
menubar, | ||||
notificationarea, | ||||
Matthias Bussonnier
|
r18390 | savewidget, | ||
actions, | ||||
Jonathan Frederic
|
r17203 | keyboardmanager, | ||
Matthias BUSSONNIER
|
r18280 | kernelselector, | ||
CodeMirror, | ||||
Matthias Bussonnier
|
r18359 | about, | ||
Matthias BUSSONNIER
|
r18280 | // please keep sure that even if not used, this is loaded last | ||
custom | ||||
Jonathan Frederic
|
r17192 | ) { | ||
MinRK
|
r15234 | "use strict"; | ||
Matthias BUSSONNIER
|
r10758 | |||
Matthias Bussonnier
|
r18290 | // compat with old IPython, remove for IPython > 3.0 | ||
Matthias BUSSONNIER
|
r18280 | window.CodeMirror = CodeMirror; | ||
jon
|
r17210 | var common_options = { | ||
Matthias Bussonnier
|
r18290 | ws_url : utils.get_body_data("wsUrl"), | ||
Jonathan Frederic
|
r17198 | base_url : utils.get_body_data("baseUrl"), | ||
notebook_path : utils.get_body_data("notebookPath"), | ||||
notebook_name : utils.get_body_data('notebookName') | ||||
MinRK
|
r15234 | }; | ||
Matthias BUSSONNIER
|
r9505 | |||
Bussonnier Matthias
|
r19583 | var config_section = new configmod.ConfigSection('notebook', common_options); | ||
config_section.load(); | ||||
Jonathan Frederic
|
r17202 | var page = new page.Page(); | ||
Jonathan Frederic
|
r19179 | var pager = new pager.Pager('div#pager', { | ||
jon
|
r17210 | events: events}); | ||
Matthias Bussonnier
|
r18390 | var acts = new actions.init(); | ||
jon
|
r17210 | var keyboard_manager = new keyboardmanager.KeyboardManager({ | ||
pager: pager, | ||||
Matthias Bussonnier
|
r18390 | events: events, | ||
actions: acts }); | ||||
Jonathan Frederic
|
r17213 | var save_widget = new savewidget.SaveWidget('span#save_widget', { | ||
events: events, | ||||
keyboard_manager: keyboard_manager}); | ||||
Jeff Hemmelgarn
|
r18643 | var contents = new contents.Contents($.extend({ | ||
Bussonnier Matthias
|
r19583 | events: events, config:config_section}, | ||
Jeff Hemmelgarn
|
r18626 | common_options)); | ||
jon
|
r17210 | var notebook = new notebook.Notebook('div#notebook', $.extend({ | ||
events: events, | ||||
keyboard_manager: keyboard_manager, | ||||
save_widget: save_widget, | ||||
Jeff Hemmelgarn
|
r18643 | contents: contents, | ||
Thomas Kluyver
|
r19529 | config: config_section}, | ||
jon
|
r17210 | common_options)); | ||
var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options); | ||||
var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', { | ||||
notebook: notebook, | ||||
Matthias Bussonnier
|
r18390 | events: events, | ||
actions: acts}); | ||||
jon
|
r17210 | var quick_help = new quickhelp.QuickHelp({ | ||
keyboard_manager: keyboard_manager, | ||||
Jonathan Frederic
|
r17212 | events: events, | ||
notebook: notebook}); | ||||
Matthias Bussonnier
|
r18390 | keyboard_manager.set_notebook(notebook); | ||
keyboard_manager.set_quickhelp(quick_help); | ||||
jon
|
r17210 | var menubar = new menubar.MenuBar('#menubar', $.extend({ | ||
notebook: notebook, | ||||
Jeff Hemmelgarn
|
r18643 | contents: contents, | ||
jon
|
r17210 | events: events, | ||
save_widget: save_widget, | ||||
quick_help: quick_help}, | ||||
common_options)); | ||||
Thomas Kluyver
|
r19017 | var notification_area = new notificationarea.NotebookNotificationArea( | ||
jon
|
r17210 | '#notification_area', { | ||
events: events, | ||||
save_widget: save_widget, | ||||
Jonathan Frederic
|
r17212 | notebook: notebook, | ||
keyboard_manager: keyboard_manager}); | ||||
Jonathan Frederic
|
r17192 | notification_area.init_notification_widgets(); | ||
Thomas Kluyver
|
r17370 | var kernel_selector = new kernelselector.KernelSelector( | ||
Min RK
|
r19596 | '#kernel_logo_widget', notebook); | ||
Jonathan Frederic
|
r17192 | |||
mcelrath
|
r7394 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ | ||
'<span id="test2" style="font-weight: bold;">x</span>'+ | ||||
MinRK
|
r15234 | '<span id="test3" style="font-style: italic;">x</span></pre></div>'); | ||
mcelrath
|
r7394 | var nh = $('#test1').innerHeight(); | ||
var bh = $('#test2').innerHeight(); | ||||
var ih = $('#test3').innerHeight(); | ||||
if(nh != bh || nh != ih) { | ||||
mcelrath
|
r7446 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); | ||
mcelrath
|
r7394 | } | ||
mcelrath
|
r7666 | $('#fonttest').remove(); | ||
mcelrath
|
r7394 | |||
Jonathan Frederic
|
r17192 | page.show(); | ||
Brian E. Granger
|
r4484 | |||
MinRK
|
r10505 | var first_load = function () { | ||
MinRK
|
r10006 | var hash = document.location.hash; | ||
if (hash) { | ||||
document.location.hash = ''; | ||||
document.location.hash = hash; | ||||
} | ||||
Jonathan Frederic
|
r17192 | notebook.set_autosave_interval(notebook.minimum_autosave_interval); | ||
MinRK
|
r10505 | // only do this once | ||
Jonathan Frederic
|
r17195 | events.off('notebook_loaded.Notebook', first_load); | ||
MinRK
|
r10505 | }; | ||
Jonathan Frederic
|
r17195 | events.on('notebook_loaded.Notebook', first_load); | ||
Jason Grout
|
r17319 | |||
Jonathan Frederic
|
r17212 | IPython.page = page; | ||
IPython.notebook = notebook; | ||||
Jeff Hemmelgarn
|
r18643 | IPython.contents = contents; | ||
Jonathan Frederic
|
r17212 | 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.keyboard_manager = keyboard_manager; | ||||
IPython.save_widget = save_widget; | ||||
Jonathan Frederic
|
r17215 | IPython.tooltip = notebook.tooltip; | ||
Jason Grout
|
r17319 | |||
events.trigger('app_initialized.NotebookApp'); | ||||
Thomas Kluyver
|
r19081 | config_section.loaded.then(function() { | ||
if (config_section.data.load_extensions) { | ||||
var nbextension_paths = Object.getOwnPropertyNames( | ||||
config_section.data.load_extensions); | ||||
IPython.load_extensions.apply(this, nbextension_paths); | ||||
} | ||||
}); | ||||
Min RK
|
r18752 | notebook.load_notebook(common_options.notebook_path); | ||
Jason Grout
|
r17319 | |||
MinRK
|
r15234 | }); | ||