forked from ipython/ipython
/
notebookmain.js
131 lines (117 loc) · 5.64 KB
/
notebookmain.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// On document ready
//============================================================================
$(document).ready(function () {
if (window.MathJax == undefined){
// MathJax undefined, but expected. Draw warning.
window.MathJax = null;
var dialog = $('<div></div>').html(
"<p class='dialog'>"+
"We were unable to retrieve MathJax. Math/LaTeX rendering will be disabled."+
"</p>"+
"<p class='dialog'>"+
"With a working internet connection, you can run the following at a Python"+
" or IPython prompt, which will install a local copy of MathJax:"+
"</p>"+
"<pre class='dialog'>"+
">>> from IPython.external import mathjax; mathjax.install_mathjax()"+
"</pre>"+
"<p class='dialog'>"+
"This will try to install MathJax into the directory where you installed"+
" IPython. If you installed IPython to a location that requires"+
" administrative privileges to write, you will need to make this call as"+
" an administrator."+
"</p>"+
"<p class='dialog'>"+
"On OSX/Linux/Unix, this can be done at the command-line via:"+
"</p>"+
"<pre class='dialog'>"+
"$ sudo python -c 'from IPython.external import mathjax; mathjax.install_mathjax()'"+
"</pre>"+
"<p class='dialog'>"+
"Or you can instruct the notebook server to start without MathJax support, with:"+
"<pre class='dialog'>"+
"</p>"+
"$ ipython notebook --no-mathjax"+
"</pre>"+
"<p class='dialog'>"+
"in which case, equations will not be rendered."+
"</p>"
).dialog({
title: 'MathJax disabled',
width: "70%",
modal: true,
})
}else if (window.MathJax){
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
},
displayAlign: 'left', // Change this to 'center' to center equations.
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}}
}
});
}else{
// window.MathJax == null
// --no-mathjax mode
}
IPython.markdown_converter = new Markdown.Converter();
IPython.read_only = $('meta[name=read_only]').attr("content") == 'True';
$('div#header').addClass('border-box-sizing');
$('div#main_app').addClass('border-box-sizing ui-widget ui-widget-content');
$('div#notebook_panel').addClass('border-box-sizing ui-widget');
IPython.layout_manager = new IPython.LayoutManager();
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
IPython.left_panel = new IPython.LeftPanel('div#left_panel', 'div#left_panel_splitter');
IPython.save_widget = new IPython.SaveWidget('span#save_widget');
IPython.quick_help = new IPython.QuickHelp('span#quick_help_area');
IPython.login_widget = new IPython.LoginWidget('span#login_widget');
IPython.print_widget = new IPython.PrintWidget('span#print_widget');
IPython.notebook = new IPython.Notebook('div#notebook');
IPython.kernel_status_widget = new IPython.KernelStatusWidget('#kernel_status');
IPython.kernel_status_widget.status_idle();
IPython.layout_manager.do_resize();
// These have display: none in the css file and are made visible here to prevent FLOUC.
$('div#header').css('display','block');
if(IPython.read_only){
// hide various elements from read-only view
IPython.save_widget.element.find('button#save_notebook').addClass('hidden');
IPython.quick_help.element.addClass('hidden'); // shortcuts are disabled in read_only
$('button#new_notebook').addClass('hidden');
$('div#cell_section').addClass('hidden');
$('div#config_section').addClass('hidden');
$('div#kernel_section').addClass('hidden');
$('span#login_widget').removeClass('hidden');
// left panel starts collapsed, but the collapse must happen after
// elements start drawing. Don't draw contents of the panel until
// after they are collapsed
IPython.left_panel.left_panel_element.css('visibility', 'hidden');
}
$('div#main_app').css('display','block');
// Perform these actions after the notebook has been loaded.
// We wait 100 milliseconds because the notebook scrolls to the top after a load
// is completed and we need to wait for that to mostly finish.
IPython.notebook.load_notebook(function () {
setTimeout(function () {
IPython.save_widget.update_url();
IPython.layout_manager.do_resize();
IPython.pager.collapse();
if(IPython.read_only){
// collapse the left panel on read-only
IPython.left_panel.collapse();
// and finally unhide the panel contents after collapse
setTimeout(function(){
IPython.left_panel.left_panel_element.css('visibility', 'visible');
}, 200);
}
},100);
});
});