Show More
@@ -1,89 +1,94 b'' | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2011 The IPython Development Team |
|
2 | // Copyright (C) 2011 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // On document ready |
|
9 | // On document ready | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | $(document).ready(function () { |
|
13 | $(document).ready(function () { | |
14 |
|
14 | |||
15 | // monkey patch CM to be able to syntax highlight cell magics |
|
15 | // monkey patch CM to be able to syntax highlight cell magics | |
16 | // bug reported upstream, |
|
16 | // bug reported upstream, | |
17 | // see https://github.com/marijnh/CodeMirror2/issues/670 |
|
17 | // see https://github.com/marijnh/CodeMirror2/issues/670 | |
18 | if(CodeMirror.getMode(1,'text/plain').indent == undefined ){ |
|
18 | if(CodeMirror.getMode(1,'text/plain').indent == undefined ){ | |
19 | console.log('patching CM for undefined indent'); |
|
19 | console.log('patching CM for undefined indent'); | |
20 | CodeMirror.modes.null = function() { return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}}} |
|
20 | CodeMirror.modes.null = function() { return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}}} | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | CodeMirror.patchedGetMode = function(config, mode){ |
|
23 | CodeMirror.patchedGetMode = function(config, mode){ | |
24 | var cmmode = CodeMirror.getMode(config, mode); |
|
24 | var cmmode = CodeMirror.getMode(config, mode); | |
25 | if(cmmode.indent == null) |
|
25 | if(cmmode.indent == null) | |
26 | { |
|
26 | { | |
27 | console.log('patch mode "' , mode, '" on the fly'); |
|
27 | console.log('patch mode "' , mode, '" on the fly'); | |
28 | cmmode.indent = function(){return 0}; |
|
28 | cmmode.indent = function(){return 0}; | |
29 | } |
|
29 | } | |
30 | return cmmode; |
|
30 | return cmmode; | |
31 | } |
|
31 | } | |
32 | // end monkey patching CodeMirror |
|
32 | // end monkey patching CodeMirror | |
33 |
|
33 | |||
34 | IPython.mathjaxutils.init(); |
|
34 | IPython.mathjaxutils.init(); | |
35 |
|
35 | |||
36 | IPython.read_only = $('body').data('readOnly') === 'True'; |
|
36 | IPython.read_only = $('body').data('readOnly') === 'True'; | |
37 | $('#ipython-main-app').addClass('border-box-sizing'); |
|
37 | $('#ipython-main-app').addClass('border-box-sizing'); | |
38 | $('div#notebook_panel').addClass('border-box-sizing'); |
|
38 | $('div#notebook_panel').addClass('border-box-sizing'); | |
39 | // The header's bottom border is provided by the menu bar so we remove it. |
|
39 | // The header's bottom border is provided by the menu bar so we remove it. | |
40 | $('div#header').css('border-bottom-style','none'); |
|
40 | $('div#header').css('border-bottom-style','none'); | |
41 |
|
41 | |||
42 | var baseProjectUrl = $('body').data('baseProjectUrl') |
|
42 | var baseProjectUrl = $('body').data('baseProjectUrl') | |
43 |
|
43 | |||
44 | IPython.page = new IPython.Page(); |
|
44 | IPython.page = new IPython.Page(); | |
45 | IPython.markdown_converter = new Markdown.Converter(); |
|
45 | IPython.markdown_converter = new Markdown.Converter(); | |
46 | IPython.layout_manager = new IPython.LayoutManager(); |
|
46 | IPython.layout_manager = new IPython.LayoutManager(); | |
47 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); |
|
47 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); | |
48 | IPython.quick_help = new IPython.QuickHelp('span#quick_help_area'); |
|
48 | IPython.quick_help = new IPython.QuickHelp('span#quick_help_area'); | |
49 | IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl}); |
|
49 | IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl}); | |
50 | IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, read_only:IPython.read_only}); |
|
50 | IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, read_only:IPython.read_only}); | |
51 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); |
|
51 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | |
52 | IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl}) |
|
52 | IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl}) | |
53 | IPython.toolbar = new IPython.MainToolBar('#maintoolbar') |
|
53 | IPython.toolbar = new IPython.MainToolBar('#maintoolbar') | |
54 | IPython.tooltip = new IPython.Tooltip() |
|
54 | IPython.tooltip = new IPython.Tooltip() | |
55 | IPython.notification_area = new IPython.NotificationArea('#notification_area') |
|
55 | IPython.notification_area = new IPython.NotificationArea('#notification_area') | |
56 | IPython.notification_area.init_notification_widgets(); |
|
56 | IPython.notification_area.init_notification_widgets(); | |
57 |
|
57 | |||
58 | IPython.layout_manager.do_resize(); |
|
58 | IPython.layout_manager.do_resize(); | |
59 |
|
59 | |||
60 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ |
|
60 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ | |
61 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
|
61 | '<span id="test2" style="font-weight: bold;">x</span>'+ | |
62 | '<span id="test3" style="font-style: italic;">x</span></pre></div>') |
|
62 | '<span id="test3" style="font-style: italic;">x</span></pre></div>') | |
63 | var nh = $('#test1').innerHeight(); |
|
63 | var nh = $('#test1').innerHeight(); | |
64 | var bh = $('#test2').innerHeight(); |
|
64 | var bh = $('#test2').innerHeight(); | |
65 | var ih = $('#test3').innerHeight(); |
|
65 | var ih = $('#test3').innerHeight(); | |
66 | if(nh != bh || nh != ih) { |
|
66 | if(nh != bh || nh != ih) { | |
67 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); |
|
67 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); | |
68 | } |
|
68 | } | |
69 | $('#fonttest').remove(); |
|
69 | $('#fonttest').remove(); | |
70 |
|
70 | |||
71 | if(IPython.read_only){ |
|
71 | if(IPython.read_only){ | |
72 | // hide various elements from read-only view |
|
72 | // hide various elements from read-only view | |
73 | $('div#pager').remove(); |
|
73 | $('div#pager').remove(); | |
74 | $('div#pager_splitter').remove(); |
|
74 | $('div#pager_splitter').remove(); | |
75 |
|
75 | |||
76 | // set the notebook name field as not modifiable |
|
76 | // set the notebook name field as not modifiable | |
77 | $('#notebook_name').attr('disabled','disabled') |
|
77 | $('#notebook_name').attr('disabled','disabled') | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | IPython.page.show(); |
|
80 | IPython.page.show(); | |
81 |
|
81 | |||
82 | IPython.layout_manager.do_resize(); |
|
82 | IPython.layout_manager.do_resize(); | |
83 | $([IPython.events]).on('notebook_loaded.Notebook', function () { |
|
83 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
84 | IPython.layout_manager.do_resize(); |
|
84 | IPython.layout_manager.do_resize(); | |
|
85 | var hash = document.location.hash; | |||
|
86 | if (hash) { | |||
|
87 | document.location.hash = ''; | |||
|
88 | document.location.hash = hash; | |||
|
89 | } | |||
85 | }); |
|
90 | }); | |
86 | IPython.notebook.load_notebook($('body').data('notebookId')); |
|
91 | IPython.notebook.load_notebook($('body').data('notebookId')); | |
87 |
|
92 | |||
88 | }); |
|
93 | }); | |
89 |
|
94 |
General Comments 0
You need to be logged in to leave comments.
Login now