main.js
121 lines
| 4.7 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 | ||||
//============================================================================ | ||||
Matthias BUSSONNIER
|
r10758 | // 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. | ||||
Jonathan Frederic
|
r14342 | require(['components/marked/lib/marked', | ||
Jonathan Frederic
|
r15427 | 'widgets/js/init'], | ||
Brian E. Granger
|
r4349 | |||
Matthias BUSSONNIER
|
r10856 | function (marked) { | ||
MinRK
|
r15234 | "use strict"; | ||
Matthias BUSSONNIER
|
r10758 | |||
MinRK
|
r15234 | window.marked = marked; | ||
Matthias BUSSONNIER
|
r10856 | |||
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 | ||||
MinRK
|
r15234 | if(CodeMirror.getMode(1,'text/plain').indent === undefined ){ | ||
Matthias BUSSONNIER
|
r8202 | console.log('patching CM for undefined indent'); | ||
Matthias BUSSONNIER
|
r10758 | CodeMirror.modes.null = function() { | ||
MinRK
|
r15234 | return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}}; | ||
}; | ||||
Matthias BUSSONNIER
|
r10758 | } | ||
Matthias BUSSONNIER
|
r8202 | |||
CodeMirror.patchedGetMode = function(config, mode){ | ||||
var cmmode = CodeMirror.getMode(config, mode); | ||||
MinRK
|
r15234 | if(cmmode.indent === null) { | ||
Matthias BUSSONNIER
|
r8202 | console.log('patch mode "' , mode, '" on the fly'); | ||
MinRK
|
r15234 | cmmode.indent = function(){return 0;}; | ||
Matthias BUSSONNIER
|
r8202 | } | ||
return cmmode; | ||||
MinRK
|
r15234 | }; | ||
Matthias BUSSONNIER
|
r8202 | // end monkey patching CodeMirror | ||
Aron Ahmadia
|
r8565 | IPython.mathjaxutils.init(); | ||
Brian E. Granger
|
r4349 | |||
Bussonnier Matthias
|
r9277 | $('#ipython-main-app').addClass('border-box-sizing'); | ||
$('div#notebook_panel').addClass('border-box-sizing'); | ||||
Brian E. Granger
|
r4349 | |||
MinRK
|
r15234 | var opts = { | ||
MinRK
|
r15240 | base_url : IPython.utils.get_body_data("baseUrl"), | ||
notebook_path : IPython.utils.get_body_data("notebookPath"), | ||||
notebook_name : IPython.utils.get_body_data('notebookName') | ||||
MinRK
|
r15234 | }; | ||
Matthias BUSSONNIER
|
r9505 | |||
Brian Granger
|
r6193 | IPython.page = new IPython.Page(); | ||
Brian E. Granger
|
r4363 | IPython.layout_manager = new IPython.LayoutManager(); | ||
Brian E. Granger
|
r4357 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); | ||
Brian E. Granger
|
r10730 | IPython.quick_help = new IPython.QuickHelp(); | ||
MinRK
|
r15234 | IPython.login_widget = new IPython.LoginWidget('span#login_widget', opts); | ||
IPython.notebook = new IPython.Notebook('div#notebook', opts); | ||||
Brian E. Granger
|
r14020 | IPython.keyboard_manager = new IPython.KeyboardManager(); | ||
Brian Granger
|
r6047 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | ||
MinRK
|
r15234 | 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'); | ||||
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>'+ | ||||
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 | |||
Brian Granger
|
r6193 | IPython.page.show(); | ||
Brian E. Granger
|
r4484 | |||
Brian Granger
|
r5949 | IPython.layout_manager.do_resize(); | ||
MinRK
|
r10505 | var first_load = function () { | ||
Brian Granger
|
r6047 | IPython.layout_manager.do_resize(); | ||
MinRK
|
r10006 | var hash = document.location.hash; | ||
if (hash) { | ||||
document.location.hash = ''; | ||||
document.location.hash = hash; | ||||
} | ||||
MinRK
|
r10508 | IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval); | ||
MinRK
|
r10505 | // only do this once | ||
$([IPython.events]).off('notebook_loaded.Notebook', first_load); | ||||
}; | ||||
MinRK
|
r13189 | |||
MinRK
|
r10505 | $([IPython.events]).on('notebook_loaded.Notebook', first_load); | ||
Matthias BUSSONNIER
|
r11227 | $([IPython.events]).trigger('app_initialized.NotebookApp'); | ||
MinRK
|
r15234 | IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path); | ||
Matthias BUSSONNIER
|
r10758 | |||
MinRK
|
r10539 | if (marked) { | ||
marked.setOptions({ | ||||
gfm : true, | ||||
tables: true, | ||||
langPrefix: "language-", | ||||
highlight: function(code, lang) { | ||||
MinRK
|
r12594 | if (!lang) { | ||
// no language, no highlight | ||||
return code; | ||||
} | ||||
MinRK
|
r10539 | var highlighted; | ||
MinRK
|
r10549 | try { | ||
MinRK
|
r10539 | highlighted = hljs.highlight(lang, code, false); | ||
MinRK
|
r10549 | } catch(err) { | ||
MinRK
|
r10539 | highlighted = hljs.highlightAuto(code); | ||
} | ||||
return highlighted.value; | ||||
} | ||||
MinRK
|
r15234 | }); | ||
MinRK
|
r10539 | } | ||
MinRK
|
r15234 | }); | ||