notebookmain.js
87 lines
| 3.5 KiB
| application/javascript
|
JavascriptLexer
Brian E. Granger
|
r4609 | //---------------------------------------------------------------------------- | ||
Matthias BUSSONNIER
|
r8202 | // Copyright (C) 2011 The IPython Development Team | ||
Brian E. Granger
|
r4609 | // | ||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
Brian E. Granger
|
r4349 | |||
//============================================================================ | ||||
// On document ready | ||||
//============================================================================ | ||||
$(document).ready(function () { | ||||
Brian Granger
|
r5904 | |||
Matthias BUSSONNIER
|
r8202 | // 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 | ||||
Aron Ahmadia
|
r8565 | IPython.mathjaxutils.init(); | ||
Brian E. Granger
|
r4349 | |||
Brian Granger
|
r6193 | IPython.read_only = $('body').data('readOnly') === 'True'; | ||
$('div#main_app').addClass('border-box-sizing ui-widget'); | ||||
Brian E. Granger
|
r4363 | $('div#notebook_panel').addClass('border-box-sizing ui-widget'); | ||
Brian Granger
|
r6193 | // The header's bottom border is provided by the menu bar so we remove it. | ||
$('div#header').css('border-bottom-style','none'); | ||||
Brian E. Granger
|
r4349 | |||
Brian Granger
|
r6193 | IPython.page = new IPython.Page(); | ||
IPython.markdown_converter = new Markdown.Converter(); | ||||
Brian E. Granger
|
r4363 | IPython.layout_manager = new IPython.LayoutManager(); | ||
Brian E. Granger
|
r4357 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); | ||
MinRK
|
r5066 | IPython.quick_help = new IPython.QuickHelp('span#quick_help_area'); | ||
MinRK
|
r5200 | IPython.login_widget = new IPython.LoginWidget('span#login_widget'); | ||
Brian E. Granger
|
r4363 | IPython.notebook = new IPython.Notebook('div#notebook'); | ||
Brian Granger
|
r6047 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | ||
Brian Granger
|
r5857 | IPython.menubar = new IPython.MenuBar('#menubar') | ||
Matthias BUSSONNIER
|
r8207 | IPython.toolbar = new IPython.MainToolBar('#maintoolbar') | ||
Matthias Bussonnier
|
r7144 | IPython.tooltip = new IPython.Tooltip() | ||
Matthias BUSSONNIER
|
r8048 | IPython.notification_area = new IPython.NotificationArea('#notification_area') | ||
Matthias BUSSONNIER
|
r8074 | IPython.notification_area.init_notification_widgets(); | ||
Brian E. Granger
|
r4357 | |||
Brian E. Granger
|
r4379 | IPython.layout_manager.do_resize(); | ||
Brian E. Granger
|
r4395 | |||
mcelrath
|
r7394 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ | ||
'<span id="test2" style="font-weight: bold;">x</span>'+ | ||||
'<span id="test3" style="font-style: italic;">x</span></pre></div>') | ||||
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 | |||
MinRK
|
r5213 | if(IPython.read_only){ | ||
// hide various elements from read-only view | ||||
Matthias BUSSONNIER
|
r5655 | $('div#pager').remove(); | ||
$('div#pager_splitter').remove(); | ||||
Matthias BUSSONNIER
|
r5659 | |||
// set the notebook name field as not modifiable | ||||
$('#notebook_name').attr('disabled','disabled') | ||||
MinRK
|
r5213 | } | ||
Brian Granger
|
r6193 | IPython.page.show(); | ||
Brian E. Granger
|
r4484 | |||
Brian Granger
|
r5949 | IPython.layout_manager.do_resize(); | ||
Brian Granger
|
r6047 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | ||
IPython.layout_manager.do_resize(); | ||||
Mikhail Korobov
|
r8839 | }); | ||
Brian Granger
|
r6047 | IPython.notebook.load_notebook($('body').data('notebookId')); | ||
Brian E. Granger
|
r4488 | |||
Brian E. Granger
|
r4349 | }); | ||