Show More
@@ -1,123 +1,124 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 | "use strict"; |
|
11 | "use strict"; | |
12 |
|
12 | |||
13 | // for the time beeing, we have to pass marked as a parameter here, |
|
13 | // for the time beeing, we have to pass marked as a parameter here, | |
14 | // as injecting require.js make marked not to put itself in the globals, |
|
14 | // as injecting require.js make marked not to put itself in the globals, | |
15 | // which make both this file fail at setting marked configuration, and textcell.js |
|
15 | // which make both this file fail at setting marked configuration, and textcell.js | |
16 | // which search marked into global. |
|
16 | // which search marked into global. | |
17 | require(['components/marked/lib/marked'], |
|
17 | require(['components/marked/lib/marked'], | |
18 |
|
18 | |||
19 | function (marked) { |
|
19 | function (marked) { | |
20 |
|
20 | |||
21 | window.marked = marked |
|
21 | window.marked = marked | |
22 |
|
22 | |||
23 | // monkey patch CM to be able to syntax highlight cell magics |
|
23 | // monkey patch CM to be able to syntax highlight cell magics | |
24 | // bug reported upstream, |
|
24 | // bug reported upstream, | |
25 | // see https://github.com/marijnh/CodeMirror2/issues/670 |
|
25 | // see https://github.com/marijnh/CodeMirror2/issues/670 | |
26 | if(CodeMirror.getMode(1,'text/plain').indent == undefined ){ |
|
26 | if(CodeMirror.getMode(1,'text/plain').indent == undefined ){ | |
27 | console.log('patching CM for undefined indent'); |
|
27 | console.log('patching CM for undefined indent'); | |
28 | CodeMirror.modes.null = function() { |
|
28 | CodeMirror.modes.null = function() { | |
29 | return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}} |
|
29 | return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}} | |
30 | } |
|
30 | } | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | CodeMirror.patchedGetMode = function(config, mode){ |
|
33 | CodeMirror.patchedGetMode = function(config, mode){ | |
34 | var cmmode = CodeMirror.getMode(config, mode); |
|
34 | var cmmode = CodeMirror.getMode(config, mode); | |
35 | if(cmmode.indent == null) |
|
35 | if(cmmode.indent == null) | |
36 | { |
|
36 | { | |
37 | console.log('patch mode "' , mode, '" on the fly'); |
|
37 | console.log('patch mode "' , mode, '" on the fly'); | |
38 | cmmode.indent = function(){return 0}; |
|
38 | cmmode.indent = function(){return 0}; | |
39 | } |
|
39 | } | |
40 | return cmmode; |
|
40 | return cmmode; | |
41 | } |
|
41 | } | |
42 | // end monkey patching CodeMirror |
|
42 | // end monkey patching CodeMirror | |
43 |
|
43 | |||
44 | IPython.mathjaxutils.init(); |
|
44 | IPython.mathjaxutils.init(); | |
45 |
|
45 | |||
46 | IPython.read_only = $('body').data('readOnly') === 'True'; |
|
46 | IPython.read_only = $('body').data('readOnly') === 'True'; | |
47 | $('#ipython-main-app').addClass('border-box-sizing'); |
|
47 | $('#ipython-main-app').addClass('border-box-sizing'); | |
48 | $('div#notebook_panel').addClass('border-box-sizing'); |
|
48 | $('div#notebook_panel').addClass('border-box-sizing'); | |
49 |
|
49 | |||
50 | var baseProjectUrl = $('body').data('baseProjectUrl') |
|
50 | var baseProjectUrl = $('body').data('baseProjectUrl') | |
51 |
|
51 | |||
52 | IPython.page = new IPython.Page(); |
|
52 | IPython.page = new IPython.Page(); | |
53 | IPython.layout_manager = new IPython.LayoutManager(); |
|
53 | IPython.layout_manager = new IPython.LayoutManager(); | |
54 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); |
|
54 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); | |
55 | IPython.quick_help = new IPython.QuickHelp(); |
|
55 | IPython.quick_help = new IPython.QuickHelp(); | |
56 | IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl}); |
|
56 | IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl}); | |
57 | IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, read_only:IPython.read_only}); |
|
57 | IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, read_only:IPython.read_only}); | |
58 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); |
|
58 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | |
59 | IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl}) |
|
59 | IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl}) | |
60 | IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container') |
|
60 | IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container') | |
61 | IPython.tooltip = new IPython.Tooltip() |
|
61 | IPython.tooltip = new IPython.Tooltip() | |
62 | IPython.notification_area = new IPython.NotificationArea('#notification_area') |
|
62 | IPython.notification_area = new IPython.NotificationArea('#notification_area') | |
63 | IPython.notification_area.init_notification_widgets(); |
|
63 | IPython.notification_area.init_notification_widgets(); | |
64 |
|
64 | |||
65 | IPython.layout_manager.do_resize(); |
|
65 | IPython.layout_manager.do_resize(); | |
66 |
|
66 | |||
67 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ |
|
67 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ | |
68 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
|
68 | '<span id="test2" style="font-weight: bold;">x</span>'+ | |
69 | '<span id="test3" style="font-style: italic;">x</span></pre></div>') |
|
69 | '<span id="test3" style="font-style: italic;">x</span></pre></div>') | |
70 | var nh = $('#test1').innerHeight(); |
|
70 | var nh = $('#test1').innerHeight(); | |
71 | var bh = $('#test2').innerHeight(); |
|
71 | var bh = $('#test2').innerHeight(); | |
72 | var ih = $('#test3').innerHeight(); |
|
72 | var ih = $('#test3').innerHeight(); | |
73 | if(nh != bh || nh != ih) { |
|
73 | if(nh != bh || nh != ih) { | |
74 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); |
|
74 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); | |
75 | } |
|
75 | } | |
76 | $('#fonttest').remove(); |
|
76 | $('#fonttest').remove(); | |
77 |
|
77 | |||
78 | if(IPython.read_only){ |
|
78 | if(IPython.read_only){ | |
79 | // hide various elements from read-only view |
|
79 | // hide various elements from read-only view | |
80 | $('div#pager').remove(); |
|
80 | $('div#pager').remove(); | |
81 | $('div#pager_splitter').remove(); |
|
81 | $('div#pager_splitter').remove(); | |
82 |
|
82 | |||
83 | // set the notebook name field as not modifiable |
|
83 | // set the notebook name field as not modifiable | |
84 | $('#notebook_name').attr('disabled','disabled') |
|
84 | $('#notebook_name').attr('disabled','disabled') | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | IPython.page.show(); |
|
87 | IPython.page.show(); | |
88 |
|
88 | |||
89 | IPython.layout_manager.do_resize(); |
|
89 | IPython.layout_manager.do_resize(); | |
90 | var first_load = function () { |
|
90 | var first_load = function () { | |
91 | IPython.layout_manager.do_resize(); |
|
91 | IPython.layout_manager.do_resize(); | |
92 | var hash = document.location.hash; |
|
92 | var hash = document.location.hash; | |
93 | if (hash) { |
|
93 | if (hash) { | |
94 | document.location.hash = ''; |
|
94 | document.location.hash = ''; | |
95 | document.location.hash = hash; |
|
95 | document.location.hash = hash; | |
96 | } |
|
96 | } | |
97 | IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval); |
|
97 | IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval); | |
98 | // only do this once |
|
98 | // only do this once | |
99 | $([IPython.events]).off('notebook_loaded.Notebook', first_load); |
|
99 | $([IPython.events]).off('notebook_loaded.Notebook', first_load); | |
100 | }; |
|
100 | }; | |
101 |
|
101 | |||
102 | $([IPython.events]).on('notebook_loaded.Notebook', first_load); |
|
102 | $([IPython.events]).on('notebook_loaded.Notebook', first_load); | |
|
103 | $([IPython.events]).trigger('app_initialized.NotebookApp'); | |||
103 | IPython.notebook.load_notebook($('body').data('notebookId')); |
|
104 | IPython.notebook.load_notebook($('body').data('notebookId')); | |
104 |
|
105 | |||
105 | if (marked) { |
|
106 | if (marked) { | |
106 | marked.setOptions({ |
|
107 | marked.setOptions({ | |
107 | gfm : true, |
|
108 | gfm : true, | |
108 | tables: true, |
|
109 | tables: true, | |
109 | langPrefix: "language-", |
|
110 | langPrefix: "language-", | |
110 | highlight: function(code, lang) { |
|
111 | highlight: function(code, lang) { | |
111 | var highlighted; |
|
112 | var highlighted; | |
112 | try { |
|
113 | try { | |
113 | highlighted = hljs.highlight(lang, code, false); |
|
114 | highlighted = hljs.highlight(lang, code, false); | |
114 | } catch(err) { |
|
115 | } catch(err) { | |
115 | highlighted = hljs.highlightAuto(code); |
|
116 | highlighted = hljs.highlightAuto(code); | |
116 | } |
|
117 | } | |
117 | return highlighted.value; |
|
118 | return highlighted.value; | |
118 | } |
|
119 | } | |
119 | }) |
|
120 | }) | |
120 | } |
|
121 | } | |
121 | } |
|
122 | } | |
122 |
|
123 | |||
123 | ); |
|
124 | ); |
General Comments 0
You need to be logged in to leave comments.
Login now