main.js
124 lines
| 4.8 KiB
| application/javascript
|
JavascriptLexer
|
r4609 | //---------------------------------------------------------------------------- | ||
|
r8202 | // Copyright (C) 2011 The IPython Development Team | ||
|
r4609 | // | ||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
|
r4349 | |||
//============================================================================ | ||||
// On document ready | ||||
//============================================================================ | ||||
|
r10758 | "use strict"; | ||
|
r4349 | |||
|
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. | ||||
|
r10861 | require(['components/marked/lib/marked'], | ||
|
r4349 | |||
|
r10856 | function (marked) { | ||
|
r10758 | |||
window.marked = marked | ||||
|
r10856 | |||
|
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'); | ||||
|
r10758 | CodeMirror.modes.null = function() { | ||
return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}} | ||||
|
r8202 | } | ||
|
r10758 | } | ||
|
r8202 | |||
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 | ||||
|
r8565 | IPython.mathjaxutils.init(); | ||
|
r4349 | |||
|
r6193 | IPython.read_only = $('body').data('readOnly') === 'True'; | ||
|
r9277 | $('#ipython-main-app').addClass('border-box-sizing'); | ||
$('div#notebook_panel').addClass('border-box-sizing'); | ||||
|
r4349 | |||
|
r9505 | var baseProjectUrl = $('body').data('baseProjectUrl') | ||
|
r6193 | IPython.page = new IPython.Page(); | ||
|
r4363 | IPython.layout_manager = new IPython.LayoutManager(); | ||
|
r4357 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); | ||
|
r10730 | IPython.quick_help = new IPython.QuickHelp(); | ||
|
r9505 | IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl}); | ||
IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, read_only:IPython.read_only}); | ||||
|
r6047 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | ||
|
r9505 | IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl}) | ||
|
r10906 | IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container') | ||
|
r7144 | IPython.tooltip = new IPython.Tooltip() | ||
|
r8048 | IPython.notification_area = new IPython.NotificationArea('#notification_area') | ||
|
r8074 | IPython.notification_area.init_notification_widgets(); | ||
|
r4357 | |||
|
r4379 | IPython.layout_manager.do_resize(); | ||
|
r4395 | |||
|
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) { | ||||
|
r7446 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); | ||
|
r7394 | } | ||
|
r7666 | $('#fonttest').remove(); | ||
|
r7394 | |||
|
r5213 | if(IPython.read_only){ | ||
// hide various elements from read-only view | ||||
|
r5655 | $('div#pager').remove(); | ||
$('div#pager_splitter').remove(); | ||||
|
r5659 | |||
// set the notebook name field as not modifiable | ||||
$('#notebook_name').attr('disabled','disabled') | ||||
|
r5213 | } | ||
|
r6193 | IPython.page.show(); | ||
|
r4484 | |||
|
r5949 | IPython.layout_manager.do_resize(); | ||
|
r10505 | var first_load = function () { | ||
|
r6047 | IPython.layout_manager.do_resize(); | ||
|
r10006 | var hash = document.location.hash; | ||
if (hash) { | ||||
document.location.hash = ''; | ||||
document.location.hash = hash; | ||||
} | ||||
|
r10508 | IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval); | ||
|
r10505 | // only do this once | ||
$([IPython.events]).off('notebook_loaded.Notebook', first_load); | ||||
}; | ||||
|
r10758 | |||
|
r10505 | $([IPython.events]).on('notebook_loaded.Notebook', first_load); | ||
|
r11227 | $([IPython.events]).trigger('app_initialized.NotebookApp'); | ||
|
r6047 | IPython.notebook.load_notebook($('body').data('notebookId')); | ||
|
r10758 | |||
|
r10539 | if (marked) { | ||
marked.setOptions({ | ||||
gfm : true, | ||||
tables: true, | ||||
langPrefix: "language-", | ||||
highlight: function(code, lang) { | ||||
var highlighted; | ||||
|
r10549 | try { | ||
|
r10539 | highlighted = hljs.highlight(lang, code, false); | ||
|
r10549 | } catch(err) { | ||
|
r10539 | highlighted = hljs.highlightAuto(code); | ||
} | ||||
return highlighted.value; | ||||
} | ||||
}) | ||||
} | ||||
|
r10758 | } | ||
|
r4488 | |||
|
r10758 | ); | ||