Show More
@@ -1,19 +1,11 b'' | |||
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2014 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
7 | 3 | |
|
8 | //============================================================================ | |
|
9 | // Utilities | |
|
10 | //============================================================================ | |
|
11 | IPython.namespace('IPython.security'); | |
|
12 | ||
|
13 | IPython.security = (function (IPython) { | |
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'components/jquery/jquery.min' | |
|
7 | ], function(IPython, $) { | |
|
14 | 8 | "use strict"; |
|
15 | ||
|
16 | var utils = IPython.utils; | |
|
17 | 9 | |
|
18 | 10 | var noop = function (x) { return x; }; |
|
19 | 11 | |
@@ -121,6 +113,4 b' IPython.security = (function (IPython) {' | |||
|
121 | 113 | caja: caja, |
|
122 | 114 | sanitize_html: sanitize_html |
|
123 | 115 | }; |
|
124 | ||
|
125 | }(IPython)); | |
|
126 | ||
|
116 | }); |
@@ -550,7 +550,8 b' define([' | |||
|
550 | 550 | log_ajax_error : log_ajax_error, |
|
551 | 551 | }; |
|
552 | 552 | |
|
553 | // Register self in the global namespace for convenience. | |
|
553 | // Backwards compatability. | |
|
554 | 554 | IPython.Utils = Utils; |
|
555 | ||
|
555 | 556 | return Utils; |
|
556 | 557 | }); |
@@ -1,73 +1,51 b'' | |||
|
1 | "components/codemirror/lib/codemirror.js", | |
|
2 | // Set codemirror version. | |
|
3 | // CodeMirror.modeURL = "{{ static_url("components/codemirror/mode/%N/%N.js", include_version=False) }}"; | |
|
4 | "components/codemirror/addon/mode/loadmode.js", | |
|
5 | "components/codemirror/addon/mode/multiplex.js", | |
|
6 | "components/codemirror/addon/mode/overlay.js", | |
|
7 | "components/codemirror/addon/edit/matchbrackets.js", | |
|
8 | "components/codemirror/addon/edit/closebrackets.js", | |
|
9 | "components/codemirror/addon/comment/comment.js", | |
|
10 | "components/codemirror/mode/htmlmixed/htmlmixed.js", | |
|
11 | "components/codemirror/mode/xml/xml.js", | |
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 | "notebook/js/codemirror-ipython.js", | |
|
18 | "notebook/js/codemirror-ipythongfm.js", | |
|
19 | ||
|
20 | ||
|
21 | // monkey patch CM to be able to syntax highlight cell magics | |
|
22 | // bug reported upstream, | |
|
23 | // see https://github.com/marijnh/CodeMirror2/issues/670 | |
|
24 | if(CodeMirror.getMode(1,'text/plain').indent === undefined ){ | |
|
25 | console.log('patching CM for undefined indent'); | |
|
26 | CodeMirror.modes.null = function() { | |
|
27 | return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}}; | |
|
28 | }; | |
|
29 | } | |
|
30 | ||
|
31 | CodeMirror.patchedGetMode = function(config, mode){ | |
|
32 | var cmmode = CodeMirror.getMode(config, mode); | |
|
33 | if(cmmode.indent === null) { | |
|
34 | console.log('patch mode "' , mode, '" on the fly'); | |
|
35 | cmmode.indent = function(){return 0;}; | |
|
36 | } | |
|
37 | return cmmode; | |
|
38 | }; | |
|
39 | // end monkey patching CodeMirror | |
|
40 | ||
|
41 | ||
|
42 | "notebook/js/tooltip", | |
|
43 | Tooltip, | |
|
44 | tooltip = new Tooltip(); | |
|
45 | IPython.tooltip = tooltip; | |
|
46 | ||
|
47 | ||
|
48 | ||
|
49 | //---------------------------------------------------------------------------- | |
|
50 | // Copyright (C) 2008-2011 The IPython Development Team | |
|
51 | // | |
|
52 | // Distributed under the terms of the BSD License. The full license is in | |
|
53 | // the file COPYING, distributed as part of this software. | |
|
54 | //---------------------------------------------------------------------------- | |
|
55 | ||
|
56 | //============================================================================ | |
|
57 | // Cell | |
|
58 | //============================================================================ | |
|
59 | /** | |
|
60 | * An extendable module that provide base functionnality to create cell for notebook. | |
|
61 | * @module IPython | |
|
62 | * @namespace IPython | |
|
63 | * @submodule Cell | |
|
64 | */ | |
|
65 | ||
|
66 | var IPython = (function (IPython) { | |
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
3 | ||
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'components/jquery/jquery.min', | |
|
7 | 'components/codemirror/lib/codemirror.js', | |
|
8 | 'base/js/utils', | |
|
9 | ||
|
10 | // Set codemirror version. | |
|
11 | // CodeMirror.modeURL = '{{ static_url("components/codemirror/mode/%N/%N.js", include_version=False) }}'; | |
|
12 | 'components/codemirror/addon/mode/loadmode.js', | |
|
13 | 'components/codemirror/addon/mode/multiplex.js', | |
|
14 | 'components/codemirror/addon/mode/overlay.js', | |
|
15 | 'components/codemirror/addon/edit/matchbrackets.js', | |
|
16 | 'components/codemirror/addon/edit/closebrackets.js', | |
|
17 | 'components/codemirror/addon/comment/comment.js', | |
|
18 | 'components/codemirror/mode/htmlmixed/htmlmixed.js', | |
|
19 | 'components/codemirror/mode/xml/xml.js', | |
|
20 | 'components/codemirror/mode/javascript/javascript.js', | |
|
21 | 'components/codemirror/mode/css/css.js', | |
|
22 | 'components/codemirror/mode/rst/rst.js', | |
|
23 | 'components/codemirror/mode/markdown/markdown.js', | |
|
24 | 'components/codemirror/mode/python/python.js', | |
|
25 | 'notebook/js/codemirror-ipython.js', | |
|
26 | 'notebook/js/codemirror-ipythongfm.js', | |
|
27 | ], function(IPython, $, CodeMirror, Utils) { | |
|
67 | 28 | "use strict"; |
|
68 | 29 | |
|
69 | var utils = IPython.utils; | |
|
70 | var keycodes = IPython.keyboard.keycodes; | |
|
30 | // monkey patch CM to be able to syntax highlight cell magics | |
|
31 | // bug reported upstream, | |
|
32 | // see https://github.com/marijnh/CodeMirror2/issues/670 | |
|
33 | if(CodeMirror.getMode(1,'text/plain').indent === undefined ){ | |
|
34 | console.log('patching CM for undefined indent'); | |
|
35 | CodeMirror.modes.null = function() { | |
|
36 | return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}}; | |
|
37 | }; | |
|
38 | } | |
|
39 | ||
|
40 | CodeMirror.patchedGetMode = function(config, mode){ | |
|
41 | var cmmode = CodeMirror.getMode(config, mode); | |
|
42 | if(cmmode.indent === null) { | |
|
43 | console.log('patch mode "' , mode, '" on the fly'); | |
|
44 | cmmode.indent = function(){return 0;}; | |
|
45 | } | |
|
46 | return cmmode; | |
|
47 | }; | |
|
48 | // end monkey patching CodeMirror | |
|
71 | 49 | |
|
72 | 50 | /** |
|
73 | 51 | * The Base `Cell` class from which to inherit |
@@ -80,8 +58,8 b' var IPython = (function (IPython) {' | |||
|
80 | 58 | * @param {object|undefined} [options] |
|
81 | 59 | * @param [options.cm_config] {object} config to pass to CodeMirror, will extend default parameters |
|
82 | 60 | */ |
|
83 |
var Cell = function ( |
|
|
84 | ||
|
61 | var Cell = function (keyboard_manager) { | |
|
62 | this.keyboard_manager = keyboard_manager; | |
|
85 | 63 | options = this.mergeopt(Cell, options); |
|
86 | 64 | // superclass default overwrite our default |
|
87 | 65 | |
@@ -94,7 +72,7 b' var IPython = (function (IPython) {' | |||
|
94 | 72 | // load this from metadata later ? |
|
95 | 73 | this.user_highlight = 'auto'; |
|
96 | 74 | this.cm_config = options.cm_config; |
|
97 |
this.cell_id = |
|
|
75 | this.cell_id = Utils.uuid(); | |
|
98 | 76 | this._options = options; |
|
99 | 77 | |
|
100 | 78 | // For JS VM engines optimization, attributes should be all set (even |
@@ -130,7 +108,7 b' var IPython = (function (IPython) {' | |||
|
130 | 108 | // FIXME: Workaround CM Bug #332 (Safari segfault on drag) |
|
131 | 109 | // by disabling drag/drop altogether on Safari |
|
132 | 110 | // https://github.com/marijnh/CodeMirror/issues/332 |
|
133 |
if ( |
|
|
111 | if (Utils.browser[0] == "Safari") { | |
|
134 | 112 | Cell.options_default.cm_config.dragDrop = false; |
|
135 | 113 | } |
|
136 | 114 | |
@@ -180,27 +158,27 b' var IPython = (function (IPython) {' | |||
|
180 | 158 | // We trigger events so that Cell doesn't have to depend on Notebook. |
|
181 | 159 | that.element.click(function (event) { |
|
182 | 160 | if (!that.selected) { |
|
183 |
|
|
|
161 | that.events.trigger('select.Cell', {'cell':that}); | |
|
184 | 162 | } |
|
185 | 163 | }); |
|
186 | 164 | that.element.focusin(function (event) { |
|
187 | 165 | if (!that.selected) { |
|
188 |
|
|
|
166 | that.events.trigger('select.Cell', {'cell':that}); | |
|
189 | 167 | } |
|
190 | 168 | }); |
|
191 | 169 | if (this.code_mirror) { |
|
192 | 170 | this.code_mirror.on("change", function(cm, change) { |
|
193 |
|
|
|
171 | that.events.trigger("set_dirty.Notebook", {value: true}); | |
|
194 | 172 | }); |
|
195 | 173 | } |
|
196 | 174 | if (this.code_mirror) { |
|
197 | 175 | this.code_mirror.on('focus', function(cm, change) { |
|
198 |
|
|
|
176 | that.events.trigger('edit_mode.Cell', {cell: that}); | |
|
199 | 177 | }); |
|
200 | 178 | } |
|
201 | 179 | if (this.code_mirror) { |
|
202 | 180 | this.code_mirror.on('blur', function(cm, change) { |
|
203 |
|
|
|
181 | that.events.trigger('command_mode.Cell', {cell: that}); | |
|
204 | 182 | }); |
|
205 | 183 | } |
|
206 | 184 | }; |
@@ -219,7 +197,7 b' var IPython = (function (IPython) {' | |||
|
219 | 197 | */ |
|
220 | 198 | Cell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
221 | 199 | var that = this; |
|
222 |
var shortcuts = |
|
|
200 | var shortcuts = this.keyboard_manager.edit_shortcuts; | |
|
223 | 201 | |
|
224 | 202 | // if this is an edit_shortcuts shortcut, the global keyboard/shortcut |
|
225 | 203 | // manager will handle it |
@@ -597,9 +575,9 b' var IPython = (function (IPython) {' | |||
|
597 | 575 | this.code_mirror.setOption('mode', default_mode); |
|
598 | 576 | }; |
|
599 | 577 | |
|
578 | // Backwards compatability. | |
|
600 | 579 | IPython.Cell = Cell; |
|
601 | 580 | |
|
602 |
return |
|
|
603 | ||
|
604 | }(IPython)); | |
|
581 | return Cell; | |
|
605 | 582 | |
|
583 | }); |
@@ -1,22 +1,11 b'' | |||
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2012 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
7 | ||
|
8 | //============================================================================ | |
|
9 | // CellToolbar | |
|
10 | //============================================================================ | |
|
11 | ||
|
12 | ||
|
13 | /** | |
|
14 | * A Module to control the per-cell toolbar. | |
|
15 | * @module IPython | |
|
16 | * @namespace IPython | |
|
17 | * @submodule CellToolbar | |
|
18 | */ | |
|
19 | var IPython = (function (IPython) { | |
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
3 | ||
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'components/jquery/jquery.min', | |
|
7 | 'notebook/js/textcell', | |
|
8 | ], function(IPython, $, TextCell) { | |
|
20 | 9 | "use strict"; |
|
21 | 10 | |
|
22 | 11 | /** |
@@ -24,8 +13,10 b' var IPython = (function (IPython) {' | |||
|
24 | 13 | * @class CellToolbar |
|
25 | 14 | * @param {The cell to attach the metadata UI to} cell |
|
26 | 15 | */ |
|
27 | var CellToolbar = function (cell) { | |
|
16 | var CellToolbar = function (cell, events, notebook) { | |
|
28 | 17 | CellToolbar._instances.push(this); |
|
18 | this.notebook = notebook; | |
|
19 | this.events = events; | |
|
29 | 20 | this.cell = cell; |
|
30 | 21 | this.create_element(); |
|
31 | 22 | this.rebuild(); |
@@ -34,7 +25,7 b' var IPython = (function (IPython) {' | |||
|
34 | 25 | |
|
35 | 26 | |
|
36 | 27 | CellToolbar.prototype.create_element = function () { |
|
37 | this.inner_element = $('<div/>').addClass('celltoolbar') | |
|
28 | this.inner_element = $('<div/>').addClass('celltoolbar'); | |
|
38 | 29 | this.element = $('<div/>').addClass('ctb_hideshow') |
|
39 | 30 | .append(this.inner_element); |
|
40 | 31 | }; |
@@ -184,10 +175,10 b' var IPython = (function (IPython) {' | |||
|
184 | 175 | */ |
|
185 | 176 | CellToolbar.register_preset = function(name, preset_list) { |
|
186 | 177 | CellToolbar._presets[name] = preset_list; |
|
187 |
|
|
|
178 | this.events.trigger('preset_added.CellToolbar', {name: name}); | |
|
188 | 179 | // When "register_callback" is called by a custom extension, it may be executed after notebook is loaded. |
|
189 | 180 | // In that case, activate the preset if needed. |
|
190 |
if ( |
|
|
181 | if (this.notebook && this.notebook.metadata && this.notebook.metadata.celltoolbar === name) | |
|
191 | 182 | this.activate_preset(name); |
|
192 | 183 | }; |
|
193 | 184 | |
@@ -229,7 +220,7 b' var IPython = (function (IPython) {' | |||
|
229 | 220 | CellToolbar.rebuild_all(); |
|
230 | 221 | } |
|
231 | 222 | |
|
232 |
|
|
|
223 | this.events.trigger('preset_activated.CellToolbar', {name: preset_name}); | |
|
233 | 224 | }; |
|
234 | 225 | |
|
235 | 226 | |
@@ -283,7 +274,7 b' var IPython = (function (IPython) {' | |||
|
283 | 274 | } |
|
284 | 275 | |
|
285 | 276 | // If there are no controls or the cell is a rendered TextCell hide the toolbar. |
|
286 |
if (!this.ui_controls_list.length || (this.cell instanceof |
|
|
277 | if (!this.ui_controls_list.length || (this.cell instanceof TextCell && this.cell.rendered)) { | |
|
287 | 278 | this.hide(); |
|
288 | 279 | } else { |
|
289 | 280 | this.show(); |
@@ -415,8 +406,8 b' var IPython = (function (IPython) {' | |||
|
415 | 406 | }; |
|
416 | 407 | }; |
|
417 | 408 | |
|
418 | ||
|
409 | // Backwards compatability. | |
|
419 | 410 | IPython.CellToolbar = CellToolbar; |
|
420 | 411 | |
|
421 |
return |
|
|
422 | }(IPython)); | |
|
412 | return CellToolbar; | |
|
413 | }); |
@@ -1,3 +1,9 b'' | |||
|
1 | ||
|
2 | "notebook/js/tooltip", | |
|
3 | Tooltip, | |
|
4 | tooltip = new Tooltip(); | |
|
5 | IPython.tooltip = tooltip; | |
|
6 | ||
|
1 | 7 | //---------------------------------------------------------------------------- |
|
2 | 8 | // Copyright (C) 2008-2011 The IPython Development Team |
|
3 | 9 | // |
@@ -7,9 +7,8 b' define([' | |||
|
7 | 7 | ], function(IPython, $) { |
|
8 | 8 | "use strict"; |
|
9 | 9 | |
|
10 |
var LayoutManager = function ( |
|
|
10 | var LayoutManager = function () { | |
|
11 | 11 | this.bind_events(); |
|
12 | this.pager = pager; | |
|
13 | 12 | }; |
|
14 | 13 | |
|
15 | 14 | LayoutManager.prototype.bind_events = function () { |
@@ -39,14 +38,15 b' define([' | |||
|
39 | 38 | var app_height = this.app_height(); // content height |
|
40 | 39 | |
|
41 | 40 | $('#ipython-main-app').height(app_height); // content+padding+border height |
|
42 | ||
|
43 | var pager_height = this.pager.percentage_height*app_height; | |
|
44 | var pager_splitter_height = $('div#pager_splitter').outerHeight(true); | |
|
45 | $('div#pager').outerHeight(pager_height); | |
|
46 | if (this.pager.expanded) { | |
|
47 | $('div#notebook').outerHeight(app_height-pager_height-pager_splitter_height); | |
|
48 | } else { | |
|
49 | $('div#notebook').outerHeight(app_height-pager_splitter_height); | |
|
41 | if (this.pager) { | |
|
42 | var pager_height = this.pager.percentage_height*app_height; | |
|
43 | var pager_splitter_height = $('div#pager_splitter').outerHeight(true); | |
|
44 | $('div#pager').outerHeight(pager_height); | |
|
45 | if (this.pager.expanded) { | |
|
46 | $('div#notebook').outerHeight(app_height-pager_height-pager_splitter_height); | |
|
47 | } else { | |
|
48 | $('div#notebook').outerHeight(app_height-pager_splitter_height); | |
|
49 | } | |
|
50 | 50 | } |
|
51 | 51 | }; |
|
52 | 52 |
@@ -4,6 +4,7 b'' | |||
|
4 | 4 | var ipython = ipython || {}; |
|
5 | 5 | require([ |
|
6 | 6 | 'base/js/namespace', |
|
7 | 'components/jquery/jquery.min', | |
|
7 | 8 | 'notebook/js/notebook', |
|
8 | 9 | 'base/js/utils', |
|
9 | 10 | 'base/js/page', |
@@ -17,6 +18,7 b' require([' | |||
|
17 | 18 | 'notebook/js/notificationarea', |
|
18 | 19 | ], function( |
|
19 | 20 | IPython, |
|
21 | $, | |
|
20 | 22 | Notebook, |
|
21 | 23 | Utils, |
|
22 | 24 | Page, |
@@ -41,12 +43,13 b' require([' | |||
|
41 | 43 | }; |
|
42 | 44 | |
|
43 | 45 | page = new Page(); |
|
44 | pager = new Pager('div#pager', 'div#pager_splitter'); | |
|
45 | layout_manager = new LayoutManager(pager); | |
|
46 | events = new Events(); | |
|
46 | layout_manager = new LayoutManager(); | |
|
47 | pager = new Pager('div#pager', 'div#pager_splitter', layout_manager); | |
|
48 | layout_manager.pager = pager; | |
|
49 | events = $([new Events()]); | |
|
47 | 50 | notebook = new Notebook('div#notebook', opts, events); |
|
48 | 51 | login_widget = new LoginWidget('span#login_widget', opts); |
|
49 | toolbar = new MainToolBar('#maintoolbar-container'); | |
|
52 | toolbar = new MainToolBar('#maintoolbar-container', notebook, events); | |
|
50 | 53 | quick_help = new QuickHelp(); |
|
51 | 54 | menubar = new MenuBar('#menubar', opts); |
|
52 | 55 |
@@ -5,11 +5,13 b' define([' | |||
|
5 | 5 | 'base/js/namespace', |
|
6 | 6 | 'components/jquery/jquery.min', |
|
7 | 7 | 'notebook/js/toolbar', |
|
8 | ], function(IPython, $, Toolbar) { | |
|
8 | 'notebook/js/celltoolbar', | |
|
9 | ], function(IPython, $, Toolbar, CellToolbar) { | |
|
9 | 10 | "use strict"; |
|
10 | 11 | |
|
11 | var MainToolBar = function (selector, notebook) { | |
|
12 | var MainToolBar = function (selector, layout_manager, notebook, events) { | |
|
12 | 13 | ToolBar.apply(this, arguments); |
|
14 | this.events = events; | |
|
13 | 15 | this.notebook = notebook; |
|
14 | 16 | this.construct(); |
|
15 | 17 | this.add_celltype_list(); |
@@ -150,27 +152,27 b' define([' | |||
|
150 | 152 | select.change(function() { |
|
151 | 153 | var val = $(this).val(); |
|
152 | 154 | if (val ==='') { |
|
153 |
|
|
|
155 | CellToolbar.global_hide(); | |
|
154 | 156 | delete this.notebook.metadata.celltoolbar; |
|
155 | 157 | } else { |
|
156 |
|
|
|
157 |
|
|
|
158 | CellToolbar.global_show(); | |
|
159 | CellToolbar.activate_preset(val); | |
|
158 | 160 | this.notebook.metadata.celltoolbar = val; |
|
159 | 161 | } |
|
160 | 162 | }); |
|
161 | 163 | // Setup the currently registered presets. |
|
162 |
var presets = |
|
|
164 | var presets = CellToolbar.list_presets(); | |
|
163 | 165 | for (var i=0; i<presets.length; i++) { |
|
164 | 166 | var name = presets[i]; |
|
165 | 167 | select.append($('<option/>').attr('value', name).text(name)); |
|
166 | 168 | } |
|
167 | 169 | // Setup future preset registrations. |
|
168 |
|
|
|
170 | this.events.on('preset_added.CellToolbar', function (event, data) { | |
|
169 | 171 | var name = data.name; |
|
170 | 172 | select.append($('<option/>').attr('value', name).text(name)); |
|
171 | 173 | }); |
|
172 | 174 | // Update select value when a preset is activated. |
|
173 |
|
|
|
175 | this.events.on('preset_activated.CellToolbar', function (event, data) { | |
|
174 | 176 | if (select.val() !== data.name) |
|
175 | 177 | select.val(data.name); |
|
176 | 178 | }); |
@@ -202,7 +204,7 b' define([' | |||
|
202 | 204 | this.notebook.to_heading(undefined, 6); |
|
203 | 205 | } |
|
204 | 206 | }); |
|
205 |
|
|
|
207 | this.events.on('selected_cell_type_changed.Notebook', function (event, data) { | |
|
206 | 208 | if (data.cell_type === 'heading') { |
|
207 | 209 | that.element.find('#cell_type').val(data.cell_type+data.level); |
|
208 | 210 | } else { |
@@ -46,7 +46,7 b' define([' | |||
|
46 | 46 | * @param {Object} [events] An events object |
|
47 | 47 | */ |
|
48 | 48 | var Notebook = function (selector, options, events) { |
|
49 | this.events = events || new Events(); | |
|
49 | this.events = events || $([new Events()]); | |
|
50 | 50 | this.keyboard_manager = new KeyboardManager(); |
|
51 | 51 | this.keyboard = new Keyboard(); |
|
52 | 52 | this.save_widget = new SaveWidget('span#save_widget'); |
@@ -1,16 +1,18 b'' | |||
|
1 | 1 | // Copyright (c) IPython Development Team. |
|
2 | 2 | // Distributed under the terms of the Modified BSD License. |
|
3 | 3 | |
|
4 | //============================================================================ | |
|
5 | // Pager | |
|
6 | //============================================================================ | |
|
7 | ||
|
8 | var IPython = (function (IPython) { | |
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'components/jquery/jquery.min', | |
|
7 | 'notebook/js/toolbar', | |
|
8 | 'notebook/js/celltoolbar', | |
|
9 | ], function(IPython, $, Toolbar, CellToolbar) { | |
|
9 | 10 | "use strict"; |
|
10 | 11 | |
|
11 | 12 | var utils = IPython.utils; |
|
12 | 13 | |
|
13 | var Pager = function (pager_selector, pager_splitter_selector) { | |
|
14 | var Pager = function (pager_selector, pager_splitter_selector, layout_manager, events) { | |
|
15 | this.events = events; | |
|
14 | 16 | this.pager_element = $(pager_selector); |
|
15 | 17 | this.pager_button_area = $('#pager_button_area'); |
|
16 | 18 | var that = this; |
@@ -23,7 +25,7 b' var IPython = (function (IPython) {' | |||
|
23 | 25 | drag: function(event, ui) { |
|
24 | 26 | // recalculate the amount of space the pager should take |
|
25 | 27 | var pheight = ($(document.body).height()-event.clientY-4); |
|
26 |
var downprct = pheight/ |
|
|
28 | var downprct = pheight/layout_manager.app_height(); | |
|
27 | 29 | downprct = Math.min(0.9, downprct); |
|
28 | 30 | if (downprct < 0.1) { |
|
29 | 31 | that.percentage_height = 0.1; |
@@ -32,7 +34,7 b' var IPython = (function (IPython) {' | |||
|
32 | 34 | that.percentage_height = downprct; |
|
33 | 35 | that.expand({'duration':0}); |
|
34 | 36 | } |
|
35 |
|
|
|
37 | layout_manager.do_resize(); | |
|
36 | 38 | } |
|
37 | 39 | }); |
|
38 | 40 | this.expanded = false; |
@@ -47,22 +49,22 b' var IPython = (function (IPython) {' | |||
|
47 | 49 | $('<a>').attr('role', "button") |
|
48 | 50 | .attr('title',"Open the pager in an external window") |
|
49 | 51 | .addClass('ui-button') |
|
50 | .click(function(){that.detach()}) | |
|
52 | .click(function(){that.detach();}) | |
|
51 | 53 | .attr('style','position: absolute; right: 20px;') |
|
52 | 54 | .append( |
|
53 | 55 | $('<span>').addClass("ui-icon ui-icon-extlink") |
|
54 | 56 | ) |
|
55 | ) | |
|
57 | ); | |
|
56 | 58 | this.pager_button_area.append( |
|
57 | 59 | $('<a>').attr('role', "button") |
|
58 | 60 | .attr('title',"Close the pager") |
|
59 | 61 | .addClass('ui-button') |
|
60 | .click(function(){that.collapse()}) | |
|
62 | .click(function(){that.collapse();}) | |
|
61 | 63 | .attr('style','position: absolute; right: 5px;') |
|
62 | 64 | .append( |
|
63 | 65 | $('<span>').addClass("ui-icon ui-icon-close") |
|
64 | 66 | ) |
|
65 | ) | |
|
67 | ); | |
|
66 | 68 | }; |
|
67 | 69 | |
|
68 | 70 | Pager.prototype.style = function () { |
@@ -105,7 +107,7 b' var IPython = (function (IPython) {' | |||
|
105 | 107 | that.toggle(); |
|
106 | 108 | }); |
|
107 | 109 | |
|
108 |
|
|
|
110 | this.events.on('open_with_text.Pager', function (event, payload) { | |
|
109 | 111 | // FIXME: support other mime types |
|
110 | 112 | if (payload.data['text/plain'] && payload.data['text/plain'] !== "") { |
|
111 | 113 | that.clear(); |
@@ -171,10 +173,8 b' var IPython = (function (IPython) {' | |||
|
171 | 173 | this.pager_element.find(".container").append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text)))); |
|
172 | 174 | }; |
|
173 | 175 | |
|
174 | ||
|
176 | // Backwards compatability. | |
|
175 | 177 | IPython.Pager = Pager; |
|
176 | 178 | |
|
177 |
return |
|
|
178 | ||
|
179 | }(IPython)); | |
|
180 | ||
|
179 | return Pager; | |
|
180 | }); |
@@ -1,40 +1,27 b'' | |||
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2008-2012 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
7 | ||
|
8 | //============================================================================ | |
|
9 | // TextCell | |
|
10 | //============================================================================ | |
|
11 | ||
|
12 | ||
|
13 | ||
|
14 | /** | |
|
15 | A module that allow to create different type of Text Cell | |
|
16 | @module IPython | |
|
17 | @namespace IPython | |
|
18 | */ | |
|
19 | var IPython = (function (IPython) { | |
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
3 | ||
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'components/jquery/jquery.min', | |
|
7 | 'notebook/js/cell', | |
|
8 | 'base/js/security', | |
|
9 | ], function(IPython, $, Cell, Security) { | |
|
20 | 10 | "use strict"; |
|
21 | 11 | |
|
22 | // TextCell base class | |
|
23 | var keycodes = IPython.keyboard.keycodes; | |
|
24 | var security = IPython.security; | |
|
25 | ||
|
26 | 12 | /** |
|
27 | 13 | * Construct a new TextCell, codemirror mode is by default 'htmlmixed', and cell type is 'text' |
|
28 | 14 | * cell start as not redered. |
|
29 | 15 | * |
|
30 | 16 | * @class TextCell |
|
31 | 17 | * @constructor TextCell |
|
32 |
* @extend |
|
|
18 | * @extend Cell | |
|
33 | 19 | * @param {object|undefined} [options] |
|
34 | 20 | * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config |
|
35 | 21 | * @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass) |
|
36 | 22 | */ |
|
37 | var TextCell = function (options) { | |
|
23 | var TextCell = function (options, events, config, mathjaxutils) { | |
|
24 | // TODO: Config is IPython.config | |
|
38 | 25 | // in all TextCell/Cell subclasses |
|
39 | 26 | // do not assign most of members here, just pass it down |
|
40 | 27 | // in the options dict potentially overwriting what you wish. |
@@ -48,13 +35,14 b' var IPython = (function (IPython) {' | |||
|
48 | 35 | options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options}); |
|
49 | 36 | |
|
50 | 37 | this.cell_type = this.cell_type || 'text'; |
|
38 | this.mathjaxutils = mathjaxutils; | |
|
51 | 39 | |
|
52 |
|
|
|
40 | Cell.apply(this, [options], events); | |
|
53 | 41 | |
|
54 | 42 | this.rendered = false; |
|
55 | 43 | }; |
|
56 | 44 | |
|
57 |
TextCell.prototype = new |
|
|
45 | TextCell.prototype = new Cell(); | |
|
58 | 46 | |
|
59 | 47 | TextCell.options_default = { |
|
60 | 48 | cm_config : { |
@@ -71,7 +59,7 b' var IPython = (function (IPython) {' | |||
|
71 | 59 | * @private |
|
72 | 60 | */ |
|
73 | 61 | TextCell.prototype.create_element = function () { |
|
74 |
|
|
|
62 | Cell.prototype.create_element.apply(this, arguments); | |
|
75 | 63 | |
|
76 | 64 | var cell = $("<div>").addClass('cell text_cell border-box-sizing'); |
|
77 | 65 | cell.attr('tabindex','2'); |
@@ -79,7 +67,7 b' var IPython = (function (IPython) {' | |||
|
79 | 67 | var prompt = $('<div/>').addClass('prompt input_prompt'); |
|
80 | 68 | cell.append(prompt); |
|
81 | 69 | var inner_cell = $('<div/>').addClass('inner_cell'); |
|
82 |
this.celltoolbar = new |
|
|
70 | this.celltoolbar = new CellToolbar(this); | |
|
83 | 71 | inner_cell.append(this.celltoolbar.element); |
|
84 | 72 | var input_area = $('<div/>').addClass('input_area'); |
|
85 | 73 | this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config); |
@@ -99,12 +87,12 b' var IPython = (function (IPython) {' | |||
|
99 | 87 | * @method bind_event |
|
100 | 88 | */ |
|
101 | 89 | TextCell.prototype.bind_events = function () { |
|
102 |
|
|
|
90 | Cell.prototype.bind_events.apply(this); | |
|
103 | 91 | var that = this; |
|
104 | 92 | |
|
105 | 93 | this.element.dblclick(function () { |
|
106 | 94 | if (that.selected === false) { |
|
107 |
|
|
|
95 | this.events.trigger('select.Cell', {'cell':that}); | |
|
108 | 96 | } |
|
109 | 97 | var cont = that.unrender(); |
|
110 | 98 | if (cont) { |
@@ -116,7 +104,7 b' var IPython = (function (IPython) {' | |||
|
116 | 104 | // Cell level actions |
|
117 | 105 | |
|
118 | 106 | TextCell.prototype.select = function () { |
|
119 |
var cont = |
|
|
107 | var cont = Cell.prototype.select.apply(this); | |
|
120 | 108 | if (cont) { |
|
121 | 109 | if (this.mode === 'edit') { |
|
122 | 110 | this.code_mirror.refresh(); |
@@ -127,7 +115,7 b' var IPython = (function (IPython) {' | |||
|
127 | 115 | |
|
128 | 116 | TextCell.prototype.unrender = function () { |
|
129 | 117 | if (this.read_only) return; |
|
130 |
var cont = |
|
|
118 | var cont = Cell.prototype.unrender.apply(this); | |
|
131 | 119 | if (cont) { |
|
132 | 120 | var text_cell = this.element; |
|
133 | 121 | var output = text_cell.find("div.text_cell_render"); |
@@ -191,7 +179,7 b' var IPython = (function (IPython) {' | |||
|
191 | 179 | * @method fromJSON |
|
192 | 180 | */ |
|
193 | 181 | TextCell.prototype.fromJSON = function (data) { |
|
194 |
|
|
|
182 | Cell.prototype.fromJSON.apply(this, arguments); | |
|
195 | 183 | if (data.cell_type === this.cell_type) { |
|
196 | 184 | if (data.source !== undefined) { |
|
197 | 185 | this.set_text(data.source); |
@@ -211,7 +199,7 b' var IPython = (function (IPython) {' | |||
|
211 | 199 | * @return {object} cell data serialised to json |
|
212 | 200 | */ |
|
213 | 201 | TextCell.prototype.toJSON = function () { |
|
214 |
var data = |
|
|
202 | var data = Cell.prototype.toJSON.apply(this); | |
|
215 | 203 | data.source = this.get_text(); |
|
216 | 204 | if (data.source == this.placeholder) { |
|
217 | 205 | data.source = ""; |
@@ -245,17 +233,17 b' var IPython = (function (IPython) {' | |||
|
245 | 233 | * @method render |
|
246 | 234 | */ |
|
247 | 235 | MarkdownCell.prototype.render = function () { |
|
248 |
var cont = |
|
|
236 | var cont = TextCell.prototype.render.apply(this); | |
|
249 | 237 | if (cont) { |
|
250 | 238 | var text = this.get_text(); |
|
251 | 239 | var math = null; |
|
252 | 240 | if (text === "") { text = this.placeholder; } |
|
253 |
var text_and_math = |
|
|
241 | var text_and_math = this.mathjaxutils.remove_math(text); | |
|
254 | 242 | text = text_and_math[0]; |
|
255 | 243 | math = text_and_math[1]; |
|
256 | 244 | var html = marked.parser(marked.lexer(text)); |
|
257 |
html = |
|
|
258 |
html = |
|
|
245 | html = this.mathjaxutils.replace_math(html, math); | |
|
246 | html = Security.sanitize_html(html); | |
|
259 | 247 | html = $($.parseHTML(html)); |
|
260 | 248 | // links in markdown cells should open in new tabs |
|
261 | 249 | html.find("a[href]").not('[href^="#"]').attr("target", "_blank"); |
@@ -273,7 +261,7 b' var IPython = (function (IPython) {' | |||
|
273 | 261 | /** |
|
274 | 262 | * @class RawCell |
|
275 | 263 | * @constructor RawCell |
|
276 |
* @extends |
|
|
264 | * @extends TextCell | |
|
277 | 265 | */ |
|
278 | 266 | var RawCell = function (options) { |
|
279 | 267 | |
@@ -309,12 +297,12 b' var IPython = (function (IPython) {' | |||
|
309 | 297 | * @method auto_highlight |
|
310 | 298 | */ |
|
311 | 299 | RawCell.prototype.auto_highlight = function () { |
|
312 |
this._auto_highlight( |
|
|
300 | this._auto_highlight(config.raw_cell_highlight); | |
|
313 | 301 | }; |
|
314 | 302 | |
|
315 | 303 | /** @method render **/ |
|
316 | 304 | RawCell.prototype.render = function () { |
|
317 |
var cont = |
|
|
305 | var cont = TextCell.prototype.render.apply(this); | |
|
318 | 306 | if (cont){ |
|
319 | 307 | var text = this.get_text(); |
|
320 | 308 | if (text === "") { text = this.placeholder; } |
@@ -327,12 +315,12 b' var IPython = (function (IPython) {' | |||
|
327 | 315 | |
|
328 | 316 | /** |
|
329 | 317 | * @class HeadingCell |
|
330 |
* @extends |
|
|
318 | * @extends TextCell | |
|
331 | 319 | */ |
|
332 | 320 | |
|
333 | 321 | /** |
|
334 | 322 | * @constructor HeadingCell |
|
335 |
* @extends |
|
|
323 | * @extends TextCell | |
|
336 | 324 | */ |
|
337 | 325 | var HeadingCell = function (options) { |
|
338 | 326 | options = this.mergeopt(HeadingCell, options); |
@@ -412,22 +400,21 b' var IPython = (function (IPython) {' | |||
|
412 | 400 | return r.children().first().html(); |
|
413 | 401 | }; |
|
414 | 402 | |
|
415 | ||
|
416 | 403 | HeadingCell.prototype.render = function () { |
|
417 |
var cont = |
|
|
404 | var cont = TextCell.prototype.render.apply(this); | |
|
418 | 405 | if (cont) { |
|
419 | 406 | var text = this.get_text(); |
|
420 | 407 | var math = null; |
|
421 | 408 | // Markdown headings must be a single line |
|
422 | 409 | text = text.replace(/\n/g, ' '); |
|
423 | 410 | if (text === "") { text = this.placeholder; } |
|
424 | text = Array(this.level + 1).join("#") + " " + text; | |
|
425 |
var text_and_math = |
|
|
411 | text = new Array(this.level + 1).join("#") + " " + text; | |
|
412 | var text_and_math = this.mathjaxutils.remove_math(text); | |
|
426 | 413 | text = text_and_math[0]; |
|
427 | 414 | math = text_and_math[1]; |
|
428 | 415 | var html = marked.parser(marked.lexer(text)); |
|
429 |
html = |
|
|
430 |
html = |
|
|
416 | html = this.mathjaxutils.replace_math(html, math); | |
|
417 | html = Security.sanitize_html(html); | |
|
431 | 418 | var h = $($.parseHTML(html)); |
|
432 | 419 | // add id and linkback anchor |
|
433 | 420 | var hash = h.text().replace(/ /g, '-'); |
@@ -446,14 +433,17 b' var IPython = (function (IPython) {' | |||
|
446 | 433 | return cont; |
|
447 | 434 | }; |
|
448 | 435 | |
|
449 | // TODO: RETURN IN THIS NAMESPACE! | |
|
436 | // Backwards compatability. | |
|
450 | 437 | IPython.TextCell = TextCell; |
|
451 | 438 | IPython.MarkdownCell = MarkdownCell; |
|
452 | 439 | IPython.RawCell = RawCell; |
|
453 | 440 | IPython.HeadingCell = HeadingCell; |
|
454 | 441 | |
|
455 | ||
|
456 | return IPython; | |
|
457 | ||
|
458 | }(IPython)); | |
|
459 | ||
|
442 | Cells = { | |
|
443 | 'TextCell': TextCell, | |
|
444 | 'MarkdownCell': MarkdownCell, | |
|
445 | 'RawCell': RawCell, | |
|
446 | 'HeadingCell': HeadingCell, | |
|
447 | }; | |
|
448 | return Cells; | |
|
449 | }); |
@@ -1,20 +1,10 b'' | |||
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2008 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
7 | 3 | |
|
8 | //============================================================================ | |
|
9 | // ToolBar | |
|
10 | //============================================================================ | |
|
11 | /** | |
|
12 | * @module IPython | |
|
13 | * @namespace IPython | |
|
14 | * @submodule ToolBar | |
|
15 | */ | |
|
16 | ||
|
17 | var IPython = (function (IPython) { | |
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'components/jquery/jquery.min', | |
|
7 | ], function(IPython, $) { | |
|
18 | 8 | "use strict"; |
|
19 | 9 | |
|
20 | 10 | /** |
@@ -23,8 +13,9 b' var IPython = (function (IPython) {' | |||
|
23 | 13 | * @constructor |
|
24 | 14 | * @param {Dom object} selector |
|
25 | 15 | */ |
|
26 | var ToolBar = function (selector) { | |
|
16 | var ToolBar = function (selector, layout_manager) { | |
|
27 | 17 | this.selector = selector; |
|
18 | this.layout_manager = layout_manager; | |
|
28 | 19 | if (this.selector !== undefined) { |
|
29 | 20 | this.element = $(selector); |
|
30 | 21 | this.style(); |
@@ -98,14 +89,13 b' var IPython = (function (IPython) {' | |||
|
98 | 89 | */ |
|
99 | 90 | ToolBar.prototype.toggle = function () { |
|
100 | 91 | this.element.toggle(); |
|
101 |
if ( |
|
|
102 |
|
|
|
92 | if (this.layout_manager !== undefined) { | |
|
93 | this.layout_manager.do_resize(); | |
|
103 | 94 | } |
|
104 | 95 | }; |
|
105 | 96 | |
|
106 | ||
|
97 | // Backwards compatability. | |
|
107 | 98 | IPython.ToolBar = ToolBar; |
|
108 | 99 | |
|
109 |
return |
|
|
110 | ||
|
111 | }(IPython)); | |
|
100 | return Toolbar; | |
|
101 | }); |
@@ -33,7 +33,7 b' require([' | |||
|
33 | 33 | base_url: Utils.get_body_data("baseUrl"), |
|
34 | 34 | notebook_path: Utils.get_body_data("notebookPath"), |
|
35 | 35 | }; |
|
36 | events = new Events(); | |
|
36 | events = $([new Events()]); | |
|
37 | 37 | session_list = new SesssionList(opts, events); |
|
38 | 38 | notebook_list = new NotebookList('#notebook_list', opts, undefined, session_list); |
|
39 | 39 | cluster_list = new ClusterList('#cluster_list', opts); |
General Comments 0
You need to be logged in to leave comments.
Login now