##// END OF EJS Templates
Merge pull request #5980 from jdfreder/requirejs...
Min RK -
r17220:b80b3bcc merge
parent child Browse files
Show More
@@ -15,6 +15,7 b' before_install:'
15 - time sudo apt-get update
15 - time sudo apt-get update
16 - time sudo apt-get install pandoc casperjs nodejs libzmq3-dev
16 - time sudo apt-get install pandoc casperjs nodejs libzmq3-dev
17 - time pip install -f https://nipy.bic.berkeley.edu/wheelhouse/travis jinja2 sphinx pygments tornado requests mock pyzmq jsonschema jsonpointer
17 - time pip install -f https://nipy.bic.berkeley.edu/wheelhouse/travis jinja2 sphinx pygments tornado requests mock pyzmq jsonschema jsonpointer
18 - time npm install -g requirejs jquery
18 install:
19 install:
19 - time python setup.py install -q
20 - time python setup.py install -q
20 script:
21 script:
@@ -1,21 +1,12 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 var ipython = ipython || {};
9 // On document ready
5 require(['base/js/page'], function(page) {
10 //============================================================================
6 var page_instance = new page.Page();
11
12
13 $(document).ready(function () {
14
15 IPython.page = new IPython.Page();
16 $('button#login_submit').addClass("btn btn-default");
7 $('button#login_submit').addClass("btn btn-default");
17 IPython.page.show();
8 page_instance.show();
18 $('input#password_input').focus();
9 $('input#password_input').focus();
19
10
11 ipython.page = page_instance;
20 });
12 });
21
@@ -1,20 +1,16 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'base/js/utils',
7
7 'jquery',
8 //============================================================================
8 ], function(IPython, utils, $){
9 // Login button
10 //============================================================================
11
12 var IPython = (function (IPython) {
13 "use strict";
9 "use strict";
14
10
15 var LoginWidget = function (selector, options) {
11 var LoginWidget = function (selector, options) {
16 options = options || {};
12 options = options || {};
17 this.base_url = options.base_url || IPython.utils.get_body_data("baseUrl");
13 this.base_url = options.base_url || utils.get_body_data("baseUrl");
18 this.selector = selector;
14 this.selector = selector;
19 if (this.selector !== undefined) {
15 if (this.selector !== undefined) {
20 this.element = $(selector);
16 this.element = $(selector);
@@ -31,13 +27,13 b' var IPython = (function (IPython) {'
31 LoginWidget.prototype.bind_events = function () {
27 LoginWidget.prototype.bind_events = function () {
32 var that = this;
28 var that = this;
33 this.element.find("button#logout").click(function () {
29 this.element.find("button#logout").click(function () {
34 window.location = IPython.utils.url_join_encode(
30 window.location = utils.url_join_encode(
35 that.base_url,
31 that.base_url,
36 "logout"
32 "logout"
37 );
33 );
38 });
34 });
39 this.element.find("button#login").click(function () {
35 this.element.find("button#login").click(function () {
40 window.location = IPython.utils.url_join_encode(
36 window.location = utils.url_join_encode(
41 that.base_url,
37 that.base_url,
42 "login"
38 "login"
43 );
39 );
@@ -47,6 +43,5 b' var IPython = (function (IPython) {'
47 // Set module variables
43 // Set module variables
48 IPython.LoginWidget = LoginWidget;
44 IPython.LoginWidget = LoginWidget;
49
45
50 return IPython;
46 return {'LoginWidget': LoginWidget};
51
47 }); No newline at end of file
52 }(IPython));
@@ -1,20 +1,11 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 var ipython = ipython || {};
9 // On document ready
5 require(['base/js/page'], function(page) {
10 //============================================================================
6 var page_instance = new page.Page();
11
12
13 $(document).ready(function () {
14
15 IPython.page = new IPython.Page();
16 $('#ipython-main-app').addClass('border-box-sizing');
7 $('#ipython-main-app').addClass('border-box-sizing');
17 IPython.page.show();
8 page_instance.show();
18
9
10 ipython.page = page_instance;
19 });
11 });
20
@@ -1,20 +1,14 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Utility for modal dialogs with bootstrap
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11
7 ], function(IPython, $) {
12 IPython.namespace('IPython.dialog');
13
14 IPython.dialog = (function (IPython) {
15 "use strict";
8 "use strict";
16
9
17 var modal = function (options) {
10 var modal = function (options) {
11
18 var modal = $("<div/>")
12 var modal = $("<div/>")
19 .addClass("modal")
13 .addClass("modal")
20 .addClass("fade")
14 .addClass("fade")
@@ -79,26 +73,28 b' IPython.dialog = (function (IPython) {'
79 });
73 });
80 }
74 }
81 modal.on("hidden.bs.modal", function () {
75 modal.on("hidden.bs.modal", function () {
82 if (IPython.notebook) {
76 if (options.notebook) {
83 var cell = IPython.notebook.get_selected_cell();
77 var cell = options.notebook.get_selected_cell();
84 if (cell) cell.select();
78 if (cell) cell.select();
85 IPython.keyboard_manager.enable();
79 }
86 IPython.keyboard_manager.command_mode();
80 if (options.keyboard_manager) {
81 options.keyboard_manager.enable();
82 options.keyboard_manager.command_mode();
87 }
83 }
88 });
84 });
89
85
90 if (IPython.keyboard_manager) {
86 if (options.keyboard_manager) {
91 IPython.keyboard_manager.disable();
87 options.keyboard_manager.disable();
92 }
88 }
93
89
94 return modal.modal(options);
90 return modal.modal(options);
95 };
91 };
96
92
97 var edit_metadata = function (md, callback, name) {
93 var edit_metadata = function (options) {
98 name = name || "Cell";
94 options.name = options.name || "Cell";
99 var error_div = $('<div/>').css('color', 'red');
95 var error_div = $('<div/>').css('color', 'red');
100 var message =
96 var message =
101 "Manually edit the JSON below to manipulate the metadata for this " + name + "." +
97 "Manually edit the JSON below to manipulate the metadata for this " + options.name + "." +
102 " We recommend putting custom metadata attributes in an appropriately named sub-structure," +
98 " We recommend putting custom metadata attributes in an appropriately named sub-structure," +
103 " so they don't conflict with those of others.";
99 " so they don't conflict with those of others.";
104
100
@@ -106,7 +102,7 b' IPython.dialog = (function (IPython) {'
106 .attr('rows', '13')
102 .attr('rows', '13')
107 .attr('cols', '80')
103 .attr('cols', '80')
108 .attr('name', 'metadata')
104 .attr('name', 'metadata')
109 .text(JSON.stringify(md || {}, null, 2));
105 .text(JSON.stringify(options.md || {}, null, 2));
110
106
111 var dialogform = $('<div/>').attr('title', 'Edit the metadata')
107 var dialogform = $('<div/>').attr('title', 'Edit the metadata')
112 .append(
108 .append(
@@ -128,8 +124,8 b' IPython.dialog = (function (IPython) {'
128 autoIndent: true,
124 autoIndent: true,
129 mode: 'application/json',
125 mode: 'application/json',
130 });
126 });
131 var modal = IPython.dialog.modal({
127 var modal = modal({
132 title: "Edit " + name + " Metadata",
128 title: "Edit " + options.name + " Metadata",
133 body: dialogform,
129 body: dialogform,
134 buttons: {
130 buttons: {
135 OK: { class : "btn-primary",
131 OK: { class : "btn-primary",
@@ -143,19 +139,25 b' IPython.dialog = (function (IPython) {'
143 error_div.text('WARNING: Could not save invalid JSON.');
139 error_div.text('WARNING: Could not save invalid JSON.');
144 return false;
140 return false;
145 }
141 }
146 callback(new_md);
142 options.callback(new_md);
147 }
143 }
148 },
144 },
149 Cancel: {}
145 Cancel: {}
150 }
146 },
147 notebook: options.notebook,
148 keyboard_manager: options.keyboard_manager,
151 });
149 });
152
150
153 modal.on('shown.bs.modal', function(){ editor.refresh(); });
151 modal.on('shown.bs.modal', function(){ editor.refresh(); });
154 };
152 };
155
153
156 return {
154 var dialog = {
157 modal : modal,
155 modal : modal,
158 edit_metadata : edit_metadata,
156 edit_metadata : edit_metadata,
159 };
157 };
160
158
161 }(IPython));
159 // Backwards compatability.
160 IPython.dialog = dialog;
161
162 return dialog;
163 });
@@ -1,13 +1,5 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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 // Events
10 //============================================================================
11
3
12 // Give us an object to bind all events to. This object should be created
4 // Give us an object to bind all events to. This object should be created
13 // before all other objects so it exists when others register event handlers.
5 // before all other objects so it exists when others register event handlers.
@@ -15,18 +7,13 b''
15 // $([IPython.events]).trigger('event.Namespace');
7 // $([IPython.events]).trigger('event.Namespace');
16 // To handle it:
8 // To handle it:
17 // $([IPython.events]).on('event.Namespace',function () {});
9 // $([IPython.events]).on('event.Namespace',function () {});
18
10 define(['base/js/namespace'], function(IPython) {
19 var IPython = (function (IPython) {
20 "use strict";
11 "use strict";
21
12
22 var utils = IPython.utils;
23
24 var Events = function () {};
13 var Events = function () {};
25
14
15 // Backwards compatability.
26 IPython.Events = Events;
16 IPython.Events = Events;
27 IPython.events = new Events();
17
28
18 return {'Events': Events};
29 return IPython;
19 });
30
31 }(IPython));
32
@@ -1,19 +1,14 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Keyboard management
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11
7 'base/js/utils',
12 IPython.namespace('IPython.keyboard');
8 ], function(IPython, $, utils) {
13
14 IPython.keyboard = (function (IPython) {
15 "use strict";
9 "use strict";
16
10
11
17 // Setup global keycodes and inverse keycodes.
12 // Setup global keycodes and inverse keycodes.
18
13
19 // See http://unixpapa.com/js/key.html for a complete description. The short of
14 // See http://unixpapa.com/js/key.html for a complete description. The short of
@@ -51,8 +46,8 b' IPython.keyboard = (function (IPython) {'
51 '; :': 186, '= +': 187, '- _': 189
46 '; :': 186, '= +': 187, '- _': 189
52 };
47 };
53
48
54 var browser = IPython.utils.browser[0];
49 var browser = utils.browser[0];
55 var platform = IPython.utils.platform;
50 var platform = utils.platform;
56
51
57 if (browser === 'Firefox' || browser === 'Opera' || browser === 'Netscape') {
52 if (browser === 'Firefox' || browser === 'Opera' || browser === 'Netscape') {
58 $.extend(_keycodes, _mozilla_keycodes);
53 $.extend(_keycodes, _mozilla_keycodes);
@@ -130,18 +125,19 b' IPython.keyboard = (function (IPython) {'
130
125
131 // Shortcut manager class
126 // Shortcut manager class
132
127
133 var ShortcutManager = function (delay) {
128 var ShortcutManager = function (delay, events) {
134 this._shortcuts = {};
129 this._shortcuts = {};
135 this._counts = {};
130 this._counts = {};
136 this._timers = {};
131 this._timers = {};
137 this.delay = delay || 800; // delay in milliseconds
132 this.delay = delay || 800; // delay in milliseconds
133 this.events = events;
138 };
134 };
139
135
140 ShortcutManager.prototype.help = function () {
136 ShortcutManager.prototype.help = function () {
141 var help = [];
137 var help = [];
142 for (var shortcut in this._shortcuts) {
138 for (var shortcut in this._shortcuts) {
143 var help_string = this._shortcuts[shortcut]['help'];
139 var help_string = this._shortcuts[shortcut].help;
144 var help_index = this._shortcuts[shortcut]['help_index'];
140 var help_index = this._shortcuts[shortcut].help_index;
145 if (help_string) {
141 if (help_string) {
146 if (platform === 'MacOS') {
142 if (platform === 'MacOS') {
147 shortcut = shortcut.replace('meta', 'cmd');
143 shortcut = shortcut.replace('meta', 'cmd');
@@ -182,7 +178,7 b' IPython.keyboard = (function (IPython) {'
182 this._shortcuts[shortcut] = data;
178 this._shortcuts[shortcut] = data;
183 if (!suppress_help_update) {
179 if (!suppress_help_update) {
184 // update the keyboard shortcuts notebook help
180 // update the keyboard shortcuts notebook help
185 $([IPython.events]).trigger('rebuild.QuickHelp');
181 this.events.trigger('rebuild.QuickHelp');
186 }
182 }
187 };
183 };
188
184
@@ -191,7 +187,7 b' IPython.keyboard = (function (IPython) {'
191 this.add_shortcut(shortcut, data[shortcut], true);
187 this.add_shortcut(shortcut, data[shortcut], true);
192 }
188 }
193 // update the keyboard shortcuts notebook help
189 // update the keyboard shortcuts notebook help
194 $([IPython.events]).trigger('rebuild.QuickHelp');
190 this.events.trigger('rebuild.QuickHelp');
195 };
191 };
196
192
197 ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) {
193 ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) {
@@ -200,7 +196,7 b' IPython.keyboard = (function (IPython) {'
200 delete this._shortcuts[shortcut];
196 delete this._shortcuts[shortcut];
201 if (!suppress_help_update) {
197 if (!suppress_help_update) {
202 // update the keyboard shortcuts notebook help
198 // update the keyboard shortcuts notebook help
203 $([IPython.events]).trigger('rebuild.QuickHelp');
199 this.events.trigger('rebuild.QuickHelp');
204 }
200 }
205 };
201 };
206
202
@@ -211,7 +207,7 b' IPython.keyboard = (function (IPython) {'
211 var timer = null;
207 var timer = null;
212 if (c[shortcut] === data.count-1) {
208 if (c[shortcut] === data.count-1) {
213 c[shortcut] = 0;
209 c[shortcut] = 0;
214 var timer = t[shortcut];
210 timer = t[shortcut];
215 if (timer) {clearTimeout(timer); delete t[shortcut];}
211 if (timer) {clearTimeout(timer); delete t[shortcut];}
216 return data.handler(event);
212 return data.handler(event);
217 } else {
213 } else {
@@ -228,7 +224,7 b' IPython.keyboard = (function (IPython) {'
228 var shortcut = event_to_shortcut(event);
224 var shortcut = event_to_shortcut(event);
229 var data = this._shortcuts[shortcut];
225 var data = this._shortcuts[shortcut];
230 if (data) {
226 if (data) {
231 var handler = data['handler'];
227 var handler = data.handler;
232 if (handler) {
228 if (handler) {
233 if (data.count === 1) {
229 if (data.count === 1) {
234 return handler(event);
230 return handler(event);
@@ -243,10 +239,10 b' IPython.keyboard = (function (IPython) {'
243 ShortcutManager.prototype.handles = function (event) {
239 ShortcutManager.prototype.handles = function (event) {
244 var shortcut = event_to_shortcut(event);
240 var shortcut = event_to_shortcut(event);
245 var data = this._shortcuts[shortcut];
241 var data = this._shortcuts[shortcut];
246 return !( data === undefined || data.handler === undefined )
242 return !( data === undefined || data.handler === undefined );
247 }
243 };
248
244
249 return {
245 var keyboard = {
250 keycodes : keycodes,
246 keycodes : keycodes,
251 inv_keycodes : inv_keycodes,
247 inv_keycodes : inv_keycodes,
252 ShortcutManager : ShortcutManager,
248 ShortcutManager : ShortcutManager,
@@ -256,4 +252,8 b' IPython.keyboard = (function (IPython) {'
256 event_to_shortcut : event_to_shortcut
252 event_to_shortcut : event_to_shortcut
257 };
253 };
258
254
259 }(IPython));
255 // For backwards compatability.
256 IPython.keyboard = keyboard;
257
258 return keyboard;
259 });
@@ -1,34 +1,8 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 var IPython = IPython || {};
4 var IPython = IPython || {};
9
5 define([], function(){
10 IPython.version = "3.0.0-dev";
6 IPython.version = "3.0.0-dev";
11
7 return IPython;
12 IPython.namespace = function (ns_string) {
8 });
13 "use strict";
14
15 var parts = ns_string.split('.'),
16 parent = IPython,
17 i;
18
19 // String redundant leading global
20 if (parts[0] === "IPython") {
21 parts = parts.slice(1);
22 }
23
24 for (i=0; i<parts.length; i+=1) {
25 // Create property if it doesn't exist
26 if (typeof parent[parts[i]] === "undefined") {
27 parent[parts[i]] = {};
28 }
29 }
30 return parent;
31 };
32
33
34
@@ -1,15 +1,10 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 ], function(IPython, $){
8 //============================================================================
9 // Global header/site setup.
10 //============================================================================
11
12 var IPython = (function (IPython) {
13 "use strict";
8 "use strict";
14
9
15 var Page = function () {
10 var Page = function () {
@@ -22,11 +17,9 b' var IPython = (function (IPython) {'
22 $('div#site').addClass('border-box-sizing');
17 $('div#site').addClass('border-box-sizing');
23 };
18 };
24
19
25
26 Page.prototype.bind_events = function () {
20 Page.prototype.bind_events = function () {
27 };
21 };
28
22
29
30 Page.prototype.show = function () {
23 Page.prototype.show = function () {
31 // The header and site divs start out hidden to prevent FLOUC.
24 // The header and site divs start out hidden to prevent FLOUC.
32 // Main scripts should call this method after styling everything.
25 // Main scripts should call this method after styling everything.
@@ -34,23 +27,19 b' var IPython = (function (IPython) {'
34 this.show_site();
27 this.show_site();
35 };
28 };
36
29
37
38 Page.prototype.show_header = function () {
30 Page.prototype.show_header = function () {
39 // The header and site divs start out hidden to prevent FLOUC.
31 // The header and site divs start out hidden to prevent FLOUC.
40 // Main scripts should call this method after styling everything.
32 // Main scripts should call this method after styling everything.
41 $('div#header').css('display','block');
33 $('div#header').css('display','block');
42 };
34 };
43
35
44
45 Page.prototype.show_site = function () {
36 Page.prototype.show_site = function () {
46 // The header and site divs start out hidden to prevent FLOUC.
37 // The header and site divs start out hidden to prevent FLOUC.
47 // Main scripts should call this method after styling everything.
38 // Main scripts should call this method after styling everything.
48 $('div#site').css('display','block');
39 $('div#site').css('display','block');
49 };
40 };
50
41
51
42 // Register self in the global namespace for convenience.
52 IPython.Page = Page;
43 IPython.Page = Page;
53
44 return {'Page': Page};
54 return IPython;
45 });
55
56 }(IPython));
@@ -1,20 +1,7 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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 // On document ready
10 //============================================================================
11
12
13 $(document).ready(function () {
14 "use strict";
15
16 IPython.page = new IPython.Page();
17 IPython.page.show();
18
3
4 require(['base/js/page'], function(page) {
5 var page_instance = new page.Page();
6 page_instance.show();
19 });
7 });
20
@@ -1,19 +1,12 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2014 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Utilities
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11 IPython.namespace('IPython.security');
7 'components/google-caja/html-css-sanitizer-minified',
12
8 ], function(IPython, $) {
13 IPython.security = (function (IPython) {
14 "use strict";
9 "use strict";
15
16 var utils = IPython.utils;
17
10
18 var noop = function (x) { return x; };
11 var noop = function (x) { return x; };
19
12
@@ -117,10 +110,12 b' IPython.security = (function (IPython) {'
117 return sanitized;
110 return sanitized;
118 };
111 };
119
112
120 return {
113 var security = {
121 caja: caja,
114 caja: caja,
122 sanitize_html: sanitize_html
115 sanitize_html: sanitize_html
123 };
116 };
124
117
125 }(IPython));
118 IPython.security = security;
126
119
120 return security;
121 });
@@ -1,13 +1,10 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 //============================================================================
4 define([
5 // Utilities
5 'base/js/namespace',
6 //============================================================================
6 'jquery',
7
7 ], function(IPython, $){
8 IPython.namespace('IPython.utils');
9
10 IPython.utils = (function (IPython) {
11 "use strict";
8 "use strict";
12
9
13 IPython.load_extensions = function () {
10 IPython.load_extensions = function () {
@@ -528,8 +525,8 b' IPython.utils = (function (IPython) {'
528 }
525 }
529 console.log(msg);
526 console.log(msg);
530 };
527 };
531
528
532 return {
529 var utils = {
533 regex_split : regex_split,
530 regex_split : regex_split,
534 uuid : uuid,
531 uuid : uuid,
535 fixConsole : fixConsole,
532 fixConsole : fixConsole,
@@ -553,5 +550,8 b' IPython.utils = (function (IPython) {'
553 log_ajax_error : log_ajax_error,
550 log_ajax_error : log_ajax_error,
554 };
551 };
555
552
556 }(IPython));
553 // Backwards compatability.
557
554 IPython.utils = utils;
555
556 return utils;
557 });
@@ -17,7 +17,7 b''
17 * Create a custom button in toolbar that execute `%qtconsole` in kernel
17 * Create a custom button in toolbar that execute `%qtconsole` in kernel
18 * and hence open a qtconsole attached to the same kernel as the current notebook
18 * and hence open a qtconsole attached to the same kernel as the current notebook
19 *
19 *
20 * $([IPython.events]).on('app_initialized.NotebookApp', function(){
20 * IPython.events.on('app_initialized.NotebookApp', function(){
21 * IPython.toolbar.add_buttons_group([
21 * IPython.toolbar.add_buttons_group([
22 * {
22 * {
23 * 'label' : 'run qtconsole',
23 * 'label' : 'run qtconsole',
@@ -35,7 +35,7 b''
35 * At the completion of the dashboard loading, load an unofficial javascript extension
35 * At the completion of the dashboard loading, load an unofficial javascript extension
36 * that is installed in profile/static/custom/
36 * that is installed in profile/static/custom/
37 *
37 *
38 * $([IPython.events]).on('app_initialized.DashboardApp', function(){
38 * IPython.events.on('app_initialized.DashboardApp', function(){
39 * require(['custom/unofficial_extension.js'])
39 * require(['custom/unofficial_extension.js'])
40 * });
40 * });
41 *
41 *
@@ -122,4 +122,4 b' dateFormat.i18n = {'
122 // For convenience...
122 // For convenience...
123 Date.prototype.format = function (mask, utc) {
123 Date.prototype.format = function (mask, utc) {
124 return dateFormat(this, mask, utc);
124 return dateFormat(this, mask, utc);
125 };
125 }; No newline at end of file
@@ -1,53 +1,60 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'base/js/utils',
8 //============================================================================
8 ], function(IPython, $, utils) {
9 // Cell
10 //============================================================================
11 /**
12 * An extendable module that provide base functionnality to create cell for notebook.
13 * @module IPython
14 * @namespace IPython
15 * @submodule Cell
16 */
17
18 var IPython = (function (IPython) {
19 "use strict";
9 "use strict";
20
10
21 var utils = IPython.utils;
11 // monkey patch CM to be able to syntax highlight cell magics
22 var keycodes = IPython.keyboard.keycodes;
12 // bug reported upstream,
13 // see https://github.com/marijnh/CodeMirror2/issues/670
14 if(CodeMirror.getMode(1,'text/plain').indent === undefined ){
15 CodeMirror.modes.null = function() {
16 return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}};
17 };
18 }
23
19
24 /**
20 CodeMirror.patchedGetMode = function(config, mode){
25 * The Base `Cell` class from which to inherit
21 var cmmode = CodeMirror.getMode(config, mode);
26 * @class Cell
22 if(cmmode.indent === null) {
27 **/
23 console.log('patch mode "' , mode, '" on the fly');
24 cmmode.indent = function(){return 0;};
25 }
26 return cmmode;
27 };
28 // end monkey patching CodeMirror
28
29
29 /*
30 * @constructor
31 *
32 * @param {object|undefined} [options]
33 * @param [options.cm_config] {object} config to pass to CodeMirror, will extend default parameters
34 */
35 var Cell = function (options) {
30 var Cell = function (options) {
36
31 // Constructor
37 options = this.mergeopt(Cell, options);
32 //
33 // The Base `Cell` class from which to inherit.
34 //
35 // Parameters:
36 // options: dictionary
37 // Dictionary of keyword arguments.
38 // events: $(Events) instance
39 // config: dictionary
40 // keyboard_manager: KeyboardManager instance
41 options = options || {};
42 this.keyboard_manager = options.keyboard_manager;
43 this.events = options.events;
44 var config = this.mergeopt(Cell, options.config);
38 // superclass default overwrite our default
45 // superclass default overwrite our default
39
46
40 this.placeholder = options.placeholder || '';
47 this.placeholder = config.placeholder || '';
41 this.read_only = options.cm_config.readOnly;
48 this.read_only = config.cm_config.readOnly;
42 this.selected = false;
49 this.selected = false;
43 this.rendered = false;
50 this.rendered = false;
44 this.mode = 'command';
51 this.mode = 'command';
45 this.metadata = {};
52 this.metadata = {};
46 // load this from metadata later ?
53 // load this from metadata later ?
47 this.user_highlight = 'auto';
54 this.user_highlight = 'auto';
48 this.cm_config = options.cm_config;
55 this.cm_config = config.cm_config;
49 this.cell_id = utils.uuid();
56 this.cell_id = utils.uuid();
50 this._options = options;
57 this._options = config;
51
58
52 // For JS VM engines optimization, attributes should be all set (even
59 // For JS VM engines optimization, attributes should be all set (even
53 // to null) in the constructor, and if possible, if different subclass
60 // to null) in the constructor, and if possible, if different subclass
@@ -132,27 +139,27 b' var IPython = (function (IPython) {'
132 // We trigger events so that Cell doesn't have to depend on Notebook.
139 // We trigger events so that Cell doesn't have to depend on Notebook.
133 that.element.click(function (event) {
140 that.element.click(function (event) {
134 if (!that.selected) {
141 if (!that.selected) {
135 $([IPython.events]).trigger('select.Cell', {'cell':that});
142 that.events.trigger('select.Cell', {'cell':that});
136 }
143 }
137 });
144 });
138 that.element.focusin(function (event) {
145 that.element.focusin(function (event) {
139 if (!that.selected) {
146 if (!that.selected) {
140 $([IPython.events]).trigger('select.Cell', {'cell':that});
147 that.events.trigger('select.Cell', {'cell':that});
141 }
148 }
142 });
149 });
143 if (this.code_mirror) {
150 if (this.code_mirror) {
144 this.code_mirror.on("change", function(cm, change) {
151 this.code_mirror.on("change", function(cm, change) {
145 $([IPython.events]).trigger("set_dirty.Notebook", {value: true});
152 that.events.trigger("set_dirty.Notebook", {value: true});
146 });
153 });
147 }
154 }
148 if (this.code_mirror) {
155 if (this.code_mirror) {
149 this.code_mirror.on('focus', function(cm, change) {
156 this.code_mirror.on('focus', function(cm, change) {
150 $([IPython.events]).trigger('edit_mode.Cell', {cell: that});
157 that.events.trigger('edit_mode.Cell', {cell: that});
151 });
158 });
152 }
159 }
153 if (this.code_mirror) {
160 if (this.code_mirror) {
154 this.code_mirror.on('blur', function(cm, change) {
161 this.code_mirror.on('blur', function(cm, change) {
155 $([IPython.events]).trigger('command_mode.Cell', {cell: that});
162 that.events.trigger('command_mode.Cell', {cell: that});
156 });
163 });
157 }
164 }
158 };
165 };
@@ -171,7 +178,7 b' var IPython = (function (IPython) {'
171 */
178 */
172 Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
179 Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
173 var that = this;
180 var that = this;
174 var shortcuts = IPython.keyboard_manager.edit_shortcuts;
181 var shortcuts = this.keyboard_manager.edit_shortcuts;
175
182
176 // if this is an edit_shortcuts shortcut, the global keyboard/shortcut
183 // if this is an edit_shortcuts shortcut, the global keyboard/shortcut
177 // manager will handle it
184 // manager will handle it
@@ -549,9 +556,8 b' var IPython = (function (IPython) {'
549 this.code_mirror.setOption('mode', default_mode);
556 this.code_mirror.setOption('mode', default_mode);
550 };
557 };
551
558
559 // Backwards compatability.
552 IPython.Cell = Cell;
560 IPython.Cell = Cell;
553
561
554 return IPython;
562 return {'Cell': Cell};
555
563 });
556 }(IPython));
557
@@ -1,32 +1,25 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 ], function(IPython, $) {
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) {
20 "use strict";
8 "use strict";
21
9
22 /**
10 var CellToolbar = function (options) {
23 * @constructor
11 // Constructor
24 * @class CellToolbar
12 //
25 * @param {The cell to attach the metadata UI to} cell
13 // Parameters:
26 */
14 // options: dictionary
27 var CellToolbar = function (cell) {
15 // Dictionary of keyword arguments.
16 // events: $(Events) instance
17 // cell: Cell instance
18 // notebook: Notebook instance
28 CellToolbar._instances.push(this);
19 CellToolbar._instances.push(this);
29 this.cell = cell;
20 this.notebook = options.notebook;
21 this.events = options.events;
22 this.cell = options.cell;
30 this.create_element();
23 this.create_element();
31 this.rebuild();
24 this.rebuild();
32 return this;
25 return this;
@@ -34,7 +27,7 b' var IPython = (function (IPython) {'
34
27
35
28
36 CellToolbar.prototype.create_element = function () {
29 CellToolbar.prototype.create_element = function () {
37 this.inner_element = $('<div/>').addClass('celltoolbar')
30 this.inner_element = $('<div/>').addClass('celltoolbar');
38 this.element = $('<div/>').addClass('ctb_hideshow')
31 this.element = $('<div/>').addClass('ctb_hideshow')
39 .append(this.inner_element);
32 .append(this.inner_element);
40 };
33 };
@@ -182,13 +175,13 b' var IPython = (function (IPython) {'
182 * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
175 * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
183 * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
176 * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
184 */
177 */
185 CellToolbar.register_preset = function(name, preset_list) {
178 CellToolbar.register_preset = function(name, preset_list, notebook, events) {
186 CellToolbar._presets[name] = preset_list;
179 CellToolbar._presets[name] = preset_list;
187 $([IPython.events]).trigger('preset_added.CellToolbar', {name: name});
180 events.trigger('preset_added.CellToolbar', {name: name});
188 // When "register_callback" is called by a custom extension, it may be executed after notebook is loaded.
181 // When "register_callback" is called by a custom extension, it may be executed after notebook is loaded.
189 // In that case, activate the preset if needed.
182 // In that case, activate the preset if needed.
190 if (IPython.notebook && IPython.notebook.metadata && IPython.notebook.metadata.celltoolbar === name)
183 if (notebook && notebook.metadata && notebook.metadata.celltoolbar === name)
191 this.activate_preset(name);
184 CellToolbar.activate_preset(name, events);
192 };
185 };
193
186
194
187
@@ -221,7 +214,7 b' var IPython = (function (IPython) {'
221 *
214 *
222 * CellToolbar.activate_preset('foo.foo_preset1');
215 * CellToolbar.activate_preset('foo.foo_preset1');
223 */
216 */
224 CellToolbar.activate_preset = function(preset_name){
217 CellToolbar.activate_preset = function(preset_name, events){
225 var preset = CellToolbar._presets[preset_name];
218 var preset = CellToolbar._presets[preset_name];
226
219
227 if(preset !== undefined){
220 if(preset !== undefined){
@@ -229,7 +222,9 b' var IPython = (function (IPython) {'
229 CellToolbar.rebuild_all();
222 CellToolbar.rebuild_all();
230 }
223 }
231
224
232 $([IPython.events]).trigger('preset_activated.CellToolbar', {name: preset_name});
225 if (events) {
226 events.trigger('preset_activated.CellToolbar', {name: preset_name});
227 }
233 };
228 };
234
229
235
230
@@ -283,7 +278,7 b' var IPython = (function (IPython) {'
283 }
278 }
284
279
285 // If there are no controls or the cell is a rendered TextCell hide the toolbar.
280 // 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 IPython.TextCell && this.cell.rendered)) {
281 if (!this.ui_controls_list.length || (this.cell_type != 'code' && this.cell.rendered)) {
287 this.hide();
282 this.hide();
288 } else {
283 } else {
289 this.show();
284 this.show();
@@ -415,8 +410,8 b' var IPython = (function (IPython) {'
415 };
410 };
416 };
411 };
417
412
418
413 // Backwards compatability.
419 IPython.CellToolbar = CellToolbar;
414 IPython.CellToolbar = CellToolbar;
420
415
421 return IPython;
416 return {'CellToolbar': CellToolbar};
422 }(IPython));
417 });
@@ -1,31 +1,23 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'jquery',
6 //----------------------------------------------------------------------------
6 'notebook/js/celltoolbar',
7
7 'base/js/dialog',
8 //============================================================================
8 ], function($, celltoolbar, dialog) {
9 // CellToolbar Default
10 //============================================================================
11
12 /**
13 * Example Use for the CellToolbar library
14 */
15 // IIFE without asignement, we don't modifiy the IPython namespace
16 (function (IPython) {
17 "use strict";
9 "use strict";
18
10
19 var CellToolbar = IPython.CellToolbar;
11 var CellToolbar = celltoolbar.CellToolbar;
20
12
21 var raw_edit = function(cell){
13 var raw_edit = function(cell){
22 IPython.dialog.edit_metadata(cell.metadata, function (md) {
14 dialog.edit_metadata(cell.metadata, function (md) {
23 cell.metadata = md;
15 cell.metadata = md;
24 });
16 });
25 };
17 };
26
18
27 var add_raw_edit_button = function(div, cell) {
19 var add_raw_edit_button = function(div, cell) {
28 var button_container = div;
20 var button_container = $(div);
29 var button = $('<button/>')
21 var button = $('<button/>')
30 .addClass("btn btn-default btn-xs")
22 .addClass("btn btn-default btn-xs")
31 .text("Edit Metadata")
23 .text("Edit Metadata")
@@ -36,11 +28,13 b''
36 button_container.append(button);
28 button_container.append(button);
37 };
29 };
38
30
39 CellToolbar.register_callback('default.rawedit', add_raw_edit_button);
31 var register = function (notebook, events) {
40 var example_preset = [];
32 CellToolbar.register_callback('default.rawedit', add_raw_edit_button);
41 example_preset.push('default.rawedit');
33 var example_preset = [];
34 example_preset.push('default.rawedit');
42
35
43 CellToolbar.register_preset('Edit Metadata', example_preset);
36 CellToolbar.register_preset('Edit Metadata', example_preset, notebook, events);
44 console.log('Default extension for cell metadata editing loaded.');
37 console.log('Default extension for cell metadata editing loaded.');
45
38 };
46 }(IPython));
39 return {'register': register};
40 });
@@ -1,28 +1,20 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 // Example Use for the CellToolbar library
5 // the file COPYING, distributed as part of this software.
5 // add the following to your custom.js to load
6 //----------------------------------------------------------------------------
6 // Celltoolbar UI for slideshow
7
7
8 //============================================================================
8 // ```
9 // CellToolbar Example
9 // $.getScript('/static/js/celltoolbarpresets/example.js');
10 //============================================================================
10 // ```
11
11 define([
12 /**
12 'jquery',
13 * Example Use for the CellToolbar library
13 'notebook/js/celltoolbar',
14 * add the following to your custom.js to load
14 ], function($, celltoolbar) {
15 * Celltoolbar UI for slideshow
16 *
17 * ```
18 * $.getScript('/static/js/celltoolbarpresets/example.js');
19 * ```
20 */
21 // IIFE without asignement, we don't modifiy the IPython namespace
22 (function (IPython) {
23 "use strict";
15 "use strict";
24
16
25 var CellToolbar = IPython.CellToolbar;
17 var CellToolbar = celltoolbar.CellToolbar;
26
18
27 var example_preset = [];
19 var example_preset = [];
28
20
@@ -32,32 +24,32 b''
32 var fun = function(value){
24 var fun = function(value){
33 try{
25 try{
34 if(value){
26 if(value){
35 cell.code_mirror.setOption('readOnly','nocursor')
27 cell.code_mirror.setOption('readOnly','nocursor');
36 button.button('option','icons',{primary:'ui-icon-locked'})
28 button.button('option','icons',{primary:'ui-icon-locked'});
37 } else {
29 } else {
38 cell.code_mirror.setOption('readOnly',false)
30 cell.code_mirror.setOption('readOnly',false);
39 button.button('option','icons',{primary:'ui-icon-unlocked'})
31 button.button('option','icons',{primary:'ui-icon-unlocked'});
40 }
32 }
41 } catch(e){}
33 } catch(e){}
42
34
43 }
35 };
44 fun(cell.metadata.ro)
36 fun(cell.metadata.ro);
45 button.click(function(){
37 button.click(function(){
46 var v = cell.metadata.ro;
38 var v = cell.metadata.ro;
47 var locked = !v;
39 var locked = !v;
48 cell.metadata.ro = locked;
40 cell.metadata.ro = locked;
49 fun(locked)
41 fun(locked);
50 })
42 })
51 .css('height','16px')
43 .css('height','16px')
52 .css('width','35px');
44 .css('width','35px');
53 button_container.append(button);
45 button_container.append(button);
54 }
46 };
55
47
56 CellToolbar.register_callback('example.lock',simple_button);
48 CellToolbar.register_callback('example.lock',simple_button);
57 example_preset.push('example.lock');
49 example_preset.push('example.lock');
58
50
59 var toggle_test = function(div, cell) {
51 var toggle_test = function(div, cell) {
60 var button_container = $(div)
52 var button_container = $(div);
61 var button = $('<div/>')
53 var button = $('<div/>')
62 .button({label:String(cell.metadata.foo)}).
54 .button({label:String(cell.metadata.foo)}).
63 css('width','65px');
55 css('width','65px');
@@ -65,9 +57,9 b''
65 var v = cell.metadata.foo;
57 var v = cell.metadata.foo;
66 cell.metadata.foo = !v;
58 cell.metadata.foo = !v;
67 button.button("option","label",String(!v));
59 button.button("option","label",String(!v));
68 })
60 });
69 button_container.append(button);
61 button_container.append(button);
70 }
62 };
71
63
72 CellToolbar.register_callback('example.toggle',toggle_test);
64 CellToolbar.register_callback('example.toggle',toggle_test);
73 example_preset.push('example.toggle');
65 example_preset.push('example.toggle');
@@ -76,16 +68,16 b''
76 // setter
68 // setter
77 function(cell, value){
69 function(cell, value){
78 // we check that the slideshow namespace exist and create it if needed
70 // we check that the slideshow namespace exist and create it if needed
79 if (cell.metadata.yn_test == undefined){cell.metadata.yn_test = {}}
71 if (cell.metadata.yn_test === undefined){cell.metadata.yn_test = {};}
80 // set the value
72 // set the value
81 cell.metadata.yn_test.value = value
73 cell.metadata.yn_test.value = value;
82 },
74 },
83 //geter
75 //geter
84 function(cell){ var ns = cell.metadata.yn_test;
76 function(cell){ var ns = cell.metadata.yn_test;
85 // if the slideshow namespace does not exist return `undefined`
77 // if the slideshow namespace does not exist return `undefined`
86 // (will be interpreted as `false` by checkbox) otherwise
78 // (will be interpreted as `false` by checkbox) otherwise
87 // return the value
79 // return the value
88 return (ns == undefined)? undefined: ns.value
80 return (ns === undefined)? undefined: ns.value;
89 }
81 }
90 );
82 );
91
83
@@ -103,16 +95,16 b''
103 // setter
95 // setter
104 function(cell,value){
96 function(cell,value){
105 // we check that the slideshow namespace exist and create it if needed
97 // we check that the slideshow namespace exist and create it if needed
106 if (cell.metadata.test == undefined){cell.metadata.test = {}}
98 if (cell.metadata.test === undefined){cell.metadata.test = {};}
107 // set the value
99 // set the value
108 cell.metadata.test.slide_type = value
100 cell.metadata.test.slide_type = value;
109 },
101 },
110 //geter
102 //geter
111 function(cell){ var ns = cell.metadata.test;
103 function(cell){ var ns = cell.metadata.test;
112 // if the slideshow namespace does not exist return `undefined`
104 // if the slideshow namespace does not exist return `undefined`
113 // (will be interpreted as `false` by checkbox) otherwise
105 // (will be interpreted as `false` by checkbox) otherwise
114 // return the value
106 // return the value
115 return (ns == undefined)? undefined: ns.slide_type
107 return (ns === undefined)? undefined: ns.slide_type;
116 });
108 });
117
109
118 CellToolbar.register_callback('example.select',select_test);
110 CellToolbar.register_callback('example.select',select_test);
@@ -120,7 +112,7 b''
120
112
121 var simple_dialog = function(title,text){
113 var simple_dialog = function(title,text){
122 var dlg = $('<div/>').attr('title',title)
114 var dlg = $('<div/>').attr('title',title)
123 .append($('<p/>').text(text))
115 .append($('<p/>').text(text));
124 $(dlg).dialog({
116 $(dlg).dialog({
125 autoOpen: true,
117 autoOpen: true,
126 height: 300,
118 height: 300,
@@ -131,24 +123,26 b''
131 $(this).remove();
123 $(this).remove();
132 }
124 }
133 });
125 });
134 }
126 };
135
127
136 var add_simple_dialog_button = function(div, cell) {
128 var add_simple_dialog_button = function(div, cell) {
137 var help_text = ["This is the Metadata editting UI.",
129 var help_text = ["This is the Metadata editting UI.",
138 "It heavily rely on plugin to work ",
130 "It heavily rely on plugin to work ",
139 "and is still under developpement. You shouldn't wait too long before",
131 "and is still under developpement. You shouldn't wait too long before",
140 " seeing some customisable buttons in those toolbar."
132 " seeing some customisable buttons in those toolbar."
141 ].join('\n')
133 ].join('\n');
142 var button_container = $(div)
134 var button_container = $(div);
143 var button = $('<div/>').button({label:'?'})
135 var button = $('<div/>').button({label:'?'})
144 .click(function(){simple_dialog('help',help_text); return false;})
136 .click(function(){simple_dialog('help',help_text); return false;});
145 button_container.append(button);
137 button_container.append(button);
146 }
138 };
147
148 CellToolbar.register_callback('example.help',add_simple_dialog_button)
149 example_preset.push('example.help')
150
139
151 CellToolbar.register_preset('Example',example_preset);
140 var register = function (notebook, events) {
152 console.log('Example extension for metadata editing loaded.');
141 CellToolbar.register_callback('example.help',add_simple_dialog_button);
142 example_preset.push('example.help');
153
143
154 }(IPython));
144 CellToolbar.register_preset('Example',example_preset, notebook, events);
145 console.log('Example extension for metadata editing loaded.');
146 };
147 return {'register': register};
148 });
@@ -1,18 +1,15 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // CellToolbar Example
5 'jquery',
10 //============================================================================
6 'notebook/js/celltoolbar',
7 'base/js/dialog',
8 'base/js/keyboard',
9 ], function($, celltoolbar, dialog, keyboard) {
10 "use strict";
11
11
12 (function(IPython) {
12 var CellToolbar = celltoolbar.CellToolbar;
13 "use strict";
14
15 var CellToolbar = IPython.CellToolbar;
16 var raw_cell_preset = [];
13 var raw_cell_preset = [];
17
14
18 var select_type = CellToolbar.utils.select_ui_generator([
15 var select_type = CellToolbar.utils.select_ui_generator([
@@ -39,7 +36,7 b''
39 $('<input/>').attr('type','text').attr('size','25')
36 $('<input/>').attr('type','text').attr('size','25')
40 .val(cell.metadata.raw_mimetype || "-")
37 .val(cell.metadata.raw_mimetype || "-")
41 );
38 );
42 IPython.dialog.modal({
39 dialog.modal({
43 title: "Raw Cell MIME Type",
40 title: "Raw Cell MIME Type",
44 body: dialog,
41 body: dialog,
45 buttons : {
42 buttons : {
@@ -57,7 +54,7 b''
57 var that = $(this);
54 var that = $(this);
58 // Upon ENTER, click the OK button.
55 // Upon ENTER, click the OK button.
59 that.find('input[type="text"]').keydown(function (event, ui) {
56 that.find('input[type="text"]').keydown(function (event, ui) {
60 if (event.which === IPython.keyboard.keycodes.enter) {
57 if (event.which === keyboard.keycodes.enter) {
61 that.find('.btn-primary').first().click();
58 that.find('.btn-primary').first().click();
62 return false;
59 return false;
63 }
60 }
@@ -77,11 +74,13 b''
77 "Raw NBConvert Format"
74 "Raw NBConvert Format"
78 );
75 );
79
76
80 CellToolbar.register_callback('raw_cell.select', select_type, ['raw']);
77 var register = function (notebook, events) {
81
78 CellToolbar.register_callback('raw_cell.select', select_type, ['raw']);
82 raw_cell_preset.push('raw_cell.select');
79 raw_cell_preset.push('raw_cell.select');
83
80
84 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
81 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset, notebook, events);
85 console.log('Raw Cell Format toolbar preset loaded.');
82 console.log('Raw Cell Format toolbar preset loaded.');
83 };
84 return {'register': register};
86
85
87 }(IPython));
86 });
@@ -1,19 +1,14 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 //CellToolbar Example
5 'jquery',
10 //============================================================================
6 'notebook/js/celltoolbar',
11
7 ], function($, celltoolbar) {
12 // IIFE without asignement, we don't modifiy the IPython namespace
13 (function (IPython) {
14 "use strict";
8 "use strict";
15
9
16 var CellToolbar = IPython.CellToolbar;
10
11 var CellToolbar = celltoolbar.CellToolbar;
17 var slideshow_preset = [];
12 var slideshow_preset = [];
18
13
19 var select_type = CellToolbar.utils.select_ui_generator([
14 var select_type = CellToolbar.utils.select_ui_generator([
@@ -27,24 +22,25 b''
27 // setter
22 // setter
28 function(cell, value){
23 function(cell, value){
29 // we check that the slideshow namespace exist and create it if needed
24 // we check that the slideshow namespace exist and create it if needed
30 if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
25 if (cell.metadata.slideshow === undefined){cell.metadata.slideshow = {};}
31 // set the value
26 // set the value
32 cell.metadata.slideshow.slide_type = value
27 cell.metadata.slideshow.slide_type = value;
33 },
28 },
34 //geter
29 //geter
35 function(cell){ var ns = cell.metadata.slideshow;
30 function(cell){ var ns = cell.metadata.slideshow;
36 // if the slideshow namespace does not exist return `undefined`
31 // if the slideshow namespace does not exist return `undefined`
37 // (will be interpreted as `false` by checkbox) otherwise
32 // (will be interpreted as `false` by checkbox) otherwise
38 // return the value
33 // return the value
39 return (ns == undefined)? undefined: ns.slide_type
34 return (ns === undefined)? undefined: ns.slide_type;
40 },
35 },
41 "Slide Type");
36 "Slide Type");
42
37
43 CellToolbar.register_callback('slideshow.select',select_type);
38 var register = function (notebook, events) {
44
39 CellToolbar.register_callback('slideshow.select',select_type);
45 slideshow_preset.push('slideshow.select');
40 slideshow_preset.push('slideshow.select');
46
47 CellToolbar.register_preset('Slideshow',slideshow_preset);
48 console.log('Slideshow extension for metadata editing loaded.');
49
41
50 }(IPython));
42 CellToolbar.register_preset('Slideshow',slideshow_preset, notebook, events);
43 console.log('Slideshow extension for metadata editing loaded.');
44 };
45 return {'register': register};
46 });
@@ -1,68 +1,67 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'base/js/utils',
8 //============================================================================
8 'base/js/keyboard',
9 // CodeCell
9 'notebook/js/cell',
10 //============================================================================
10 'notebook/js/outputarea',
11 /**
11 'notebook/js/completer',
12 * An extendable module that provide base functionnality to create cell for notebook.
12 'notebook/js/celltoolbar',
13 * @module IPython
13 ], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar) {
14 * @namespace IPython
15 * @submodule CodeCell
16 */
17
18
19 /* local util for codemirror */
20 var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
21
22 /**
23 *
24 * function to delete until previous non blanking space character
25 * or first multiple of 4 tabstop.
26 * @private
27 */
28 CodeMirror.commands.delSpaceToPrevTabStop = function(cm){
29 var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
30 if (!posEq(from, to)) { cm.replaceRange("", from, to); return; }
31 var cur = cm.getCursor(), line = cm.getLine(cur.line);
32 var tabsize = cm.getOption('tabSize');
33 var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
34 from = {ch:cur.ch-chToPrevTabStop,line:cur.line};
35 var select = cm.getRange(from,cur);
36 if( select.match(/^\ +$/) !== null){
37 cm.replaceRange("",from,cur);
38 } else {
39 cm.deleteH(-1,"char");
40 }
41 };
42
43
44 var IPython = (function (IPython) {
45 "use strict";
14 "use strict";
15 var Cell = cell.Cell;
46
16
47 var utils = IPython.utils;
17 /* local util for codemirror */
48 var keycodes = IPython.keyboard.keycodes;
18 var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
49
19
50 /**
20 /**
51 * A Cell conceived to write code.
52 *
21 *
53 * The kernel doesn't have to be set at creation time, in that case
22 * function to delete until previous non blanking space character
54 * it will be null and set_kernel has to be called later.
23 * or first multiple of 4 tabstop.
55 * @class CodeCell
24 * @private
56 * @extends IPython.Cell
57 *
58 * @constructor
59 * @param {Object|null} kernel
60 * @param {object|undefined} [options]
61 * @param [options.cm_config] {object} config to pass to CodeMirror
62 */
25 */
26 CodeMirror.commands.delSpaceToPrevTabStop = function(cm){
27 var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
28 if (!posEq(from, to)) { cm.replaceRange("", from, to); return; }
29 var cur = cm.getCursor(), line = cm.getLine(cur.line);
30 var tabsize = cm.getOption('tabSize');
31 var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
32 from = {ch:cur.ch-chToPrevTabStop,line:cur.line};
33 var select = cm.getRange(from,cur);
34 if( select.match(/^\ +$/) !== null){
35 cm.replaceRange("",from,cur);
36 } else {
37 cm.deleteH(-1,"char");
38 }
39 };
40
41 var keycodes = keyboard.keycodes;
42
63 var CodeCell = function (kernel, options) {
43 var CodeCell = function (kernel, options) {
44 // Constructor
45 //
46 // A Cell conceived to write code.
47 //
48 // Parameters:
49 // kernel: Kernel instance
50 // The kernel doesn't have to be set at creation time, in that case
51 // it will be null and set_kernel has to be called later.
52 // options: dictionary
53 // Dictionary of keyword arguments.
54 // events: $(Events) instance
55 // config: dictionary
56 // keyboard_manager: KeyboardManager instance
57 // notebook: Notebook instance
58 // tooltip: Tooltip instance
64 this.kernel = kernel || null;
59 this.kernel = kernel || null;
60 this.notebook = options.notebook;
65 this.collapsed = false;
61 this.collapsed = false;
62 this.events = options.events;
63 this.tooltip = options.tooltip;
64 this.config = options.config;
66
65
67 // create all attributed in constructor function
66 // create all attributed in constructor function
68 // even if null for V8 VM optimisation
67 // even if null for V8 VM optimisation
@@ -77,9 +76,11 b' var IPython = (function (IPython) {'
77 onKeyEvent: $.proxy(this.handle_keyevent,this)
76 onKeyEvent: $.proxy(this.handle_keyevent,this)
78 };
77 };
79
78
80 options = this.mergeopt(CodeCell, options, {cm_config:cm_overwrite_options});
79 var config = this.mergeopt(CodeCell, this.config, {cm_config: cm_overwrite_options});
81
80 Cell.apply(this,[{
82 IPython.Cell.apply(this,[options]);
81 config: config,
82 keyboard_manager: options.keyboard_manager,
83 events: this.events}]);
83
84
84 // Attributes we want to override in this subclass.
85 // Attributes we want to override in this subclass.
85 this.cell_type = "code";
86 this.cell_type = "code";
@@ -109,18 +110,18 b' var IPython = (function (IPython) {'
109
110
110 CodeCell.msg_cells = {};
111 CodeCell.msg_cells = {};
111
112
112 CodeCell.prototype = new IPython.Cell();
113 CodeCell.prototype = new Cell();
113
114
114 /**
115 /**
115 * @method auto_highlight
116 * @method auto_highlight
116 */
117 */
117 CodeCell.prototype.auto_highlight = function () {
118 CodeCell.prototype.auto_highlight = function () {
118 this._auto_highlight(IPython.config.cell_magic_highlight);
119 this._auto_highlight(this.config.cell_magic_highlight);
119 };
120 };
120
121
121 /** @method create_element */
122 /** @method create_element */
122 CodeCell.prototype.create_element = function () {
123 CodeCell.prototype.create_element = function () {
123 IPython.Cell.prototype.create_element.apply(this, arguments);
124 Cell.prototype.create_element.apply(this, arguments);
124
125
125 var cell = $('<div></div>').addClass('cell border-box-sizing code_cell');
126 var cell = $('<div></div>').addClass('cell border-box-sizing code_cell');
126 cell.attr('tabindex','2');
127 cell.attr('tabindex','2');
@@ -128,10 +129,13 b' var IPython = (function (IPython) {'
128 var input = $('<div></div>').addClass('input');
129 var input = $('<div></div>').addClass('input');
129 var prompt = $('<div/>').addClass('prompt input_prompt');
130 var prompt = $('<div/>').addClass('prompt input_prompt');
130 var inner_cell = $('<div/>').addClass('inner_cell');
131 var inner_cell = $('<div/>').addClass('inner_cell');
131 this.celltoolbar = new IPython.CellToolbar(this);
132 this.celltoolbar = new celltoolbar.CellToolbar({
133 cell: this,
134 events: this.events,
135 notebook: this.notebook});
132 inner_cell.append(this.celltoolbar.element);
136 inner_cell.append(this.celltoolbar.element);
133 var input_area = $('<div/>').addClass('input_area');
137 var input_area = $('<div/>').addClass('input_area');
134 this.code_mirror = CodeMirror(input_area.get(0), this.cm_config);
138 this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
135 $(this.code_mirror.getInputField()).attr("spellcheck", "false");
139 $(this.code_mirror.getInputField()).attr("spellcheck", "false");
136 inner_cell.append(input_area);
140 inner_cell.append(input_area);
137 input.append(prompt).append(inner_cell);
141 input.append(prompt).append(inner_cell);
@@ -158,13 +162,17 b' var IPython = (function (IPython) {'
158 var output = $('<div></div>');
162 var output = $('<div></div>');
159 cell.append(input).append(widget_area).append(output);
163 cell.append(input).append(widget_area).append(output);
160 this.element = cell;
164 this.element = cell;
161 this.output_area = new IPython.OutputArea(output, true);
165 this.output_area = new outputarea.OutputArea({
162 this.completer = new IPython.Completer(this);
166 selector: output,
167 prompt_area: true,
168 events: this.events,
169 keyboard_manager: this.keyboard_manager});
170 this.completer = new completer.Completer(this, this.events);
163 };
171 };
164
172
165 /** @method bind_events */
173 /** @method bind_events */
166 CodeCell.prototype.bind_events = function () {
174 CodeCell.prototype.bind_events = function () {
167 IPython.Cell.prototype.bind_events.apply(this);
175 Cell.prototype.bind_events.apply(this);
168 var that = this;
176 var that = this;
169
177
170 this.element.focusout(
178 this.element.focusout(
@@ -187,7 +195,7 b' var IPython = (function (IPython) {'
187 // they are sent, and remove tooltip if any, except for tab again
195 // they are sent, and remove tooltip if any, except for tab again
188 var tooltip_closed = null;
196 var tooltip_closed = null;
189 if (event.type === 'keydown' && event.which != keycodes.tab ) {
197 if (event.type === 'keydown' && event.which != keycodes.tab ) {
190 tooltip_closed = IPython.tooltip.remove_and_cancel_tooltip();
198 tooltip_closed = this.tooltip.remove_and_cancel_tooltip();
191 }
199 }
192
200
193 var cur = editor.getCursor();
201 var cur = editor.getCursor();
@@ -195,21 +203,21 b' var IPython = (function (IPython) {'
195 this.auto_highlight();
203 this.auto_highlight();
196 }
204 }
197
205
198 if (event.which === keycodes.down && event.type === 'keypress' && IPython.tooltip.time_before_tooltip >= 0) {
206 if (event.which === keycodes.down && event.type === 'keypress' && this.tooltip.time_before_tooltip >= 0) {
199 // triger on keypress (!) otherwise inconsistent event.which depending on plateform
207 // triger on keypress (!) otherwise inconsistent event.which depending on plateform
200 // browser and keyboard layout !
208 // browser and keyboard layout !
201 // Pressing '(' , request tooltip, don't forget to reappend it
209 // Pressing '(' , request tooltip, don't forget to reappend it
202 // The second argument says to hide the tooltip if the docstring
210 // The second argument says to hide the tooltip if the docstring
203 // is actually empty
211 // is actually empty
204 IPython.tooltip.pending(that, true);
212 this.tooltip.pending(that, true);
205 } else if ( tooltip_closed && event.which === keycodes.esc && event.type === 'keydown') {
213 } else if ( tooltip_closed && event.which === keycodes.esc && event.type === 'keydown') {
206 // If tooltip is active, cancel it. The call to
214 // If tooltip is active, cancel it. The call to
207 // remove_and_cancel_tooltip above doesn't pass, force=true.
215 // remove_and_cancel_tooltip above doesn't pass, force=true.
208 // Because of this it won't actually close the tooltip
216 // Because of this it won't actually close the tooltip
209 // if it is in sticky mode. Thus, we have to check again if it is open
217 // if it is in sticky mode. Thus, we have to check again if it is open
210 // and close it with force=true.
218 // and close it with force=true.
211 if (!IPython.tooltip._hidden) {
219 if (!this.tooltip._hidden) {
212 IPython.tooltip.remove_and_cancel_tooltip(true);
220 this.tooltip.remove_and_cancel_tooltip(true);
213 }
221 }
214 // If we closed the tooltip, don't let CM or the global handlers
222 // If we closed the tooltip, don't let CM or the global handlers
215 // handle this event.
223 // handle this event.
@@ -223,12 +231,12 b' var IPython = (function (IPython) {'
223 return false;
231 return false;
224 }
232 }
225 }
233 }
226 IPython.tooltip.request(that);
234 this.tooltip.request(that);
227 event.stop();
235 event.stop();
228 return true;
236 return true;
229 } else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
237 } else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
230 // Tab completion.
238 // Tab completion.
231 IPython.tooltip.remove_and_cancel_tooltip();
239 this.tooltip.remove_and_cancel_tooltip();
232 if (editor.somethingSelected()) {
240 if (editor.somethingSelected()) {
233 return false;
241 return false;
234 }
242 }
@@ -246,7 +254,7 b' var IPython = (function (IPython) {'
246
254
247 // keyboard event wasn't one of those unique to code cells, let's see
255 // keyboard event wasn't one of those unique to code cells, let's see
248 // if it's one of the generic ones (i.e. check edit mode shortcuts)
256 // if it's one of the generic ones (i.e. check edit mode shortcuts)
249 return IPython.Cell.prototype.handle_codemirror_keyevent.apply(this, [editor, event]);
257 return Cell.prototype.handle_codemirror_keyevent.apply(this, [editor, event]);
250 };
258 };
251
259
252 // Kernel related calls.
260 // Kernel related calls.
@@ -305,7 +313,7 b' var IPython = (function (IPython) {'
305 };
313 };
306
314
307 CodeCell.prototype._open_with_pager = function (payload) {
315 CodeCell.prototype._open_with_pager = function (payload) {
308 $([IPython.events]).trigger('open_with_text.Pager', payload);
316 this.events.trigger('open_with_text.Pager', payload);
309 };
317 };
310
318
311 /**
319 /**
@@ -315,7 +323,7 b' var IPython = (function (IPython) {'
315 CodeCell.prototype._handle_execute_reply = function (msg) {
323 CodeCell.prototype._handle_execute_reply = function (msg) {
316 this.set_input_prompt(msg.content.execution_count);
324 this.set_input_prompt(msg.content.execution_count);
317 this.element.removeClass("running");
325 this.element.removeClass("running");
318 $([IPython.events]).trigger('set_dirty.Notebook', {value: true});
326 this.events.trigger('set_dirty.Notebook', {value: true});
319 };
327 };
320
328
321 /**
329 /**
@@ -324,7 +332,7 b' var IPython = (function (IPython) {'
324 */
332 */
325 CodeCell.prototype._handle_set_next_input = function (payload) {
333 CodeCell.prototype._handle_set_next_input = function (payload) {
326 var data = {'cell': this, 'text': payload.text};
334 var data = {'cell': this, 'text': payload.text};
327 $([IPython.events]).trigger('set_next_input.Notebook', data);
335 this.events.trigger('set_next_input.Notebook', data);
328 };
336 };
329
337
330 /**
338 /**
@@ -339,7 +347,7 b' var IPython = (function (IPython) {'
339 // Basic cell manipulation.
347 // Basic cell manipulation.
340
348
341 CodeCell.prototype.select = function () {
349 CodeCell.prototype.select = function () {
342 var cont = IPython.Cell.prototype.select.apply(this);
350 var cont = Cell.prototype.select.apply(this);
343 if (cont) {
351 if (cont) {
344 this.code_mirror.refresh();
352 this.code_mirror.refresh();
345 this.auto_highlight();
353 this.auto_highlight();
@@ -348,7 +356,7 b' var IPython = (function (IPython) {'
348 };
356 };
349
357
350 CodeCell.prototype.render = function () {
358 CodeCell.prototype.render = function () {
351 var cont = IPython.Cell.prototype.render.apply(this);
359 var cont = Cell.prototype.render.apply(this);
352 // Always execute, even if we are already in the rendered state
360 // Always execute, even if we are already in the rendered state
353 return cont;
361 return cont;
354 };
362 };
@@ -451,7 +459,7 b' var IPython = (function (IPython) {'
451 // JSON serialization
459 // JSON serialization
452
460
453 CodeCell.prototype.fromJSON = function (data) {
461 CodeCell.prototype.fromJSON = function (data) {
454 IPython.Cell.prototype.fromJSON.apply(this, arguments);
462 Cell.prototype.fromJSON.apply(this, arguments);
455 if (data.cell_type === 'code') {
463 if (data.cell_type === 'code') {
456 if (data.input !== undefined) {
464 if (data.input !== undefined) {
457 this.set_text(data.input);
465 this.set_text(data.input);
@@ -479,7 +487,7 b' var IPython = (function (IPython) {'
479
487
480
488
481 CodeCell.prototype.toJSON = function () {
489 CodeCell.prototype.toJSON = function () {
482 var data = IPython.Cell.prototype.toJSON.apply(this);
490 var data = Cell.prototype.toJSON.apply(this);
483 data.input = this.get_text();
491 data.input = this.get_text();
484 // is finite protect against undefined and '*' value
492 // is finite protect against undefined and '*' value
485 if (isFinite(this.input_prompt_number)) {
493 if (isFinite(this.input_prompt_number)) {
@@ -499,11 +507,11 b' var IPython = (function (IPython) {'
499 * @return is the action being taken
507 * @return is the action being taken
500 */
508 */
501 CodeCell.prototype.unselect = function () {
509 CodeCell.prototype.unselect = function () {
502 var cont = IPython.Cell.prototype.unselect.apply(this);
510 var cont = Cell.prototype.unselect.apply(this);
503 if (cont) {
511 if (cont) {
504 // When a code cell is usnelected, make sure that the corresponding
512 // When a code cell is usnelected, make sure that the corresponding
505 // tooltip and completer to that cell is closed.
513 // tooltip and completer to that cell is closed.
506 IPython.tooltip.remove_and_cancel_tooltip(true);
514 this.tooltip.remove_and_cancel_tooltip(true);
507 if (this.completer !== null) {
515 if (this.completer !== null) {
508 this.completer.close();
516 this.completer.close();
509 }
517 }
@@ -511,7 +519,8 b' var IPython = (function (IPython) {'
511 return cont;
519 return cont;
512 };
520 };
513
521
522 // Backwards compatability.
514 IPython.CodeCell = CodeCell;
523 IPython.CodeCell = CodeCell;
515
524
516 return IPython;
525 return {'CodeCell': CodeCell};
517 }(IPython));
526 });
@@ -8,7 +8,6 b''
8
8
9 CodeMirror.requireMode('gfm', function(){
9 CodeMirror.requireMode('gfm', function(){
10 CodeMirror.requireMode('stex', function(){
10 CodeMirror.requireMode('stex', function(){
11 console.log('defining custom mode...');
12 CodeMirror.defineMode("ipythongfm", function(config, parserConfig) {
11 CodeMirror.defineMode("ipythongfm", function(config, parserConfig) {
13
12
14 var gfm_mode = CodeMirror.getMode(config, "gfm");
13 var gfm_mode = CodeMirror.getMode(config, "gfm");
@@ -1,17 +1,17 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 // Completer
4 define([
5 //
5 'base/js/namespace',
6 // Completer is be a class that takes a cell instance.
6 'jquery',
7
7 'base/js/utils',
8 var IPython = (function (IPython) {
8 'base/js/keyboard',
9 // that will prevent us from misspelling
9 'notebook/js/contexthint',
10 ], function(IPython, $, utils, keyboard) {
10 "use strict";
11 "use strict";
11
12
12 // easier key mapping
13 // easier key mapping
13 var keycodes = IPython.keyboard.keycodes;
14 var keycodes = keyboard.keycodes;
14 var utils = IPython.utils;
15
15
16 var prepend_n_prc = function(str, n) {
16 var prepend_n_prc = function(str, n) {
17 for( var i =0 ; i< n ; i++){
17 for( var i =0 ; i< n ; i++){
@@ -78,14 +78,14 b' var IPython = (function (IPython) {'
78 }
78 }
79
79
80
80
81 var Completer = function (cell) {
81 var Completer = function (cell, events) {
82 this.cell = cell;
82 this.cell = cell;
83 this.editor = cell.code_mirror;
83 this.editor = cell.code_mirror;
84 var that = this;
84 var that = this;
85 $([IPython.events]).on('status_busy.Kernel', function () {
85 events.on('status_busy.Kernel', function () {
86 that.skip_kernel_completion = true;
86 that.skip_kernel_completion = true;
87 });
87 });
88 $([IPython.events]).on('status_idle.Kernel', function () {
88 events.on('status_idle.Kernel', function () {
89 that.skip_kernel_completion = false;
89 that.skip_kernel_completion = false;
90 });
90 });
91 };
91 };
@@ -379,7 +379,9 b' var IPython = (function (IPython) {'
379 that.carry_on_completion();
379 that.carry_on_completion();
380 }, 50);
380 }, 50);
381 };
381 };
382
383 // For backwards compatability.
382 IPython.Completer = Completer;
384 IPython.Completer = Completer;
383
385
384 return IPython;
386 return {'Completer': Completer};
385 }(IPython));
387 });
@@ -1,28 +1,9 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([], function() {
9 // Notebook
10 //============================================================================
11
12 /**
13 * @module IPython
14 * @namespace IPython
15 **/
16
17 var IPython = (function (IPython) {
18 "use strict";
5 "use strict";
19 /**
6
20 * A place where some stuff can be confugured.
21 *
22 * @class config
23 * @static
24 *
25 **/
26 var default_config = {
7 var default_config = {
27 /**
8 /**
28 * Dictionary of object to autodetect highlight mode for code cell.
9 * Dictionary of object to autodetect highlight mode for code cell.
@@ -50,30 +31,25 b' var IPython = (function (IPython) {'
50 * cell_magic_highlight['javascript'] = {'reg':[/^var/]}
31 * cell_magic_highlight['javascript'] = {'reg':[/^var/]}
51 */
32 */
52 cell_magic_highlight : {
33 cell_magic_highlight : {
53 'magic_javascript' :{'reg':[/^%%javascript/]}
34 'magic_javascript' :{'reg':[/^%%javascript/]},
54 ,'magic_perl' :{'reg':[/^%%perl/]}
35 'magic_perl' :{'reg':[/^%%perl/]},
55 ,'magic_ruby' :{'reg':[/^%%ruby/]}
36 'magic_ruby' :{'reg':[/^%%ruby/]},
56 ,'magic_python' :{'reg':[/^%%python3?/]}
37 'magic_python' :{'reg':[/^%%python3?/]},
57 ,'magic_shell' :{'reg':[/^%%bash/]}
38 'magic_shell' :{'reg':[/^%%bash/]},
58 ,'magic_r' :{'reg':[/^%%R/]}
39 'magic_r' :{'reg':[/^%%R/]},
59 ,'magic_text/x-cython' :{'reg':[/^%%cython/]}
40 'magic_text/x-cython' :{'reg':[/^%%cython/]},
60 },
41 },
61
42
62 /**
43 /**
63 * same as `cell_magic_highlight` but for raw cells
44 * same as `cell_magic_highlight` but for raw cells
64 * @attribute raw_cell_highlight
45 * @attribute raw_cell_highlight
65 */
46 */
66 raw_cell_highlight : {
47 raw_cell_highlight : {
67 'diff' :{'reg':[/^diff/]}
48 'diff' :{'reg':[/^diff/]}
68 },
49 },
69
50 };
70 };
51
71
52 return {
72 // use the same method to merge user configuration
53 'default_config': default_config,
73 IPython.config = {};
54 };
74 $.extend(IPython.config, default_config);
55 });
75
76 return IPython;
77
78 }(IPython));
79
@@ -1,12 +1,15 b''
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
3
1 // highly adapted for codemiror jshint
4 // highly adapted for codemiror jshint
2 (function () {
5 define([], function() {
3 "use strict";
6 "use strict";
4
7
5 function forEach(arr, f) {
8 var forEach = function(arr, f) {
6 for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
9 for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
7 }
10 };
8
11
9 function arrayContains(arr, item) {
12 var arrayContains = function(arr, item) {
10 if (!Array.prototype.indexOf) {
13 if (!Array.prototype.indexOf) {
11 var i = arr.length;
14 var i = arr.length;
12 while (i--) {
15 while (i--) {
@@ -17,7 +20,7 b''
17 return false;
20 return false;
18 }
21 }
19 return arr.indexOf(item) != -1;
22 return arr.indexOf(item) != -1;
20 }
23 };
21
24
22 CodeMirror.contextHint = function (editor) {
25 CodeMirror.contextHint = function (editor) {
23 // Find the token at the cursor
26 // Find the token at the cursor
@@ -26,7 +29,7 b''
26 tprop = token;
29 tprop = token;
27 // If it's not a 'word-style' token, ignore the token.
30 // If it's not a 'word-style' token, ignore the token.
28 // If it is a property, find out what it is a property of.
31 // If it is a property, find out what it is a property of.
29 var list = new Array();
32 var list = [];
30 var clist = getCompletions(token, editor);
33 var clist = getCompletions(token, editor);
31 for (var i = 0; i < clist.length; i++) {
34 for (var i = 0; i < clist.length; i++) {
32 list.push({
35 list.push({
@@ -40,55 +43,56 b''
40 line: cur.line,
43 line: cur.line,
41 ch: token.end
44 ch: token.end
42 }
45 }
43 })
46 });
44 }
47 }
45 return list;
48 return list;
46 }
49 };
47
50
48 // find all 'words' of current cell
51 // find all 'words' of current cell
49 var getAllTokens = function (editor) {
52 var getAllTokens = function (editor) {
50 var found = [];
53 var found = [];
51
54
52 // add to found if not already in it
55 // add to found if not already in it
53
56
54
57
55 function maybeAdd(str) {
58 function maybeAdd(str) {
56 if (!arrayContains(found, str)) found.push(str);
59 if (!arrayContains(found, str)) found.push(str);
57 }
60 }
58
61
59 // loop through all token on all lines
62 // loop through all token on all lines
60 var lineCount = editor.lineCount();
63 var lineCount = editor.lineCount();
61 // loop on line
64 // loop on line
62 for (var l = 0; l < lineCount; l++) {
65 for (var l = 0; l < lineCount; l++) {
63 var line = editor.getLine(l);
66 var line = editor.getLine(l);
64 //loop on char
67 //loop on char
65 for (var c = 1; c < line.length; c++) {
68 for (var c = 1; c < line.length; c++) {
66 var tk = editor.getTokenAt({
69 var tk = editor.getTokenAt({
67 line: l,
70 line: l,
68 ch: c
71 ch: c
69 });
72 });
70 // if token has a class, it has geat chances of beeing
73 // if token has a class, it has geat chances of beeing
71 // of interest. Add it to the list of possible completions.
74 // of interest. Add it to the list of possible completions.
72 // we could skip token of ClassName 'comment'
75 // we could skip token of ClassName 'comment'
73 // or 'number' and 'operator'
76 // or 'number' and 'operator'
74 if (tk.className != null) {
77 if (tk.className !== null) {
75 maybeAdd(tk.string);
78 maybeAdd(tk.string);
76 }
77 // jump to char after end of current token
78 c = tk.end;
79 }
79 }
80 // jump to char after end of current token
81 c = tk.end;
80 }
82 }
81 return found;
82 }
83 }
84 return found;
85 };
83
86
84
87 var getCompletions = function(token, editor) {
85 function getCompletions(token, editor) {
86 var candidates = getAllTokens(editor);
88 var candidates = getAllTokens(editor);
87 // filter all token that have a common start (but nox exactly) the lenght of the current token
89 // filter all token that have a common start (but nox exactly) the lenght of the current token
88 var lambda = function (x) {
90 var lambda = function (x) {
89 return (x.indexOf(token.string) == 0 && x != token.string)
91 return (x.indexOf(token.string) === 0 && x != token.string);
90 };
92 };
91 var filterd = candidates.filter(lambda);
93 var filterd = candidates.filter(lambda);
92 return filterd;
94 return filterd;
93 }
95 };
94 })();
96
97 return {'contextHint': CodeMirror.contextHint};
98 });
This diff has been collapsed as it changes many lines, (902 lines changed) Show them Hide them
@@ -1,468 +1,476 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Keyboard management
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11
7 'base/js/utils',
12 var IPython = (function (IPython) {
8 'base/js/keyboard',
9 ], function(IPython, $, utils, keyboard) {
13 "use strict";
10 "use strict";
11
12 var browser = utils.browser[0];
13 var platform = utils.platform;
14
14
15 var browser = IPython.utils.browser[0];
15 // Main keyboard manager for the notebook
16 var platform = IPython.utils.platform;
16 var keycodes = keyboard.keycodes;
17
17
18 // Default keyboard shortcuts
18 var KeyboardManager = function (options) {
19 // Constructor
20 //
21 // Parameters:
22 // options: dictionary
23 // Dictionary of keyword arguments.
24 // events: $(Events) instance
25 // pager: Pager instance
26 this.mode = 'command';
27 this.enabled = true;
28 this.pager = options.pager;
29 this.quick_help = undefined;
30 this.notebook = undefined;
31 this.bind_events();
32 this.command_shortcuts = new keyboard.ShortcutManager(undefined, options.events);
33 this.command_shortcuts.add_shortcuts(this.get_default_common_shortcuts());
34 this.command_shortcuts.add_shortcuts(this.get_default_command_shortcuts());
35 this.edit_shortcuts = new keyboard.ShortcutManager(undefined, options.events);
36 this.edit_shortcuts.add_shortcuts(this.get_default_common_shortcuts());
37 this.edit_shortcuts.add_shortcuts(this.get_default_edit_shortcuts());
38 };
19
39
20 var default_common_shortcuts = {
40 KeyboardManager.prototype.get_default_common_shortcuts = function() {
21 'shift' : {
41 var that = this;
22 help : '',
42 var shortcuts = {
23 help_index : '',
43 'shift' : {
24 handler : function (event) {
44 help : '',
25 // ignore shift keydown
45 help_index : '',
26 return true;
46 handler : function (event) {
27 }
47 // ignore shift keydown
28 },
48 return true;
29 'shift-enter' : {
49 }
30 help : 'run cell, select below',
50 },
31 help_index : 'ba',
51 'shift-enter' : {
32 handler : function (event) {
52 help : 'run cell, select below',
33 IPython.notebook.execute_cell_and_select_below();
53 help_index : 'ba',
34 return false;
54 handler : function (event) {
35 }
55 that.notebook.execute_cell_and_select_below();
36 },
56 return false;
37 'ctrl-enter' : {
57 }
38 help : 'run cell',
58 },
39 help_index : 'bb',
59 'ctrl-enter' : {
40 handler : function (event) {
60 help : 'run cell',
41 IPython.notebook.execute_cell();
61 help_index : 'bb',
42 return false;
62 handler : function (event) {
43 }
63 that.notebook.execute_cell();
44 },
64 return false;
45 'alt-enter' : {
65 }
46 help : 'run cell, insert below',
66 },
47 help_index : 'bc',
67 'alt-enter' : {
48 handler : function (event) {
68 help : 'run cell, insert below',
49 IPython.notebook.execute_cell_and_insert_below();
69 help_index : 'bc',
50 return false;
70 handler : function (event) {
71 that.notebook.execute_cell_and_insert_below();
72 return false;
73 }
51 }
74 }
75 };
76
77 if (platform === 'MacOS') {
78 shortcuts['cmd-s'] =
79 {
80 help : 'save notebook',
81 help_index : 'fb',
82 handler : function (event) {
83 that.notebook.save_checkpoint();
84 event.preventDefault();
85 return false;
86 }
87 };
88 } else {
89 shortcuts['ctrl-s'] =
90 {
91 help : 'save notebook',
92 help_index : 'fb',
93 handler : function (event) {
94 that.notebook.save_checkpoint();
95 event.preventDefault();
96 return false;
97 }
98 };
52 }
99 }
100 return shortcuts;
53 };
101 };
54
102
55 if (platform === 'MacOS') {
103 KeyboardManager.prototype.get_default_edit_shortcuts = function() {
56 default_common_shortcuts['cmd-s'] =
104 var that = this;
57 {
105 return {
58 help : 'save notebook',
106 'esc' : {
59 help_index : 'fb',
107 help : 'command mode',
108 help_index : 'aa',
60 handler : function (event) {
109 handler : function (event) {
61 IPython.notebook.save_checkpoint();
110 that.notebook.command_mode();
62 event.preventDefault();
63 return false;
111 return false;
64 }
112 }
65 };
113 },
66 } else {
114 'ctrl-m' : {
67 default_common_shortcuts['ctrl-s'] =
115 help : 'command mode',
68 {
116 help_index : 'ab',
69 help : 'save notebook',
70 help_index : 'fb',
71 handler : function (event) {
117 handler : function (event) {
72 IPython.notebook.save_checkpoint();
118 that.notebook.command_mode();
73 event.preventDefault();
74 return false;
119 return false;
75 }
120 }
76 };
121 },
77 }
122 'up' : {
78
123 help : '',
79 // Edit mode defaults
124 help_index : '',
80
125 handler : function (event) {
81 var default_edit_shortcuts = {
126 var index = that.notebook.get_selected_index();
82 'esc' : {
127 var cell = that.notebook.get_cell(index);
83 help : 'command mode',
128 if (cell && cell.at_top() && index !== 0) {
84 help_index : 'aa',
129 event.preventDefault();
85 handler : function (event) {
130 that.notebook.command_mode();
86 IPython.notebook.command_mode();
131 that.notebook.select_prev();
87 return false;
132 that.notebook.edit_mode();
88 }
133 var cm = that.notebook.get_selected_cell().code_mirror;
89 },
134 cm.setCursor(cm.lastLine(), 0);
90 'ctrl-m' : {
135 return false;
91 help : 'command mode',
136 } else if (cell) {
92 help_index : 'ab',
137 var cm = cell.code_mirror;
93 handler : function (event) {
138 cm.execCommand('goLineUp');
94 IPython.notebook.command_mode();
139 return false;
95 return false;
140 }
96 }
141 }
97 },
142 },
98 'up' : {
143 'down' : {
99 help : '',
144 help : '',
100 help_index : '',
145 help_index : '',
101 handler : function (event) {
146 handler : function (event) {
102 var index = IPython.notebook.get_selected_index();
147 var index = that.notebook.get_selected_index();
103 var cell = IPython.notebook.get_cell(index);
148 var cell = that.notebook.get_cell(index);
104 if (cell && cell.at_top() && index !== 0) {
149 if (cell.at_bottom() && index !== (that.notebook.ncells()-1)) {
105 event.preventDefault();
150 event.preventDefault();
106 IPython.notebook.command_mode();
151 that.notebook.command_mode();
107 IPython.notebook.select_prev();
152 that.notebook.select_next();
108 IPython.notebook.edit_mode();
153 that.notebook.edit_mode();
109 var cm = IPython.notebook.get_selected_cell().code_mirror;
154 var cm = that.notebook.get_selected_cell().code_mirror;
110 cm.setCursor(cm.lastLine(), 0);
155 cm.setCursor(0, 0);
111 return false;
156 return false;
112 } else if (cell) {
157 } else {
113 var cm = cell.code_mirror;
158 var cm = cell.code_mirror;
114 cm.execCommand('goLineUp');
159 cm.execCommand('goLineDown');
160 return false;
161 }
162 }
163 },
164 'ctrl-shift--' : {
165 help : 'split cell',
166 help_index : 'ea',
167 handler : function (event) {
168 that.notebook.split_cell();
115 return false;
169 return false;
116 }
170 }
117 }
171 },
118 },
172 'ctrl-shift-subtract' : {
119 'down' : {
173 help : '',
120 help : '',
174 help_index : 'eb',
121 help_index : '',
175 handler : function (event) {
122 handler : function (event) {
176 that.notebook.split_cell();
123 var index = IPython.notebook.get_selected_index();
124 var cell = IPython.notebook.get_cell(index);
125 if (cell.at_bottom() && index !== (IPython.notebook.ncells()-1)) {
126 event.preventDefault();
127 IPython.notebook.command_mode();
128 IPython.notebook.select_next();
129 IPython.notebook.edit_mode();
130 var cm = IPython.notebook.get_selected_cell().code_mirror;
131 cm.setCursor(0, 0);
132 return false;
133 } else {
134 var cm = cell.code_mirror;
135 cm.execCommand('goLineDown');
136 return false;
177 return false;
137 }
178 }
138 }
179 },
139 },
180 };
140 'ctrl-shift--' : {
141 help : 'split cell',
142 help_index : 'ea',
143 handler : function (event) {
144 IPython.notebook.split_cell();
145 return false;
146 }
147 },
148 'ctrl-shift-subtract' : {
149 help : '',
150 help_index : 'eb',
151 handler : function (event) {
152 IPython.notebook.split_cell();
153 return false;
154 }
155 },
156 };
181 };
157
182
158 // Command mode defaults
183 KeyboardManager.prototype.get_default_command_shortcuts = function() {
159
184 var that = this;
160 var default_command_shortcuts = {
185 return {
161 'enter' : {
186 'enter' : {
162 help : 'edit mode',
187 help : 'edit mode',
163 help_index : 'aa',
188 help_index : 'aa',
164 handler : function (event) {
189 handler : function (event) {
165 IPython.notebook.edit_mode();
190 that.notebook.edit_mode();
166 return false;
191 return false;
167 }
168 },
169 'up' : {
170 help : 'select previous cell',
171 help_index : 'da',
172 handler : function (event) {
173 var index = IPython.notebook.get_selected_index();
174 if (index !== 0 && index !== null) {
175 IPython.notebook.select_prev();
176 IPython.notebook.focus_cell();
177 }
192 }
178 return false;
193 },
179 }
194 'up' : {
180 },
195 help : 'select previous cell',
181 'down' : {
196 help_index : 'da',
182 help : 'select next cell',
197 handler : function (event) {
183 help_index : 'db',
198 var index = that.notebook.get_selected_index();
184 handler : function (event) {
199 if (index !== 0 && index !== null) {
185 var index = IPython.notebook.get_selected_index();
200 that.notebook.select_prev();
186 if (index !== (IPython.notebook.ncells()-1) && index !== null) {
201 that.notebook.focus_cell();
187 IPython.notebook.select_next();
202 }
188 IPython.notebook.focus_cell();
203 return false;
189 }
204 }
190 return false;
205 },
191 }
206 'down' : {
192 },
207 help : 'select next cell',
193 'k' : {
208 help_index : 'db',
194 help : 'select previous cell',
209 handler : function (event) {
195 help_index : 'dc',
210 var index = that.notebook.get_selected_index();
196 handler : function (event) {
211 if (index !== (that.notebook.ncells()-1) && index !== null) {
197 var index = IPython.notebook.get_selected_index();
212 that.notebook.select_next();
198 if (index !== 0 && index !== null) {
213 that.notebook.focus_cell();
199 IPython.notebook.select_prev();
214 }
200 IPython.notebook.focus_cell();
215 return false;
201 }
216 }
202 return false;
217 },
203 }
218 'k' : {
204 },
219 help : 'select previous cell',
205 'j' : {
220 help_index : 'dc',
206 help : 'select next cell',
221 handler : function (event) {
207 help_index : 'dd',
222 var index = that.notebook.get_selected_index();
208 handler : function (event) {
223 if (index !== 0 && index !== null) {
209 var index = IPython.notebook.get_selected_index();
224 that.notebook.select_prev();
210 if (index !== (IPython.notebook.ncells()-1) && index !== null) {
225 that.notebook.focus_cell();
211 IPython.notebook.select_next();
226 }
212 IPython.notebook.focus_cell();
227 return false;
213 }
228 }
214 return false;
229 },
215 }
230 'j' : {
216 },
231 help : 'select next cell',
217 'x' : {
232 help_index : 'dd',
218 help : 'cut cell',
233 handler : function (event) {
219 help_index : 'ee',
234 var index = that.notebook.get_selected_index();
220 handler : function (event) {
235 if (index !== (that.notebook.ncells()-1) && index !== null) {
221 IPython.notebook.cut_cell();
236 that.notebook.select_next();
222 return false;
237 that.notebook.focus_cell();
223 }
238 }
224 },
239 return false;
225 'c' : {
240 }
226 help : 'copy cell',
241 },
227 help_index : 'ef',
242 'x' : {
228 handler : function (event) {
243 help : 'cut cell',
229 IPython.notebook.copy_cell();
244 help_index : 'ee',
230 return false;
245 handler : function (event) {
231 }
246 that.notebook.cut_cell();
232 },
247 return false;
233 'shift-v' : {
248 }
234 help : 'paste cell above',
249 },
235 help_index : 'eg',
250 'c' : {
236 handler : function (event) {
251 help : 'copy cell',
237 IPython.notebook.paste_cell_above();
252 help_index : 'ef',
238 return false;
253 handler : function (event) {
239 }
254 that.notebook.copy_cell();
240 },
255 return false;
241 'v' : {
256 }
242 help : 'paste cell below',
257 },
243 help_index : 'eh',
258 'shift-v' : {
244 handler : function (event) {
259 help : 'paste cell above',
245 IPython.notebook.paste_cell_below();
260 help_index : 'eg',
246 return false;
261 handler : function (event) {
247 }
262 that.notebook.paste_cell_above();
248 },
263 return false;
249 'd' : {
264 }
250 help : 'delete cell (press twice)',
265 },
251 help_index : 'ej',
266 'v' : {
252 count: 2,
267 help : 'paste cell below',
253 handler : function (event) {
268 help_index : 'eh',
254 IPython.notebook.delete_cell();
269 handler : function (event) {
255 return false;
270 that.notebook.paste_cell_below();
256 }
271 return false;
257 },
272 }
258 'a' : {
273 },
259 help : 'insert cell above',
274 'd' : {
260 help_index : 'ec',
275 help : 'delete cell (press twice)',
261 handler : function (event) {
276 help_index : 'ej',
262 IPython.notebook.insert_cell_above();
277 count: 2,
263 IPython.notebook.select_prev();
278 handler : function (event) {
264 IPython.notebook.focus_cell();
279 that.notebook.delete_cell();
265 return false;
280 return false;
266 }
281 }
267 },
282 },
268 'b' : {
283 'a' : {
269 help : 'insert cell below',
284 help : 'insert cell above',
270 help_index : 'ed',
285 help_index : 'ec',
271 handler : function (event) {
286 handler : function (event) {
272 IPython.notebook.insert_cell_below();
287 that.notebook.insert_cell_above();
273 IPython.notebook.select_next();
288 that.notebook.select_prev();
274 IPython.notebook.focus_cell();
289 that.notebook.focus_cell();
275 return false;
290 return false;
276 }
291 }
277 },
292 },
278 'y' : {
293 'b' : {
279 help : 'to code',
294 help : 'insert cell below',
280 help_index : 'ca',
295 help_index : 'ed',
281 handler : function (event) {
296 handler : function (event) {
282 IPython.notebook.to_code();
297 that.notebook.insert_cell_below();
283 return false;
298 that.notebook.select_next();
284 }
299 that.notebook.focus_cell();
285 },
300 return false;
286 'm' : {
301 }
287 help : 'to markdown',
302 },
288 help_index : 'cb',
303 'y' : {
289 handler : function (event) {
304 help : 'to code',
290 IPython.notebook.to_markdown();
305 help_index : 'ca',
291 return false;
306 handler : function (event) {
292 }
307 that.notebook.to_code();
293 },
308 return false;
294 'r' : {
309 }
295 help : 'to raw',
310 },
296 help_index : 'cc',
311 'm' : {
297 handler : function (event) {
312 help : 'to markdown',
298 IPython.notebook.to_raw();
313 help_index : 'cb',
299 return false;
314 handler : function (event) {
300 }
315 that.notebook.to_markdown();
301 },
316 return false;
302 '1' : {
317 }
303 help : 'to heading 1',
318 },
304 help_index : 'cd',
319 'r' : {
305 handler : function (event) {
320 help : 'to raw',
306 IPython.notebook.to_heading(undefined, 1);
321 help_index : 'cc',
307 return false;
322 handler : function (event) {
308 }
323 that.notebook.to_raw();
309 },
324 return false;
310 '2' : {
325 }
311 help : 'to heading 2',
326 },
312 help_index : 'ce',
327 '1' : {
313 handler : function (event) {
328 help : 'to heading 1',
314 IPython.notebook.to_heading(undefined, 2);
329 help_index : 'cd',
315 return false;
330 handler : function (event) {
316 }
331 that.notebook.to_heading(undefined, 1);
317 },
332 return false;
318 '3' : {
333 }
319 help : 'to heading 3',
334 },
320 help_index : 'cf',
335 '2' : {
321 handler : function (event) {
336 help : 'to heading 2',
322 IPython.notebook.to_heading(undefined, 3);
337 help_index : 'ce',
323 return false;
338 handler : function (event) {
324 }
339 that.notebook.to_heading(undefined, 2);
325 },
340 return false;
326 '4' : {
341 }
327 help : 'to heading 4',
342 },
328 help_index : 'cg',
343 '3' : {
329 handler : function (event) {
344 help : 'to heading 3',
330 IPython.notebook.to_heading(undefined, 4);
345 help_index : 'cf',
331 return false;
346 handler : function (event) {
332 }
347 that.notebook.to_heading(undefined, 3);
333 },
348 return false;
334 '5' : {
349 }
335 help : 'to heading 5',
350 },
336 help_index : 'ch',
351 '4' : {
337 handler : function (event) {
352 help : 'to heading 4',
338 IPython.notebook.to_heading(undefined, 5);
353 help_index : 'cg',
339 return false;
354 handler : function (event) {
340 }
355 that.notebook.to_heading(undefined, 4);
341 },
356 return false;
342 '6' : {
357 }
343 help : 'to heading 6',
358 },
344 help_index : 'ci',
359 '5' : {
345 handler : function (event) {
360 help : 'to heading 5',
346 IPython.notebook.to_heading(undefined, 6);
361 help_index : 'ch',
347 return false;
362 handler : function (event) {
348 }
363 that.notebook.to_heading(undefined, 5);
349 },
364 return false;
350 'o' : {
365 }
351 help : 'toggle output',
366 },
352 help_index : 'gb',
367 '6' : {
353 handler : function (event) {
368 help : 'to heading 6',
354 IPython.notebook.toggle_output();
369 help_index : 'ci',
355 return false;
370 handler : function (event) {
356 }
371 that.notebook.to_heading(undefined, 6);
357 },
372 return false;
358 'shift-o' : {
373 }
359 help : 'toggle output scrolling',
374 },
360 help_index : 'gc',
375 'o' : {
361 handler : function (event) {
376 help : 'toggle output',
362 IPython.notebook.toggle_output_scroll();
377 help_index : 'gb',
363 return false;
378 handler : function (event) {
364 }
379 that.notebook.toggle_output();
365 },
380 return false;
366 's' : {
381 }
367 help : 'save notebook',
382 },
368 help_index : 'fa',
383 'shift-o' : {
369 handler : function (event) {
384 help : 'toggle output scrolling',
370 IPython.notebook.save_checkpoint();
385 help_index : 'gc',
371 return false;
386 handler : function (event) {
372 }
387 that.notebook.toggle_output_scroll();
373 },
388 return false;
374 'ctrl-j' : {
389 }
375 help : 'move cell down',
390 },
376 help_index : 'eb',
391 's' : {
377 handler : function (event) {
392 help : 'save notebook',
378 IPython.notebook.move_cell_down();
393 help_index : 'fa',
379 return false;
394 handler : function (event) {
380 }
395 that.notebook.save_checkpoint();
381 },
396 return false;
382 'ctrl-k' : {
397 }
383 help : 'move cell up',
398 },
384 help_index : 'ea',
399 'ctrl-j' : {
385 handler : function (event) {
400 help : 'move cell down',
386 IPython.notebook.move_cell_up();
401 help_index : 'eb',
387 return false;
402 handler : function (event) {
388 }
403 that.notebook.move_cell_down();
389 },
404 return false;
390 'l' : {
405 }
391 help : 'toggle line numbers',
406 },
392 help_index : 'ga',
407 'ctrl-k' : {
393 handler : function (event) {
408 help : 'move cell up',
394 IPython.notebook.cell_toggle_line_numbers();
409 help_index : 'ea',
395 return false;
410 handler : function (event) {
396 }
411 that.notebook.move_cell_up();
397 },
412 return false;
398 'i' : {
413 }
399 help : 'interrupt kernel (press twice)',
414 },
400 help_index : 'ha',
415 'l' : {
401 count: 2,
416 help : 'toggle line numbers',
402 handler : function (event) {
417 help_index : 'ga',
403 IPython.notebook.kernel.interrupt();
418 handler : function (event) {
404 return false;
419 that.notebook.cell_toggle_line_numbers();
405 }
420 return false;
406 },
421 }
407 '0' : {
422 },
408 help : 'restart kernel (press twice)',
423 'i' : {
409 help_index : 'hb',
424 help : 'interrupt kernel (press twice)',
410 count: 2,
425 help_index : 'ha',
411 handler : function (event) {
426 count: 2,
412 IPython.notebook.restart_kernel();
427 handler : function (event) {
413 return false;
428 that.notebook.kernel.interrupt();
414 }
429 return false;
415 },
430 }
416 'h' : {
431 },
417 help : 'keyboard shortcuts',
432 '0' : {
418 help_index : 'ge',
433 help : 'restart kernel (press twice)',
419 handler : function (event) {
434 help_index : 'hb',
420 IPython.quick_help.show_keyboard_shortcuts();
435 count: 2,
421 return false;
436 handler : function (event) {
422 }
437 that.notebook.restart_kernel();
423 },
438 return false;
424 'z' : {
439 }
425 help : 'undo last delete',
440 },
426 help_index : 'ei',
441 'h' : {
427 handler : function (event) {
442 help : 'keyboard shortcuts',
428 IPython.notebook.undelete_cell();
443 help_index : 'ge',
429 return false;
444 handler : function (event) {
430 }
445 that.quick_help.show_keyboard_shortcuts();
431 },
446 return false;
432 'shift-m' : {
447 }
433 help : 'merge cell below',
448 },
434 help_index : 'ek',
449 'z' : {
435 handler : function (event) {
450 help : 'undo last delete',
436 IPython.notebook.merge_cell_below();
451 help_index : 'ei',
437 return false;
452 handler : function (event) {
438 }
453 that.notebook.undelete_cell();
439 },
454 return false;
440 'q' : {
455 }
441 help : 'close pager',
456 },
442 help_index : 'gd',
457 'shift-m' : {
443 handler : function (event) {
458 help : 'merge cell below',
444 IPython.pager.collapse();
459 help_index : 'ek',
445 return false;
460 handler : function (event) {
446 }
461 that.notebook.merge_cell_below();
447 },
462 return false;
448 };
463 }
449
464 },
450
465 'q' : {
451 // Main keyboard manager for the notebook
466 help : 'close pager',
452
467 help_index : 'gd',
453 var ShortcutManager = IPython.keyboard.ShortcutManager;
468 handler : function (event) {
454 var keycodes = IPython.keyboard.keycodes;
469 that.pager.collapse();
455
470 return false;
456 var KeyboardManager = function () {
471 }
457 this.mode = 'command';
472 },
458 this.enabled = true;
473 };
459 this.bind_events();
460 this.command_shortcuts = new ShortcutManager();
461 this.command_shortcuts.add_shortcuts(default_common_shortcuts);
462 this.command_shortcuts.add_shortcuts(default_command_shortcuts);
463 this.edit_shortcuts = new ShortcutManager();
464 this.edit_shortcuts.add_shortcuts(default_common_shortcuts);
465 this.edit_shortcuts.add_shortcuts(default_edit_shortcuts);
466 };
474 };
467
475
468 KeyboardManager.prototype.bind_events = function () {
476 KeyboardManager.prototype.bind_events = function () {
@@ -473,7 +481,7 b' var IPython = (function (IPython) {'
473 };
481 };
474
482
475 KeyboardManager.prototype.handle_keydown = function (event) {
483 KeyboardManager.prototype.handle_keydown = function (event) {
476 var notebook = IPython.notebook;
484 var notebook = this.notebook;
477
485
478 if (event.which === keycodes.esc) {
486 if (event.which === keycodes.esc) {
479 // Intercept escape at highest level to avoid closing
487 // Intercept escape at highest level to avoid closing
@@ -545,18 +553,14 b' var IPython = (function (IPython) {'
545 // is_focused must be used to check for the case where an element within
553 // is_focused must be used to check for the case where an element within
546 // the element being removed is focused.
554 // the element being removed is focused.
547 e.on('remove', function () {
555 e.on('remove', function () {
548 if (IPython.utils.is_focused(e[0])) {
556 if (utils.is_focused(e[0])) {
549 that.enable();
557 that.enable();
550 }
558 }
551 });
559 });
552 };
560 };
553
561
554
562 // For backwards compatability.
555 IPython.default_common_shortcuts = default_common_shortcuts;
556 IPython.default_edit_shortcuts = default_edit_shortcuts;
557 IPython.default_command_shortcuts = default_command_shortcuts;
558 IPython.KeyboardManager = KeyboardManager;
563 IPython.KeyboardManager = KeyboardManager;
559
564
560 return IPython;
565 return {'KeyboardManager': KeyboardManager};
561
566 });
562 }(IPython));
@@ -1,19 +1,15 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 ], function(IPython, $) {
8 //============================================================================
9 // Layout
10 //============================================================================
11
12 var IPython = (function (IPython) {
13 "use strict";
8 "use strict";
14
9
15 var LayoutManager = function () {
10 var LayoutManager = function () {
16 this.bind_events();
11 this.bind_events();
12 this.pager = undefined;
17 };
13 };
18
14
19 LayoutManager.prototype.bind_events = function () {
15 LayoutManager.prototype.bind_events = function () {
@@ -43,19 +39,20 b' var IPython = (function (IPython) {'
43 var app_height = this.app_height(); // content height
39 var app_height = this.app_height(); // content height
44
40
45 $('#ipython-main-app').height(app_height); // content+padding+border height
41 $('#ipython-main-app').height(app_height); // content+padding+border height
46
42 if (this.pager) {
47 var pager_height = IPython.pager.percentage_height*app_height;
43 var pager_height = this.pager.percentage_height*app_height;
48 var pager_splitter_height = $('div#pager_splitter').outerHeight(true);
44 var pager_splitter_height = $('div#pager_splitter').outerHeight(true);
49 $('div#pager').outerHeight(pager_height);
45 $('div#pager').outerHeight(pager_height);
50 if (IPython.pager.expanded) {
46 if (this.pager.expanded) {
51 $('div#notebook').outerHeight(app_height-pager_height-pager_splitter_height);
47 $('div#notebook').outerHeight(app_height-pager_height-pager_splitter_height);
52 } else {
48 } else {
53 $('div#notebook').outerHeight(app_height-pager_splitter_height);
49 $('div#notebook').outerHeight(app_height-pager_splitter_height);
50 }
54 }
51 }
55 };
52 };
56
53
54 // Backwards compatability.
57 IPython.LayoutManager = LayoutManager;
55 IPython.LayoutManager = LayoutManager;
58
56
59 return IPython;
57 return {'LayoutManager': LayoutManager};
60
58 });
61 }(IPython));
@@ -1,78 +1,93 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 require([
9 // On document ready
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11
7 'notebook/js/notebook',
12 // for the time beeing, we have to pass marked as a parameter here,
8 'base/js/utils',
13 // as injecting require.js make marked not to put itself in the globals,
9 'base/js/page',
14 // which make both this file fail at setting marked configuration, and textcell.js
10 'notebook/js/layoutmanager',
15 // which search marked into global.
11 'base/js/events',
16 require(['components/marked/lib/marked',
12 'auth/js/loginwidget',
17 'widgets/js/init',
13 'notebook/js/maintoolbar',
18 'components/bootstrap-tour/build/js/bootstrap-tour.min'],
14 'notebook/js/pager',
19
15 'notebook/js/quickhelp',
20 function (marked) {
16 'notebook/js/menubar',
17 'notebook/js/notificationarea',
18 'notebook/js/savewidget',
19 'notebook/js/keyboardmanager',
20 'notebook/js/config',
21 ], function(
22 IPython,
23 $,
24 notebook,
25 utils,
26 page,
27 layoutmanager,
28 events,
29 loginwidget,
30 maintoolbar,
31 pager,
32 quickhelp,
33 menubar,
34 notificationarea,
35 savewidget,
36 keyboardmanager,
37 config
38 ) {
21 "use strict";
39 "use strict";
22
40
23 window.marked = marked;
24
25 // monkey patch CM to be able to syntax highlight cell magics
26 // bug reported upstream,
27 // see https://github.com/marijnh/CodeMirror2/issues/670
28 if(CodeMirror.getMode(1,'text/plain').indent === undefined ){
29 console.log('patching CM for undefined indent');
30 CodeMirror.modes.null = function() {
31 return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}};
32 };
33 }
34
35 CodeMirror.patchedGetMode = function(config, mode){
36 var cmmode = CodeMirror.getMode(config, mode);
37 if(cmmode.indent === null) {
38 console.log('patch mode "' , mode, '" on the fly');
39 cmmode.indent = function(){return 0;};
40 }
41 return cmmode;
42 };
43 // end monkey patching CodeMirror
44
45 IPython.mathjaxutils.init();
46
47 $('#ipython-main-app').addClass('border-box-sizing');
41 $('#ipython-main-app').addClass('border-box-sizing');
48 $('div#notebook_panel').addClass('border-box-sizing');
42 $('div#notebook_panel').addClass('border-box-sizing');
49
43
50 var opts = {
44 var common_options = {
51 base_url : IPython.utils.get_body_data("baseUrl"),
45 base_url : utils.get_body_data("baseUrl"),
52 notebook_path : IPython.utils.get_body_data("notebookPath"),
46 notebook_path : utils.get_body_data("notebookPath"),
53 notebook_name : IPython.utils.get_body_data('notebookName')
47 notebook_name : utils.get_body_data('notebookName')
54 };
48 };
55
49
56 IPython.page = new IPython.Page();
50 var user_config = $.extend({}, config.default_config);
57 IPython.layout_manager = new IPython.LayoutManager();
51 var page = new page.Page();
58 IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
52 var layout_manager = new layoutmanager.LayoutManager();
59 IPython.quick_help = new IPython.QuickHelp();
53 var events = $([new events.Events()]);
60 try {
54 var pager = new pager.Pager('div#pager', 'div#pager_splitter', {
61 IPython.tour = new IPython.NotebookTour();
55 layout_manager: layout_manager,
62 } catch (e) {
56 events: events});
63 console.log("Failed to instantiate Notebook Tour", e);
57 var keyboard_manager = new keyboardmanager.KeyboardManager({
64 }
58 pager: pager,
65 IPython.login_widget = new IPython.LoginWidget('span#login_widget', opts);
59 events: events});
66 IPython.notebook = new IPython.Notebook('div#notebook', opts);
60 var save_widget = new savewidget.SaveWidget('span#save_widget', {
67 IPython.keyboard_manager = new IPython.KeyboardManager();
61 events: events,
68 IPython.save_widget = new IPython.SaveWidget('span#save_widget');
62 keyboard_manager: keyboard_manager});
69 IPython.menubar = new IPython.MenuBar('#menubar', opts);
63 var notebook = new notebook.Notebook('div#notebook', $.extend({
70 IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container');
64 events: events,
71 IPython.tooltip = new IPython.Tooltip();
65 keyboard_manager: keyboard_manager,
72 IPython.notification_area = new IPython.NotificationArea('#notification_area');
66 save_widget: save_widget,
73 IPython.notification_area.init_notification_widgets();
67 config: user_config},
74
68 common_options));
75 IPython.layout_manager.do_resize();
69 var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options);
70 var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', {
71 notebook: notebook,
72 events: events});
73 var quick_help = new quickhelp.QuickHelp({
74 keyboard_manager: keyboard_manager,
75 events: events,
76 notebook: notebook});
77 var menubar = new menubar.MenuBar('#menubar', $.extend({
78 notebook: notebook,
79 layout_manager: layout_manager,
80 events: events,
81 save_widget: save_widget,
82 quick_help: quick_help},
83 common_options));
84 var notification_area = new notificationarea.NotificationArea(
85 '#notification_area', {
86 events: events,
87 save_widget: save_widget,
88 notebook: notebook,
89 keyboard_manager: keyboard_manager});
90 notification_area.init_notification_widgets();
76
91
77 $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+
92 $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+
78 '<span id="test2" style="font-weight: bold;">x</span>'+
93 '<span id="test2" style="font-weight: bold;">x</span>'+
@@ -85,43 +100,37 b' function (marked) {'
85 }
100 }
86 $('#fonttest').remove();
101 $('#fonttest').remove();
87
102
88 IPython.page.show();
103 page.show();
89
104
90 IPython.layout_manager.do_resize();
105 layout_manager.do_resize();
91 var first_load = function () {
106 var first_load = function () {
92 IPython.layout_manager.do_resize();
107 layout_manager.do_resize();
93 var hash = document.location.hash;
108 var hash = document.location.hash;
94 if (hash) {
109 if (hash) {
95 document.location.hash = '';
110 document.location.hash = '';
96 document.location.hash = hash;
111 document.location.hash = hash;
97 }
112 }
98 IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval);
113 notebook.set_autosave_interval(notebook.minimum_autosave_interval);
99 // only do this once
114 // only do this once
100 $([IPython.events]).off('notebook_loaded.Notebook', first_load);
115 events.off('notebook_loaded.Notebook', first_load);
101 };
116 };
102
117
103 $([IPython.events]).on('notebook_loaded.Notebook', first_load);
118 events.on('notebook_loaded.Notebook', first_load);
104 $([IPython.events]).trigger('app_initialized.NotebookApp');
119 events.trigger('app_initialized.NotebookApp');
105 IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path);
120 notebook.load_notebook(common_options.notebook_name, common_options.notebook_path);
106
121
107 if (marked) {
122 IPython.page = page;
108 marked.setOptions({
123 IPython.layout_manager = layout_manager;
109 gfm : true,
124 IPython.notebook = notebook;
110 tables: true,
125 IPython.pager = pager;
111 langPrefix: "language-",
126 IPython.quick_help = quick_help;
112 highlight: function(code, lang) {
127 IPython.login_widget = login_widget;
113 if (!lang) {
128 IPython.menubar = menubar;
114 // no language, no highlight
129 IPython.toolbar = toolbar;
115 return code;
130 IPython.notification_area = notification_area;
116 }
131 IPython.events = events;
117 var highlighted;
132 IPython.keyboard_manager = keyboard_manager;
118 try {
133 IPython.save_widget = save_widget;
119 highlighted = hljs.highlight(lang, code, false);
134 IPython.config = user_config;
120 } catch(err) {
135 IPython.tooltip = notebook.tooltip;
121 highlighted = hljs.highlightAuto(code);
122 }
123 return highlighted.value;
124 }
125 });
126 }
127 });
136 });
@@ -1,35 +1,43 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'notebook/js/toolbar',
8 //============================================================================
8 'notebook/js/celltoolbar',
9 // ToolBar
9 ], function(IPython, $, toolbar, celltoolbar) {
10 //============================================================================
11
12 var IPython = (function (IPython) {
13 "use strict";
10 "use strict";
14
11
15 var MainToolBar = function (selector) {
12 var MainToolBar = function (selector, options) {
16 IPython.ToolBar.apply(this, arguments);
13 // Constructor
14 //
15 // Parameters:
16 // selector: string
17 // options: dictionary
18 // Dictionary of keyword arguments.
19 // events: $(Events) instance
20 // notebook: Notebook instance
21 toolbar.ToolBar.apply(this, arguments);
22 this.events = options.events;
23 this.notebook = options.notebook;
17 this.construct();
24 this.construct();
18 this.add_celltype_list();
25 this.add_celltype_list();
19 this.add_celltoolbar_list();
26 this.add_celltoolbar_list();
20 this.bind_events();
27 this.bind_events();
21 };
28 };
22
29
23 MainToolBar.prototype = new IPython.ToolBar();
30 MainToolBar.prototype = new toolbar.ToolBar();
24
31
25 MainToolBar.prototype.construct = function () {
32 MainToolBar.prototype.construct = function () {
33 var that = this;
26 this.add_buttons_group([
34 this.add_buttons_group([
27 {
35 {
28 id : 'save_b',
36 id : 'save_b',
29 label : 'Save and Checkpoint',
37 label : 'Save and Checkpoint',
30 icon : 'icon-save',
38 icon : 'icon-save',
31 callback : function () {
39 callback : function () {
32 IPython.notebook.save_checkpoint();
40 that.notebook.save_checkpoint();
33 }
41 }
34 }
42 }
35 ]);
43 ]);
@@ -40,9 +48,9 b' var IPython = (function (IPython) {'
40 label : 'Insert Cell Below',
48 label : 'Insert Cell Below',
41 icon : 'icon-plus-sign',
49 icon : 'icon-plus-sign',
42 callback : function () {
50 callback : function () {
43 IPython.notebook.insert_cell_below('code');
51 that.notebook.insert_cell_below('code');
44 IPython.notebook.select_next();
52 that.notebook.select_next();
45 IPython.notebook.focus_cell();
53 that.notebook.focus_cell();
46 }
54 }
47 }
55 }
48 ],'insert_above_below');
56 ],'insert_above_below');
@@ -53,7 +61,7 b' var IPython = (function (IPython) {'
53 label : 'Cut Cell',
61 label : 'Cut Cell',
54 icon : 'icon-cut',
62 icon : 'icon-cut',
55 callback : function () {
63 callback : function () {
56 IPython.notebook.cut_cell();
64 that.notebook.cut_cell();
57 }
65 }
58 },
66 },
59 {
67 {
@@ -61,7 +69,7 b' var IPython = (function (IPython) {'
61 label : 'Copy Cell',
69 label : 'Copy Cell',
62 icon : 'icon-copy',
70 icon : 'icon-copy',
63 callback : function () {
71 callback : function () {
64 IPython.notebook.copy_cell();
72 that.notebook.copy_cell();
65 }
73 }
66 },
74 },
67 {
75 {
@@ -69,7 +77,7 b' var IPython = (function (IPython) {'
69 label : 'Paste Cell Below',
77 label : 'Paste Cell Below',
70 icon : 'icon-paste',
78 icon : 'icon-paste',
71 callback : function () {
79 callback : function () {
72 IPython.notebook.paste_cell_below();
80 that.notebook.paste_cell_below();
73 }
81 }
74 }
82 }
75 ],'cut_copy_paste');
83 ],'cut_copy_paste');
@@ -80,7 +88,7 b' var IPython = (function (IPython) {'
80 label : 'Move Cell Up',
88 label : 'Move Cell Up',
81 icon : 'icon-arrow-up',
89 icon : 'icon-arrow-up',
82 callback : function () {
90 callback : function () {
83 IPython.notebook.move_cell_up();
91 that.notebook.move_cell_up();
84 }
92 }
85 },
93 },
86 {
94 {
@@ -88,7 +96,7 b' var IPython = (function (IPython) {'
88 label : 'Move Cell Down',
96 label : 'Move Cell Down',
89 icon : 'icon-arrow-down',
97 icon : 'icon-arrow-down',
90 callback : function () {
98 callback : function () {
91 IPython.notebook.move_cell_down();
99 that.notebook.move_cell_down();
92 }
100 }
93 }
101 }
94 ],'move_up_down');
102 ],'move_up_down');
@@ -101,7 +109,7 b' var IPython = (function (IPython) {'
101 icon : 'icon-play',
109 icon : 'icon-play',
102 callback : function () {
110 callback : function () {
103 // emulate default shift-enter behavior
111 // emulate default shift-enter behavior
104 IPython.notebook.execute_cell_and_select_below();
112 that.notebook.execute_cell_and_select_below();
105 }
113 }
106 },
114 },
107 {
115 {
@@ -109,7 +117,7 b' var IPython = (function (IPython) {'
109 label : 'Interrupt',
117 label : 'Interrupt',
110 icon : 'icon-stop',
118 icon : 'icon-stop',
111 callback : function () {
119 callback : function () {
112 IPython.notebook.session.interrupt_kernel();
120 that.notebook.session.interrupt_kernel();
113 }
121 }
114 },
122 },
115 {
123 {
@@ -117,7 +125,7 b' var IPython = (function (IPython) {'
117 label : 'Restart Kernel',
125 label : 'Restart Kernel',
118 icon : 'icon-repeat',
126 icon : 'icon-repeat',
119 callback : function () {
127 callback : function () {
120 IPython.notebook.restart_kernel();
128 that.notebook.restart_kernel();
121 }
129 }
122 }
130 }
123 ],'run_int');
131 ],'run_int');
@@ -150,30 +158,31 b' var IPython = (function (IPython) {'
150 .addClass('form-control select-xs')
158 .addClass('form-control select-xs')
151 .append($('<option/>').attr('value', '').text('None'));
159 .append($('<option/>').attr('value', '').text('None'));
152 this.element.append(label).append(select);
160 this.element.append(label).append(select);
161 var that = this;
153 select.change(function() {
162 select.change(function() {
154 var val = $(this).val()
163 var val = $(this).val();
155 if (val =='') {
164 if (val ==='') {
156 IPython.CellToolbar.global_hide();
165 celltoolbar.CellToolbar.global_hide();
157 delete IPython.notebook.metadata.celltoolbar;
166 delete that.notebook.metadata.celltoolbar;
158 } else {
167 } else {
159 IPython.CellToolbar.global_show();
168 celltoolbar.CellToolbar.global_show();
160 IPython.CellToolbar.activate_preset(val);
169 celltoolbar.CellToolbar.activate_preset(val, that.events);
161 IPython.notebook.metadata.celltoolbar = val;
170 that.notebook.metadata.celltoolbar = val;
162 }
171 }
163 });
172 });
164 // Setup the currently registered presets.
173 // Setup the currently registered presets.
165 var presets = IPython.CellToolbar.list_presets();
174 var presets = celltoolbar.CellToolbar.list_presets();
166 for (var i=0; i<presets.length; i++) {
175 for (var i=0; i<presets.length; i++) {
167 var name = presets[i];
176 var name = presets[i];
168 select.append($('<option/>').attr('value', name).text(name));
177 select.append($('<option/>').attr('value', name).text(name));
169 }
178 }
170 // Setup future preset registrations.
179 // Setup future preset registrations.
171 $([IPython.events]).on('preset_added.CellToolbar', function (event, data) {
180 this.events.on('preset_added.CellToolbar', function (event, data) {
172 var name = data.name;
181 var name = data.name;
173 select.append($('<option/>').attr('value', name).text(name));
182 select.append($('<option/>').attr('value', name).text(name));
174 });
183 });
175 // Update select value when a preset is activated.
184 // Update select value when a preset is activated.
176 $([IPython.events]).on('preset_activated.CellToolbar', function (event, data) {
185 this.events.on('preset_activated.CellToolbar', function (event, data) {
177 if (select.val() !== data.name)
186 if (select.val() !== data.name)
178 select.val(data.name);
187 select.val(data.name);
179 });
188 });
@@ -186,26 +195,26 b' var IPython = (function (IPython) {'
186 this.element.find('#cell_type').change(function () {
195 this.element.find('#cell_type').change(function () {
187 var cell_type = $(this).val();
196 var cell_type = $(this).val();
188 if (cell_type === 'code') {
197 if (cell_type === 'code') {
189 IPython.notebook.to_code();
198 that.notebook.to_code();
190 } else if (cell_type === 'markdown') {
199 } else if (cell_type === 'markdown') {
191 IPython.notebook.to_markdown();
200 that.notebook.to_markdown();
192 } else if (cell_type === 'raw') {
201 } else if (cell_type === 'raw') {
193 IPython.notebook.to_raw();
202 that.notebook.to_raw();
194 } else if (cell_type === 'heading1') {
203 } else if (cell_type === 'heading1') {
195 IPython.notebook.to_heading(undefined, 1);
204 that.notebook.to_heading(undefined, 1);
196 } else if (cell_type === 'heading2') {
205 } else if (cell_type === 'heading2') {
197 IPython.notebook.to_heading(undefined, 2);
206 that.notebook.to_heading(undefined, 2);
198 } else if (cell_type === 'heading3') {
207 } else if (cell_type === 'heading3') {
199 IPython.notebook.to_heading(undefined, 3);
208 that.notebook.to_heading(undefined, 3);
200 } else if (cell_type === 'heading4') {
209 } else if (cell_type === 'heading4') {
201 IPython.notebook.to_heading(undefined, 4);
210 that.notebook.to_heading(undefined, 4);
202 } else if (cell_type === 'heading5') {
211 } else if (cell_type === 'heading5') {
203 IPython.notebook.to_heading(undefined, 5);
212 that.notebook.to_heading(undefined, 5);
204 } else if (cell_type === 'heading6') {
213 } else if (cell_type === 'heading6') {
205 IPython.notebook.to_heading(undefined, 6);
214 that.notebook.to_heading(undefined, 6);
206 }
215 }
207 });
216 });
208 $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) {
217 this.events.on('selected_cell_type_changed.Notebook', function (event, data) {
209 if (data.cell_type === 'heading') {
218 if (data.cell_type === 'heading') {
210 that.element.find('#cell_type').val(data.cell_type+data.level);
219 that.element.find('#cell_type').val(data.cell_type+data.level);
211 } else {
220 } else {
@@ -214,8 +223,8 b' var IPython = (function (IPython) {'
214 });
223 });
215 };
224 };
216
225
226 // Backwards compatability.
217 IPython.MainToolBar = MainToolBar;
227 IPython.MainToolBar = MainToolBar;
218
228
219 return IPython;
229 return {'MainToolBar': MainToolBar};
220
230 });
221 }(IPython));
@@ -1,18 +1,12 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'base/js/utils',
8 //============================================================================
8 'base/js/dialog',
9 // MathJax utility functions
9 ], function(IPython, $, utils, dialog) {
10 //============================================================================
11
12
13 IPython.namespace('IPython.mathjaxutils');
14
15 IPython.mathjaxutils = (function (IPython) {
16 "use strict";
10 "use strict";
17
11
18 var init = function () {
12 var init = function () {
@@ -75,7 +69,7 b' IPython.mathjaxutils = (function (IPython) {'
75 "which will prevent this dialog from appearing."
69 "which will prevent this dialog from appearing."
76 )
70 )
77 );
71 );
78 IPython.dialog.modal({
72 dialog.modal({
79 title : "Failed to retrieve MathJax from '" + window.mathjax_url + "'",
73 title : "Failed to retrieve MathJax from '" + window.mathjax_url + "'",
80 body : message,
74 body : message,
81 buttons : {
75 buttons : {
@@ -110,7 +104,7 b' IPython.mathjaxutils = (function (IPython) {'
110 .replace(/</g, "&lt;") // use HTML entity for <
104 .replace(/</g, "&lt;") // use HTML entity for <
111 .replace(/>/g, "&gt;") // use HTML entity for >
105 .replace(/>/g, "&gt;") // use HTML entity for >
112 ;
106 ;
113 if (IPython.utils.browser === 'msie') {
107 if (utils.browser === 'msie') {
114 block = block.replace(/(%[^\n]*)\n/g, "$1<br/>\n");
108 block = block.replace(/(%[^\n]*)\n/g, "$1<br/>\n");
115 }
109 }
116 while (j > i) {
110 while (j > i) {
@@ -159,7 +153,7 b' IPython.mathjaxutils = (function (IPython) {'
159 de_tilde = function (text) { return text; };
153 de_tilde = function (text) { return text; };
160 }
154 }
161
155
162 var blocks = IPython.utils.regex_split(text.replace(/\r\n?/g, "\n"),MATHSPLIT);
156 var blocks = utils.regex_split(text.replace(/\r\n?/g, "\n"),MATHSPLIT);
163
157
164 for (var i = 1, m = blocks.length; i < m; i += 2) {
158 for (var i = 1, m = blocks.length; i < m; i += 2) {
165 var block = blocks[i];
159 var block = blocks[i];
@@ -242,10 +236,13 b' IPython.mathjaxutils = (function (IPython) {'
242 return text;
236 return text;
243 };
237 };
244
238
245 return {
239 var mathjaxutils = {
246 init : init,
240 init : init,
247 remove_math : remove_math,
241 remove_math : remove_math,
248 replace_math : replace_math
242 replace_math : replace_math
249 };
243 };
250
244
251 }(IPython));
245 IPython.mathjaxutils = mathjaxutils;
246
247 return mathjaxutils;
248 });
@@ -1,40 +1,48 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 //============================================================================
4 define([
5 // MenuBar
5 'base/js/namespace',
6 //============================================================================
6 'jquery',
7
7 'base/js/utils',
8 /**
8 'notebook/js/tour',
9 * @module IPython
9 'components/bootstrap/js/bootstrap.min',
10 * @namespace IPython
10 ], function(IPython, $, utils, tour) {
11 * @submodule MenuBar
12 */
13
14
15 var IPython = (function (IPython) {
16 "use strict";
11 "use strict";
17
12
18 var utils = IPython.utils;
19
20 /**
21 * A MenuBar Class to generate the menubar of IPython notebook
22 * @Class MenuBar
23 *
24 * @constructor
25 *
26 *
27 * @param selector {string} selector for the menubar element in DOM
28 * @param {object} [options]
29 * @param [options.base_url] {String} String to use for the
30 * base project url. Default is to inspect
31 * $('body').data('baseUrl');
32 * does not support change for now is set through this option
33 */
34 var MenuBar = function (selector, options) {
13 var MenuBar = function (selector, options) {
14 // Constructor
15 //
16 // A MenuBar Class to generate the menubar of IPython notebook
17 //
18 // Parameters:
19 // selector: string
20 // options: dictionary
21 // Dictionary of keyword arguments.
22 // notebook: Notebook instance
23 // layout_manager: LayoutManager instance
24 // events: $(Events) instance
25 // save_widget: SaveWidget instance
26 // quick_help: QuickHelp instance
27 // base_url : string
28 // notebook_path : string
29 // notebook_name : string
35 options = options || {};
30 options = options || {};
36 this.base_url = options.base_url || IPython.utils.get_body_data("baseUrl");
31 this.base_url = options.base_url || utils.get_body_data("baseUrl");
37 this.selector = selector;
32 this.selector = selector;
33 this.notebook = options.notebook;
34 this.layout_manager = options.layout_manager;
35 this.events = options.events;
36 this.save_widget = options.save_widget;
37 this.quick_help = options.quick_help;
38
39 try {
40 this.tour = new tour.Tour(this.notebook, this.events);
41 } catch (e) {
42 this.tour = undefined;
43 console.log("Failed to instantiate Notebook Tour", e);
44 }
45
38 if (this.selector !== undefined) {
46 if (this.selector !== undefined) {
39 this.element = $(selector);
47 this.element = $(selector);
40 this.style();
48 this.style();
@@ -43,22 +51,23 b' var IPython = (function (IPython) {'
43 };
51 };
44
52
45 MenuBar.prototype.style = function () {
53 MenuBar.prototype.style = function () {
54 var that = this;
46 this.element.addClass('border-box-sizing');
55 this.element.addClass('border-box-sizing');
47 this.element.find("li").click(function (event, ui) {
56 this.element.find("li").click(function (event, ui) {
48 // The selected cell loses focus when the menu is entered, so we
57 // The selected cell loses focus when the menu is entered, so we
49 // re-select it upon selection.
58 // re-select it upon selection.
50 var i = IPython.notebook.get_selected_index();
59 var i = that.notebook.get_selected_index();
51 IPython.notebook.select(i);
60 that.notebook.select(i);
52 }
61 }
53 );
62 );
54 };
63 };
55
64
56 MenuBar.prototype._nbconvert = function (format, download) {
65 MenuBar.prototype._nbconvert = function (format, download) {
57 download = download || false;
66 download = download || false;
58 var notebook_path = IPython.notebook.notebook_path;
67 var notebook_path = this.notebook.notebook_path;
59 var notebook_name = IPython.notebook.notebook_name;
68 var notebook_name = this.notebook.notebook_name;
60 if (IPython.notebook.dirty) {
69 if (this.notebook.dirty) {
61 IPython.notebook.save_notebook({async : false});
70 this.notebook.save_notebook({async : false});
62 }
71 }
63 var url = utils.url_join_encode(
72 var url = utils.url_join_encode(
64 this.base_url,
73 this.base_url,
@@ -75,25 +84,25 b' var IPython = (function (IPython) {'
75 // File
84 // File
76 var that = this;
85 var that = this;
77 this.element.find('#new_notebook').click(function () {
86 this.element.find('#new_notebook').click(function () {
78 IPython.notebook.new_notebook();
87 that.notebook.new_notebook();
79 });
88 });
80 this.element.find('#open_notebook').click(function () {
89 this.element.find('#open_notebook').click(function () {
81 window.open(utils.url_join_encode(
90 window.open(utils.url_join_encode(
82 IPython.notebook.base_url,
91 that.notebook.base_url,
83 'tree',
92 'tree',
84 IPython.notebook.notebook_path
93 that.notebook.notebook_path
85 ));
94 ));
86 });
95 });
87 this.element.find('#copy_notebook').click(function () {
96 this.element.find('#copy_notebook').click(function () {
88 IPython.notebook.copy_notebook();
97 that.notebook.copy_notebook();
89 return false;
98 return false;
90 });
99 });
91 this.element.find('#download_ipynb').click(function () {
100 this.element.find('#download_ipynb').click(function () {
92 var base_url = IPython.notebook.base_url;
101 var base_url = that.notebook.base_url;
93 var notebook_path = IPython.notebook.notebook_path;
102 var notebook_path = that.notebook.notebook_path;
94 var notebook_name = IPython.notebook.notebook_name;
103 var notebook_name = that.notebook.notebook_name;
95 if (IPython.notebook.dirty) {
104 if (that.notebook.dirty) {
96 IPython.notebook.save_notebook({async : false});
105 that.notebook.save_notebook({async : false});
97 }
106 }
98
107
99 var url = utils.url_join_encode(
108 var url = utils.url_join_encode(
@@ -126,17 +135,17 b' var IPython = (function (IPython) {'
126 });
135 });
127
136
128 this.element.find('#rename_notebook').click(function () {
137 this.element.find('#rename_notebook').click(function () {
129 IPython.save_widget.rename_notebook();
138 that.save_widget.rename_notebook({notebook: that.notebook});
130 });
139 });
131 this.element.find('#save_checkpoint').click(function () {
140 this.element.find('#save_checkpoint').click(function () {
132 IPython.notebook.save_checkpoint();
141 that.notebook.save_checkpoint();
133 });
142 });
134 this.element.find('#restore_checkpoint').click(function () {
143 this.element.find('#restore_checkpoint').click(function () {
135 });
144 });
136 this.element.find('#trust_notebook').click(function () {
145 this.element.find('#trust_notebook').click(function () {
137 IPython.notebook.trust_notebook();
146 that.notebook.trust_notebook();
138 });
147 });
139 $([IPython.events]).on('trust_changed.Notebook', function (event, trusted) {
148 this.events.on('trust_changed.Notebook', function (event, trusted) {
140 if (trusted) {
149 if (trusted) {
141 that.element.find('#trust_notebook')
150 that.element.find('#trust_notebook')
142 .addClass("disabled")
151 .addClass("disabled")
@@ -148,7 +157,7 b' var IPython = (function (IPython) {'
148 }
157 }
149 });
158 });
150 this.element.find('#kill_and_exit').click(function () {
159 this.element.find('#kill_and_exit').click(function () {
151 IPython.notebook.session.delete();
160 that.notebook.session.delete();
152 setTimeout(function(){
161 setTimeout(function(){
153 // allow closing of new tabs in Chromium, impossible in FF
162 // allow closing of new tabs in Chromium, impossible in FF
154 window.open('', '_self', '');
163 window.open('', '_self', '');
@@ -157,148 +166,150 b' var IPython = (function (IPython) {'
157 });
166 });
158 // Edit
167 // Edit
159 this.element.find('#cut_cell').click(function () {
168 this.element.find('#cut_cell').click(function () {
160 IPython.notebook.cut_cell();
169 that.notebook.cut_cell();
161 });
170 });
162 this.element.find('#copy_cell').click(function () {
171 this.element.find('#copy_cell').click(function () {
163 IPython.notebook.copy_cell();
172 that.notebook.copy_cell();
164 });
173 });
165 this.element.find('#delete_cell').click(function () {
174 this.element.find('#delete_cell').click(function () {
166 IPython.notebook.delete_cell();
175 that.notebook.delete_cell();
167 });
176 });
168 this.element.find('#undelete_cell').click(function () {
177 this.element.find('#undelete_cell').click(function () {
169 IPython.notebook.undelete_cell();
178 that.notebook.undelete_cell();
170 });
179 });
171 this.element.find('#split_cell').click(function () {
180 this.element.find('#split_cell').click(function () {
172 IPython.notebook.split_cell();
181 that.notebook.split_cell();
173 });
182 });
174 this.element.find('#merge_cell_above').click(function () {
183 this.element.find('#merge_cell_above').click(function () {
175 IPython.notebook.merge_cell_above();
184 that.notebook.merge_cell_above();
176 });
185 });
177 this.element.find('#merge_cell_below').click(function () {
186 this.element.find('#merge_cell_below').click(function () {
178 IPython.notebook.merge_cell_below();
187 that.notebook.merge_cell_below();
179 });
188 });
180 this.element.find('#move_cell_up').click(function () {
189 this.element.find('#move_cell_up').click(function () {
181 IPython.notebook.move_cell_up();
190 that.notebook.move_cell_up();
182 });
191 });
183 this.element.find('#move_cell_down').click(function () {
192 this.element.find('#move_cell_down').click(function () {
184 IPython.notebook.move_cell_down();
193 that.notebook.move_cell_down();
185 });
194 });
186 this.element.find('#edit_nb_metadata').click(function () {
195 this.element.find('#edit_nb_metadata').click(function () {
187 IPython.notebook.edit_metadata();
196 that.notebook.edit_metadata({
197 notebook: that.notebook,
198 keyboard_manager: that.notebook.keyboard_manager});
188 });
199 });
189
200
190 // View
201 // View
191 this.element.find('#toggle_header').click(function () {
202 this.element.find('#toggle_header').click(function () {
192 $('div#header').toggle();
203 $('div#header').toggle();
193 IPython.layout_manager.do_resize();
204 that.layout_manager.do_resize();
194 });
205 });
195 this.element.find('#toggle_toolbar').click(function () {
206 this.element.find('#toggle_toolbar').click(function () {
196 $('div#maintoolbar').toggle();
207 $('div#maintoolbar').toggle();
197 IPython.layout_manager.do_resize();
208 that.layout_manager.do_resize();
198 });
209 });
199 // Insert
210 // Insert
200 this.element.find('#insert_cell_above').click(function () {
211 this.element.find('#insert_cell_above').click(function () {
201 IPython.notebook.insert_cell_above('code');
212 that.notebook.insert_cell_above('code');
202 IPython.notebook.select_prev();
213 that.notebook.select_prev();
203 });
214 });
204 this.element.find('#insert_cell_below').click(function () {
215 this.element.find('#insert_cell_below').click(function () {
205 IPython.notebook.insert_cell_below('code');
216 that.notebook.insert_cell_below('code');
206 IPython.notebook.select_next();
217 that.notebook.select_next();
207 });
218 });
208 // Cell
219 // Cell
209 this.element.find('#run_cell').click(function () {
220 this.element.find('#run_cell').click(function () {
210 IPython.notebook.execute_cell();
221 that.notebook.execute_cell();
211 });
222 });
212 this.element.find('#run_cell_select_below').click(function () {
223 this.element.find('#run_cell_select_below').click(function () {
213 IPython.notebook.execute_cell_and_select_below();
224 that.notebook.execute_cell_and_select_below();
214 });
225 });
215 this.element.find('#run_cell_insert_below').click(function () {
226 this.element.find('#run_cell_insert_below').click(function () {
216 IPython.notebook.execute_cell_and_insert_below();
227 that.notebook.execute_cell_and_insert_below();
217 });
228 });
218 this.element.find('#run_all_cells').click(function () {
229 this.element.find('#run_all_cells').click(function () {
219 IPython.notebook.execute_all_cells();
230 that.notebook.execute_all_cells();
220 });
231 });
221 this.element.find('#run_all_cells_above').click(function () {
232 this.element.find('#run_all_cells_above').click(function () {
222 IPython.notebook.execute_cells_above();
233 that.notebook.execute_cells_above();
223 });
234 });
224 this.element.find('#run_all_cells_below').click(function () {
235 this.element.find('#run_all_cells_below').click(function () {
225 IPython.notebook.execute_cells_below();
236 that.notebook.execute_cells_below();
226 });
237 });
227 this.element.find('#to_code').click(function () {
238 this.element.find('#to_code').click(function () {
228 IPython.notebook.to_code();
239 that.notebook.to_code();
229 });
240 });
230 this.element.find('#to_markdown').click(function () {
241 this.element.find('#to_markdown').click(function () {
231 IPython.notebook.to_markdown();
242 that.notebook.to_markdown();
232 });
243 });
233 this.element.find('#to_raw').click(function () {
244 this.element.find('#to_raw').click(function () {
234 IPython.notebook.to_raw();
245 that.notebook.to_raw();
235 });
246 });
236 this.element.find('#to_heading1').click(function () {
247 this.element.find('#to_heading1').click(function () {
237 IPython.notebook.to_heading(undefined, 1);
248 that.notebook.to_heading(undefined, 1);
238 });
249 });
239 this.element.find('#to_heading2').click(function () {
250 this.element.find('#to_heading2').click(function () {
240 IPython.notebook.to_heading(undefined, 2);
251 that.notebook.to_heading(undefined, 2);
241 });
252 });
242 this.element.find('#to_heading3').click(function () {
253 this.element.find('#to_heading3').click(function () {
243 IPython.notebook.to_heading(undefined, 3);
254 that.notebook.to_heading(undefined, 3);
244 });
255 });
245 this.element.find('#to_heading4').click(function () {
256 this.element.find('#to_heading4').click(function () {
246 IPython.notebook.to_heading(undefined, 4);
257 that.notebook.to_heading(undefined, 4);
247 });
258 });
248 this.element.find('#to_heading5').click(function () {
259 this.element.find('#to_heading5').click(function () {
249 IPython.notebook.to_heading(undefined, 5);
260 that.notebook.to_heading(undefined, 5);
250 });
261 });
251 this.element.find('#to_heading6').click(function () {
262 this.element.find('#to_heading6').click(function () {
252 IPython.notebook.to_heading(undefined, 6);
263 that.notebook.to_heading(undefined, 6);
253 });
264 });
254
265
255 this.element.find('#toggle_current_output').click(function () {
266 this.element.find('#toggle_current_output').click(function () {
256 IPython.notebook.toggle_output();
267 that.notebook.toggle_output();
257 });
268 });
258 this.element.find('#toggle_current_output_scroll').click(function () {
269 this.element.find('#toggle_current_output_scroll').click(function () {
259 IPython.notebook.toggle_output_scroll();
270 that.notebook.toggle_output_scroll();
260 });
271 });
261 this.element.find('#clear_current_output').click(function () {
272 this.element.find('#clear_current_output').click(function () {
262 IPython.notebook.clear_output();
273 that.notebook.clear_output();
263 });
274 });
264
275
265 this.element.find('#toggle_all_output').click(function () {
276 this.element.find('#toggle_all_output').click(function () {
266 IPython.notebook.toggle_all_output();
277 that.notebook.toggle_all_output();
267 });
278 });
268 this.element.find('#toggle_all_output_scroll').click(function () {
279 this.element.find('#toggle_all_output_scroll').click(function () {
269 IPython.notebook.toggle_all_output_scroll();
280 that.notebook.toggle_all_output_scroll();
270 });
281 });
271 this.element.find('#clear_all_output').click(function () {
282 this.element.find('#clear_all_output').click(function () {
272 IPython.notebook.clear_all_output();
283 that.notebook.clear_all_output();
273 });
284 });
274
285
275 // Kernel
286 // Kernel
276 this.element.find('#int_kernel').click(function () {
287 this.element.find('#int_kernel').click(function () {
277 IPython.notebook.session.interrupt_kernel();
288 that.notebook.session.interrupt_kernel();
278 });
289 });
279 this.element.find('#restart_kernel').click(function () {
290 this.element.find('#restart_kernel').click(function () {
280 IPython.notebook.restart_kernel();
291 that.notebook.restart_kernel();
281 });
292 });
282 // Help
293 // Help
283 if (IPython.tour) {
294 if (this.tour) {
284 this.element.find('#notebook_tour').click(function () {
295 this.element.find('#notebook_tour').click(function () {
285 IPython.tour.start();
296 that.tour.start();
286 });
297 });
287 } else {
298 } else {
288 this.element.find('#notebook_tour').addClass("disabled");
299 this.element.find('#notebook_tour').addClass("disabled");
289 }
300 }
290 this.element.find('#keyboard_shortcuts').click(function () {
301 this.element.find('#keyboard_shortcuts').click(function () {
291 IPython.quick_help.show_keyboard_shortcuts();
302 that.quick_help.show_keyboard_shortcuts();
292 });
303 });
293
304
294 this.update_restore_checkpoint(null);
305 this.update_restore_checkpoint(null);
295
306
296 $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
307 this.events.on('checkpoints_listed.Notebook', function (event, data) {
297 that.update_restore_checkpoint(IPython.notebook.checkpoints);
308 that.update_restore_checkpoint(that.notebook.checkpoints);
298 });
309 });
299
310
300 $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
311 this.events.on('checkpoint_created.Notebook', function (event, data) {
301 that.update_restore_checkpoint(IPython.notebook.checkpoints);
312 that.update_restore_checkpoint(that.notebook.checkpoints);
302 });
313 });
303 };
314 };
304
315
@@ -317,6 +328,7 b' var IPython = (function (IPython) {'
317 return;
328 return;
318 }
329 }
319
330
331 var that = this;
320 checkpoints.map(function (checkpoint) {
332 checkpoints.map(function (checkpoint) {
321 var d = new Date(checkpoint.last_modified);
333 var d = new Date(checkpoint.last_modified);
322 ul.append(
334 ul.append(
@@ -325,15 +337,15 b' var IPython = (function (IPython) {'
325 .attr("href", "#")
337 .attr("href", "#")
326 .text(d.format("mmm dd HH:MM:ss"))
338 .text(d.format("mmm dd HH:MM:ss"))
327 .click(function () {
339 .click(function () {
328 IPython.notebook.restore_checkpoint_dialog(checkpoint);
340 that.notebook.restore_checkpoint_dialog(checkpoint);
329 })
341 })
330 )
342 )
331 );
343 );
332 });
344 });
333 };
345 };
334
346
347 // Backwards compatability.
335 IPython.MenuBar = MenuBar;
348 IPython.MenuBar = MenuBar;
336
349
337 return IPython;
350 return {'MenuBar': MenuBar};
338
351 });
339 }(IPython));
@@ -1,32 +1,92 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7 'base/js/utils',
8 'base/js/dialog',
9 'notebook/js/textcell',
10 'notebook/js/codecell',
11 'services/sessions/js/session',
12 'notebook/js/celltoolbar',
13 'components/marked/lib/marked',
14 'notebook/js/mathjaxutils',
15 'base/js/keyboard',
16 'notebook/js/tooltip',
17 'notebook/js/celltoolbarpresets/default',
18 'notebook/js/celltoolbarpresets/rawcell',
19 'notebook/js/celltoolbarpresets/slideshow',
20 ], function (
21 IPython,
22 $,
23 utils,
24 dialog,
25 textcell,
26 codecell,
27 session,
28 celltoolbar,
29 marked,
30 mathjaxutils,
31 keyboard,
32 tooltip,
33 default_celltoolbar,
34 rawcell_celltoolbar,
35 slideshow_celltoolbar
36 ) {
7
37
8 //============================================================================
9 // Notebook
10 //============================================================================
11
12 var IPython = (function (IPython) {
13 "use strict";
14
15 var utils = IPython.utils;
16
17 /**
18 * A notebook contains and manages cells.
19 *
20 * @class Notebook
21 * @constructor
22 * @param {String} selector A jQuery selector for the notebook's DOM element
23 * @param {Object} [options] A config object
24 */
25 var Notebook = function (selector, options) {
38 var Notebook = function (selector, options) {
26 this.options = options = options || {};
39 // Constructor
40 //
41 // A notebook contains and manages cells.
42 //
43 // Parameters:
44 // selector: string
45 // options: dictionary
46 // Dictionary of keyword arguments.
47 // events: $(Events) instance
48 // keyboard_manager: KeyboardManager instance
49 // save_widget: SaveWidget instance
50 // config: dictionary
51 // base_url : string
52 // notebook_path : string
53 // notebook_name : string
54 this.config = options.config || {};
27 this.base_url = options.base_url;
55 this.base_url = options.base_url;
28 this.notebook_path = options.notebook_path;
56 this.notebook_path = options.notebook_path;
29 this.notebook_name = options.notebook_name;
57 this.notebook_name = options.notebook_name;
58 this.events = options.events;
59 this.keyboard_manager = options.keyboard_manager;
60 this.save_widget = options.save_widget;
61 this.tooltip = new tooltip.Tooltip(this.events);
62 // TODO: This code smells (and the other `= this` line a couple lines down)
63 // We need a better way to deal with circular instance references.
64 this.keyboard_manager.notebook = this;
65 this.save_widget.notebook = this;
66
67 mathjaxutils.init();
68
69 if (marked) {
70 marked.setOptions({
71 gfm : true,
72 tables: true,
73 langPrefix: "language-",
74 highlight: function(code, lang) {
75 if (!lang) {
76 // no language, no highlight
77 return code;
78 }
79 var highlighted;
80 try {
81 highlighted = hljs.highlight(lang, code, false);
82 } catch(err) {
83 highlighted = hljs.highlightAuto(code);
84 }
85 return highlighted.value;
86 }
87 });
88 }
89
30 this.element = $(selector);
90 this.element = $(selector);
31 this.element.scroll();
91 this.element.scroll();
32 this.element.data("notebook", this);
92 this.element.data("notebook", this);
@@ -61,6 +121,11 b' var IPython = (function (IPython) {'
61 this.save_notebook = function() { // don't allow save until notebook_loaded
121 this.save_notebook = function() { // don't allow save until notebook_loaded
62 this.save_notebook_error(null, null, "Load failed, save is disabled");
122 this.save_notebook_error(null, null, "Load failed, save is disabled");
63 };
123 };
124
125 // Trigger cell toolbar registration.
126 default_celltoolbar.register(this, options.events);
127 rawcell_celltoolbar.register(this, options.events);
128 slideshow_celltoolbar.register(this, options.events);
64 };
129 };
65
130
66 /**
131 /**
@@ -102,36 +167,38 b' var IPython = (function (IPython) {'
102 Notebook.prototype.bind_events = function () {
167 Notebook.prototype.bind_events = function () {
103 var that = this;
168 var that = this;
104
169
105 $([IPython.events]).on('set_next_input.Notebook', function (event, data) {
170 this.events.on('set_next_input.Notebook', function (event, data) {
106 var index = that.find_cell_index(data.cell);
171 var index = that.find_cell_index(data.cell);
107 var new_cell = that.insert_cell_below('code',index);
172 var new_cell = that.insert_cell_below('code',index);
108 new_cell.set_text(data.text);
173 new_cell.set_text(data.text);
109 that.dirty = true;
174 that.dirty = true;
110 });
175 });
111
176
112 $([IPython.events]).on('set_dirty.Notebook', function (event, data) {
177 this.events.on('set_dirty.Notebook', function (event, data) {
113 that.dirty = data.value;
178 that.dirty = data.value;
114 });
179 });
115
180
116 $([IPython.events]).on('trust_changed.Notebook', function (event, data) {
181 this.events.on('trust_changed.Notebook', function (event, data) {
117 that.trusted = data.value;
182 that.trusted = data.value;
118 });
183 });
119
184
120 $([IPython.events]).on('select.Cell', function (event, data) {
185 this.events.on('select.Cell', function (event, data) {
121 var index = that.find_cell_index(data.cell);
186 var index = that.find_cell_index(data.cell);
122 that.select(index);
187 that.select(index);
123 });
188 });
124
189
125 $([IPython.events]).on('edit_mode.Cell', function (event, data) {
190 this.events.on('edit_mode.Cell', function (event, data) {
126 that.handle_edit_mode(data.cell);
191 that.handle_edit_mode(data.cell);
127 });
192 });
128
193
129 $([IPython.events]).on('command_mode.Cell', function (event, data) {
194 this.events.on('command_mode.Cell', function (event, data) {
130 that.handle_command_mode(data.cell);
195 that.handle_command_mode(data.cell);
131 });
196 });
132
197
133 $([IPython.events]).on('status_autorestarting.Kernel', function () {
198 this.events.on('status_autorestarting.Kernel', function () {
134 IPython.dialog.modal({
199 dialog.modal({
200 notebook: that,
201 keyboard_manager: that.keyboard_manager,
135 title: "Kernel Restarting",
202 title: "Kernel Restarting",
136 body: "The kernel appears to have died. It will restart automatically.",
203 body: "The kernel appears to have died. It will restart automatically.",
137 buttons: {
204 buttons: {
@@ -211,7 +278,7 b' var IPython = (function (IPython) {'
211 if (this.dirty == value) {
278 if (this.dirty == value) {
212 return;
279 return;
213 }
280 }
214 $([IPython.events]).trigger('set_dirty.Notebook', {value: value});
281 this.events.trigger('set_dirty.Notebook', {value: value});
215 };
282 };
216
283
217 /**
284 /**
@@ -254,9 +321,14 b' var IPython = (function (IPython) {'
254
321
255 Notebook.prototype.edit_metadata = function () {
322 Notebook.prototype.edit_metadata = function () {
256 var that = this;
323 var that = this;
257 IPython.dialog.edit_metadata(this.metadata, function (md) {
324 dialog.edit_metadata({
258 that.metadata = md;
325 md: this.metadata,
259 }, 'Notebook');
326 callback: function (md) {
327 that.metadata = md;
328 },
329 name: 'Notebook',
330 notebook: this,
331 keyboard_manager: this.keyboard_manager});
260 };
332 };
261
333
262 // Cell indexing, retrieval, etc.
334 // Cell indexing, retrieval, etc.
@@ -295,7 +367,7 b' var IPython = (function (IPython) {'
295 * @return {Cell} Cell or null if no cell was found.
367 * @return {Cell} Cell or null if no cell was found.
296 */
368 */
297 Notebook.prototype.get_msg_cell = function (msg_id) {
369 Notebook.prototype.get_msg_cell = function (msg_id) {
298 return IPython.CodeCell.msg_cells[msg_id] || null;
370 return codecell.CodeCell.msg_cells[msg_id] || null;
299 };
371 };
300
372
301 /**
373 /**
@@ -474,11 +546,11 b' var IPython = (function (IPython) {'
474 var cell = this.get_cell(index);
546 var cell = this.get_cell(index);
475 cell.select();
547 cell.select();
476 if (cell.cell_type === 'heading') {
548 if (cell.cell_type === 'heading') {
477 $([IPython.events]).trigger('selected_cell_type_changed.Notebook',
549 this.events.trigger('selected_cell_type_changed.Notebook',
478 {'cell_type':cell.cell_type,level:cell.level}
550 {'cell_type':cell.cell_type,level:cell.level}
479 );
551 );
480 } else {
552 } else {
481 $([IPython.events]).trigger('selected_cell_type_changed.Notebook',
553 this.events.trigger('selected_cell_type_changed.Notebook',
482 {'cell_type':cell.cell_type}
554 {'cell_type':cell.cell_type}
483 );
555 );
484 }
556 }
@@ -540,8 +612,8 b' var IPython = (function (IPython) {'
540 if (this.mode !== 'command') {
612 if (this.mode !== 'command') {
541 cell.command_mode();
613 cell.command_mode();
542 this.mode = 'command';
614 this.mode = 'command';
543 $([IPython.events]).trigger('command_mode.Notebook');
615 this.events.trigger('command_mode.Notebook');
544 IPython.keyboard_manager.command_mode();
616 this.keyboard_manager.command_mode();
545 }
617 }
546 };
618 };
547
619
@@ -570,8 +642,8 b' var IPython = (function (IPython) {'
570 if (cell && this.mode !== 'edit') {
642 if (cell && this.mode !== 'edit') {
571 cell.edit_mode();
643 cell.edit_mode();
572 this.mode = 'edit';
644 this.mode = 'edit';
573 $([IPython.events]).trigger('edit_mode.Notebook');
645 this.events.trigger('edit_mode.Notebook');
574 IPython.keyboard_manager.edit_mode();
646 this.keyboard_manager.edit_mode();
575 }
647 }
576 };
648 };
577
649
@@ -686,7 +758,7 b' var IPython = (function (IPython) {'
686 this.undelete_index = i;
758 this.undelete_index = i;
687 this.undelete_below = false;
759 this.undelete_below = false;
688 }
760 }
689 $([IPython.events]).trigger('delete.Cell', {'cell': cell, 'index': i});
761 this.events.trigger('delete.Cell', {'cell': cell, 'index': i});
690 this.set_dirty(true);
762 this.set_dirty(true);
691 }
763 }
692 return this;
764 return this;
@@ -753,20 +825,27 b' var IPython = (function (IPython) {'
753 type = type || this.get_selected_cell().cell_type;
825 type = type || this.get_selected_cell().cell_type;
754
826
755 if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
827 if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
828 var cell_options = {
829 events: this.events,
830 config: this.config,
831 keyboard_manager: this.keyboard_manager,
832 notebook: this,
833 tooltip: this.tooltip,
834 };
756 if (type === 'code') {
835 if (type === 'code') {
757 cell = new IPython.CodeCell(this.kernel);
836 cell = new codecell.CodeCell(this.kernel, cell_options);
758 cell.set_input_prompt();
837 cell.set_input_prompt();
759 } else if (type === 'markdown') {
838 } else if (type === 'markdown') {
760 cell = new IPython.MarkdownCell();
839 cell = new textcell.MarkdownCell(cell_options);
761 } else if (type === 'raw') {
840 } else if (type === 'raw') {
762 cell = new IPython.RawCell();
841 cell = new textcell.RawCell(cell_options);
763 } else if (type === 'heading') {
842 } else if (type === 'heading') {
764 cell = new IPython.HeadingCell();
843 cell = new textcell.HeadingCell(cell_options);
765 }
844 }
766
845
767 if(this._insert_element_at_index(cell.element,index)) {
846 if(this._insert_element_at_index(cell.element,index)) {
768 cell.render();
847 cell.render();
769 $([IPython.events]).trigger('create.Cell', {'cell': cell, 'index': index});
848 this.events.trigger('create.Cell', {'cell': cell, 'index': index});
770 cell.refresh();
849 cell.refresh();
771 // We used to select the cell after we refresh it, but there
850 // We used to select the cell after we refresh it, but there
772 // are now cases were this method is called where select is
851 // are now cases were this method is called where select is
@@ -876,7 +955,7 b' var IPython = (function (IPython) {'
876 if (this.is_valid_cell_index(i)) {
955 if (this.is_valid_cell_index(i)) {
877 var source_element = this.get_cell_element(i);
956 var source_element = this.get_cell_element(i);
878 var source_cell = source_element.data("cell");
957 var source_cell = source_element.data("cell");
879 if (!(source_cell instanceof IPython.CodeCell)) {
958 if (!(source_cell instanceof codecell.CodeCell)) {
880 var target_cell = this.insert_cell_below('code',i);
959 var target_cell = this.insert_cell_below('code',i);
881 var text = source_cell.get_text();
960 var text = source_cell.get_text();
882 if (text === source_cell.placeholder) {
961 if (text === source_cell.placeholder) {
@@ -906,7 +985,7 b' var IPython = (function (IPython) {'
906 if (this.is_valid_cell_index(i)) {
985 if (this.is_valid_cell_index(i)) {
907 var source_element = this.get_cell_element(i);
986 var source_element = this.get_cell_element(i);
908 var source_cell = source_element.data("cell");
987 var source_cell = source_element.data("cell");
909 if (!(source_cell instanceof IPython.MarkdownCell)) {
988 if (!(source_cell instanceof textcell.MarkdownCell)) {
910 var target_cell = this.insert_cell_below('markdown',i);
989 var target_cell = this.insert_cell_below('markdown',i);
911 var text = source_cell.get_text();
990 var text = source_cell.get_text();
912 if (text === source_cell.placeholder) {
991 if (text === source_cell.placeholder) {
@@ -920,7 +999,7 b' var IPython = (function (IPython) {'
920 target_cell.code_mirror.clearHistory();
999 target_cell.code_mirror.clearHistory();
921 source_element.remove();
1000 source_element.remove();
922 this.select(i);
1001 this.select(i);
923 if ((source_cell instanceof IPython.TextCell) && source_cell.rendered) {
1002 if ((source_cell instanceof textcell.TextCell) && source_cell.rendered) {
924 target_cell.render();
1003 target_cell.render();
925 }
1004 }
926 var cursor = source_cell.code_mirror.getCursor();
1005 var cursor = source_cell.code_mirror.getCursor();
@@ -942,7 +1021,7 b' var IPython = (function (IPython) {'
942 var source_element = this.get_cell_element(i);
1021 var source_element = this.get_cell_element(i);
943 var source_cell = source_element.data("cell");
1022 var source_cell = source_element.data("cell");
944 var target_cell = null;
1023 var target_cell = null;
945 if (!(source_cell instanceof IPython.RawCell)) {
1024 if (!(source_cell instanceof textcell.RawCell)) {
946 target_cell = this.insert_cell_below('raw',i);
1025 target_cell = this.insert_cell_below('raw',i);
947 var text = source_cell.get_text();
1026 var text = source_cell.get_text();
948 if (text === source_cell.placeholder) {
1027 if (text === source_cell.placeholder) {
@@ -977,7 +1056,7 b' var IPython = (function (IPython) {'
977 var source_element = this.get_cell_element(i);
1056 var source_element = this.get_cell_element(i);
978 var source_cell = source_element.data("cell");
1057 var source_cell = source_element.data("cell");
979 var target_cell = null;
1058 var target_cell = null;
980 if (source_cell instanceof IPython.HeadingCell) {
1059 if (source_cell instanceof textcell.HeadingCell) {
981 source_cell.set_level(level);
1060 source_cell.set_level(level);
982 } else {
1061 } else {
983 target_cell = this.insert_cell_below('heading',i);
1062 target_cell = this.insert_cell_below('heading',i);
@@ -996,12 +1075,12 b' var IPython = (function (IPython) {'
996 this.select(i);
1075 this.select(i);
997 var cursor = source_cell.code_mirror.getCursor();
1076 var cursor = source_cell.code_mirror.getCursor();
998 target_cell.code_mirror.setCursor(cursor);
1077 target_cell.code_mirror.setCursor(cursor);
999 if ((source_cell instanceof IPython.TextCell) && source_cell.rendered) {
1078 if ((source_cell instanceof textcell.TextCell) && source_cell.rendered) {
1000 target_cell.render();
1079 target_cell.render();
1001 }
1080 }
1002 }
1081 }
1003 this.set_dirty(true);
1082 this.set_dirty(true);
1004 $([IPython.events]).trigger('selected_cell_type_changed.Notebook',
1083 this.events.trigger('selected_cell_type_changed.Notebook',
1005 {'cell_type':'heading',level:level}
1084 {'cell_type':'heading',level:level}
1006 );
1085 );
1007 }
1086 }
@@ -1115,13 +1194,13 b' var IPython = (function (IPython) {'
1115 * @method split_cell
1194 * @method split_cell
1116 */
1195 */
1117 Notebook.prototype.split_cell = function () {
1196 Notebook.prototype.split_cell = function () {
1118 var mdc = IPython.MarkdownCell;
1197 var mdc = textcell.MarkdownCell;
1119 var rc = IPython.RawCell;
1198 var rc = textcell.RawCell;
1120 var cell = this.get_selected_cell();
1199 var cell = this.get_selected_cell();
1121 if (cell.is_splittable()) {
1200 if (cell.is_splittable()) {
1122 var texta = cell.get_pre_cursor();
1201 var texta = cell.get_pre_cursor();
1123 var textb = cell.get_post_cursor();
1202 var textb = cell.get_post_cursor();
1124 if (cell instanceof IPython.CodeCell) {
1203 if (cell instanceof codecell.CodeCell) {
1125 // In this case the operations keep the notebook in its existing mode
1204 // In this case the operations keep the notebook in its existing mode
1126 // so we don't need to do any post-op mode changes.
1205 // so we don't need to do any post-op mode changes.
1127 cell.set_text(textb);
1206 cell.set_text(textb);
@@ -1144,8 +1223,8 b' var IPython = (function (IPython) {'
1144 * @method merge_cell_above
1223 * @method merge_cell_above
1145 */
1224 */
1146 Notebook.prototype.merge_cell_above = function () {
1225 Notebook.prototype.merge_cell_above = function () {
1147 var mdc = IPython.MarkdownCell;
1226 var mdc = textcell.MarkdownCell;
1148 var rc = IPython.RawCell;
1227 var rc = textcell.RawCell;
1149 var index = this.get_selected_index();
1228 var index = this.get_selected_index();
1150 var cell = this.get_cell(index);
1229 var cell = this.get_cell(index);
1151 var render = cell.rendered;
1230 var render = cell.rendered;
@@ -1159,7 +1238,7 b' var IPython = (function (IPython) {'
1159 }
1238 }
1160 var upper_text = upper_cell.get_text();
1239 var upper_text = upper_cell.get_text();
1161 var text = cell.get_text();
1240 var text = cell.get_text();
1162 if (cell instanceof IPython.CodeCell) {
1241 if (cell instanceof codecell.CodeCell) {
1163 cell.set_text(upper_text+'\n'+text);
1242 cell.set_text(upper_text+'\n'+text);
1164 } else if ((cell instanceof mdc) || (cell instanceof rc)) {
1243 } else if ((cell instanceof mdc) || (cell instanceof rc)) {
1165 cell.unrender(); // Must unrender before we set_text.
1244 cell.unrender(); // Must unrender before we set_text.
@@ -1181,8 +1260,8 b' var IPython = (function (IPython) {'
1181 * @method merge_cell_below
1260 * @method merge_cell_below
1182 */
1261 */
1183 Notebook.prototype.merge_cell_below = function () {
1262 Notebook.prototype.merge_cell_below = function () {
1184 var mdc = IPython.MarkdownCell;
1263 var mdc = textcell.MarkdownCell;
1185 var rc = IPython.RawCell;
1264 var rc = textcell.RawCell;
1186 var index = this.get_selected_index();
1265 var index = this.get_selected_index();
1187 var cell = this.get_cell(index);
1266 var cell = this.get_cell(index);
1188 var render = cell.rendered;
1267 var render = cell.rendered;
@@ -1196,7 +1275,7 b' var IPython = (function (IPython) {'
1196 }
1275 }
1197 var lower_text = lower_cell.get_text();
1276 var lower_text = lower_cell.get_text();
1198 var text = cell.get_text();
1277 var text = cell.get_text();
1199 if (cell instanceof IPython.CodeCell) {
1278 if (cell instanceof codecell.CodeCell) {
1200 cell.set_text(text+'\n'+lower_text);
1279 cell.set_text(text+'\n'+lower_text);
1201 } else if ((cell instanceof mdc) || (cell instanceof rc)) {
1280 } else if ((cell instanceof mdc) || (cell instanceof rc)) {
1202 cell.unrender(); // Must unrender before we set_text.
1281 cell.unrender(); // Must unrender before we set_text.
@@ -1224,7 +1303,7 b' var IPython = (function (IPython) {'
1224 Notebook.prototype.collapse_output = function (index) {
1303 Notebook.prototype.collapse_output = function (index) {
1225 var i = this.index_or_selected(index);
1304 var i = this.index_or_selected(index);
1226 var cell = this.get_cell(i);
1305 var cell = this.get_cell(i);
1227 if (cell !== null && (cell instanceof IPython.CodeCell)) {
1306 if (cell !== null && (cell instanceof codecell.CodeCell)) {
1228 cell.collapse_output();
1307 cell.collapse_output();
1229 this.set_dirty(true);
1308 this.set_dirty(true);
1230 }
1309 }
@@ -1237,7 +1316,7 b' var IPython = (function (IPython) {'
1237 */
1316 */
1238 Notebook.prototype.collapse_all_output = function () {
1317 Notebook.prototype.collapse_all_output = function () {
1239 $.map(this.get_cells(), function (cell, i) {
1318 $.map(this.get_cells(), function (cell, i) {
1240 if (cell instanceof IPython.CodeCell) {
1319 if (cell instanceof codecell.CodeCell) {
1241 cell.collapse_output();
1320 cell.collapse_output();
1242 }
1321 }
1243 });
1322 });
@@ -1254,7 +1333,7 b' var IPython = (function (IPython) {'
1254 Notebook.prototype.expand_output = function (index) {
1333 Notebook.prototype.expand_output = function (index) {
1255 var i = this.index_or_selected(index);
1334 var i = this.index_or_selected(index);
1256 var cell = this.get_cell(i);
1335 var cell = this.get_cell(i);
1257 if (cell !== null && (cell instanceof IPython.CodeCell)) {
1336 if (cell !== null && (cell instanceof codecell.CodeCell)) {
1258 cell.expand_output();
1337 cell.expand_output();
1259 this.set_dirty(true);
1338 this.set_dirty(true);
1260 }
1339 }
@@ -1267,7 +1346,7 b' var IPython = (function (IPython) {'
1267 */
1346 */
1268 Notebook.prototype.expand_all_output = function () {
1347 Notebook.prototype.expand_all_output = function () {
1269 $.map(this.get_cells(), function (cell, i) {
1348 $.map(this.get_cells(), function (cell, i) {
1270 if (cell instanceof IPython.CodeCell) {
1349 if (cell instanceof codecell.CodeCell) {
1271 cell.expand_output();
1350 cell.expand_output();
1272 }
1351 }
1273 });
1352 });
@@ -1284,7 +1363,7 b' var IPython = (function (IPython) {'
1284 Notebook.prototype.clear_output = function (index) {
1363 Notebook.prototype.clear_output = function (index) {
1285 var i = this.index_or_selected(index);
1364 var i = this.index_or_selected(index);
1286 var cell = this.get_cell(i);
1365 var cell = this.get_cell(i);
1287 if (cell !== null && (cell instanceof IPython.CodeCell)) {
1366 if (cell !== null && (cell instanceof codecell.CodeCell)) {
1288 cell.clear_output();
1367 cell.clear_output();
1289 this.set_dirty(true);
1368 this.set_dirty(true);
1290 }
1369 }
@@ -1297,7 +1376,7 b' var IPython = (function (IPython) {'
1297 */
1376 */
1298 Notebook.prototype.clear_all_output = function () {
1377 Notebook.prototype.clear_all_output = function () {
1299 $.map(this.get_cells(), function (cell, i) {
1378 $.map(this.get_cells(), function (cell, i) {
1300 if (cell instanceof IPython.CodeCell) {
1379 if (cell instanceof codecell.CodeCell) {
1301 cell.clear_output();
1380 cell.clear_output();
1302 }
1381 }
1303 });
1382 });
@@ -1313,7 +1392,7 b' var IPython = (function (IPython) {'
1313 Notebook.prototype.scroll_output = function (index) {
1392 Notebook.prototype.scroll_output = function (index) {
1314 var i = this.index_or_selected(index);
1393 var i = this.index_or_selected(index);
1315 var cell = this.get_cell(i);
1394 var cell = this.get_cell(i);
1316 if (cell !== null && (cell instanceof IPython.CodeCell)) {
1395 if (cell !== null && (cell instanceof codecell.CodeCell)) {
1317 cell.scroll_output();
1396 cell.scroll_output();
1318 this.set_dirty(true);
1397 this.set_dirty(true);
1319 }
1398 }
@@ -1326,7 +1405,7 b' var IPython = (function (IPython) {'
1326 */
1405 */
1327 Notebook.prototype.scroll_all_output = function () {
1406 Notebook.prototype.scroll_all_output = function () {
1328 $.map(this.get_cells(), function (cell, i) {
1407 $.map(this.get_cells(), function (cell, i) {
1329 if (cell instanceof IPython.CodeCell) {
1408 if (cell instanceof codecell.CodeCell) {
1330 cell.scroll_output();
1409 cell.scroll_output();
1331 }
1410 }
1332 });
1411 });
@@ -1342,7 +1421,7 b' var IPython = (function (IPython) {'
1342 Notebook.prototype.toggle_output = function (index) {
1421 Notebook.prototype.toggle_output = function (index) {
1343 var i = this.index_or_selected(index);
1422 var i = this.index_or_selected(index);
1344 var cell = this.get_cell(i);
1423 var cell = this.get_cell(i);
1345 if (cell !== null && (cell instanceof IPython.CodeCell)) {
1424 if (cell !== null && (cell instanceof codecell.CodeCell)) {
1346 cell.toggle_output();
1425 cell.toggle_output();
1347 this.set_dirty(true);
1426 this.set_dirty(true);
1348 }
1427 }
@@ -1355,7 +1434,7 b' var IPython = (function (IPython) {'
1355 */
1434 */
1356 Notebook.prototype.toggle_all_output = function () {
1435 Notebook.prototype.toggle_all_output = function () {
1357 $.map(this.get_cells(), function (cell, i) {
1436 $.map(this.get_cells(), function (cell, i) {
1358 if (cell instanceof IPython.CodeCell) {
1437 if (cell instanceof codecell.CodeCell) {
1359 cell.toggle_output();
1438 cell.toggle_output();
1360 }
1439 }
1361 });
1440 });
@@ -1372,7 +1451,7 b' var IPython = (function (IPython) {'
1372 Notebook.prototype.toggle_output_scroll = function (index) {
1451 Notebook.prototype.toggle_output_scroll = function (index) {
1373 var i = this.index_or_selected(index);
1452 var i = this.index_or_selected(index);
1374 var cell = this.get_cell(i);
1453 var cell = this.get_cell(i);
1375 if (cell !== null && (cell instanceof IPython.CodeCell)) {
1454 if (cell !== null && (cell instanceof codecell.CodeCell)) {
1376 cell.toggle_output_scroll();
1455 cell.toggle_output_scroll();
1377 this.set_dirty(true);
1456 this.set_dirty(true);
1378 }
1457 }
@@ -1385,7 +1464,7 b' var IPython = (function (IPython) {'
1385 */
1464 */
1386 Notebook.prototype.toggle_all_output_scroll = function () {
1465 Notebook.prototype.toggle_all_output_scroll = function () {
1387 $.map(this.get_cells(), function (cell, i) {
1466 $.map(this.get_cells(), function (cell, i) {
1388 if (cell instanceof IPython.CodeCell) {
1467 if (cell instanceof codecell.CodeCell) {
1389 cell.toggle_output_scroll();
1468 cell.toggle_output_scroll();
1390 }
1469 }
1391 });
1470 });
@@ -1412,7 +1491,11 b' var IPython = (function (IPython) {'
1412 * @method start_session
1491 * @method start_session
1413 */
1492 */
1414 Notebook.prototype.start_session = function () {
1493 Notebook.prototype.start_session = function () {
1415 this.session = new IPython.Session(this, this.options);
1494 this.session = new session.Session({
1495 base_url: this.base_url,
1496 notebook_path: this.notebook_path,
1497 notebook_name: this.notebook_name,
1498 notebook: this});
1416 this.session.start($.proxy(this._session_started, this));
1499 this.session.start($.proxy(this._session_started, this));
1417 };
1500 };
1418
1501
@@ -1427,7 +1510,7 b' var IPython = (function (IPython) {'
1427 var ncells = this.ncells();
1510 var ncells = this.ncells();
1428 for (var i=0; i<ncells; i++) {
1511 for (var i=0; i<ncells; i++) {
1429 var cell = this.get_cell(i);
1512 var cell = this.get_cell(i);
1430 if (cell instanceof IPython.CodeCell) {
1513 if (cell instanceof codecell.CodeCell) {
1431 cell.set_kernel(this.session.kernel);
1514 cell.set_kernel(this.session.kernel);
1432 }
1515 }
1433 }
1516 }
@@ -1440,7 +1523,9 b' var IPython = (function (IPython) {'
1440 */
1523 */
1441 Notebook.prototype.restart_kernel = function () {
1524 Notebook.prototype.restart_kernel = function () {
1442 var that = this;
1525 var that = this;
1443 IPython.dialog.modal({
1526 dialog.modal({
1527 notebook: this,
1528 keyboard_manager: this.keyboard_manager,
1444 title : "Restart kernel or continue running?",
1529 title : "Restart kernel or continue running?",
1445 body : $("<p/>").text(
1530 body : $("<p/>").text(
1446 'Do you want to restart the current kernel? You will lose all variables defined in it.'
1531 'Do you want to restart the current kernel? You will lose all variables defined in it.'
@@ -1660,10 +1745,12 b' var IPython = (function (IPython) {'
1660 }
1745 }
1661 if (trusted != this.trusted) {
1746 if (trusted != this.trusted) {
1662 this.trusted = trusted;
1747 this.trusted = trusted;
1663 $([IPython.events]).trigger("trust_changed.Notebook", trusted);
1748 this.events.trigger("trust_changed.Notebook", trusted);
1664 }
1749 }
1665 if (content.worksheets.length > 1) {
1750 if (content.worksheets.length > 1) {
1666 IPython.dialog.modal({
1751 dialog.modal({
1752 notebook: this,
1753 keyboard_manager: this.keyboard_manager,
1667 title : "Multiple worksheets",
1754 title : "Multiple worksheets",
1668 body : "This notebook has " + data.worksheets.length + " worksheets, " +
1755 body : "This notebook has " + data.worksheets.length + " worksheets, " +
1669 "but this version of IPython can only handle the first. " +
1756 "but this version of IPython can only handle the first. " +
@@ -1705,7 +1792,7 b' var IPython = (function (IPython) {'
1705 };
1792 };
1706 if (trusted != this.trusted) {
1793 if (trusted != this.trusted) {
1707 this.trusted = trusted;
1794 this.trusted = trusted;
1708 $([IPython.events]).trigger("trust_changed.Notebook", trusted);
1795 this.events.trigger("trust_changed.Notebook", trusted);
1709 }
1796 }
1710 return data;
1797 return data;
1711 };
1798 };
@@ -1730,10 +1817,10 b' var IPython = (function (IPython) {'
1730 that.save_notebook();
1817 that.save_notebook();
1731 }
1818 }
1732 }, interval);
1819 }, interval);
1733 $([IPython.events]).trigger("autosave_enabled.Notebook", interval);
1820 this.events.trigger("autosave_enabled.Notebook", interval);
1734 } else {
1821 } else {
1735 this.autosave_timer = null;
1822 this.autosave_timer = null;
1736 $([IPython.events]).trigger("autosave_disabled.Notebook");
1823 this.events.trigger("autosave_disabled.Notebook");
1737 }
1824 }
1738 };
1825 };
1739
1826
@@ -1768,7 +1855,7 b' var IPython = (function (IPython) {'
1768 settings[key] = extra_settings[key];
1855 settings[key] = extra_settings[key];
1769 }
1856 }
1770 }
1857 }
1771 $([IPython.events]).trigger('notebook_saving.Notebook');
1858 this.events.trigger('notebook_saving.Notebook');
1772 var url = utils.url_join_encode(
1859 var url = utils.url_join_encode(
1773 this.base_url,
1860 this.base_url,
1774 'api/notebooks',
1861 'api/notebooks',
@@ -1789,7 +1876,7 b' var IPython = (function (IPython) {'
1789 */
1876 */
1790 Notebook.prototype.save_notebook_success = function (start, data, status, xhr) {
1877 Notebook.prototype.save_notebook_success = function (start, data, status, xhr) {
1791 this.set_dirty(false);
1878 this.set_dirty(false);
1792 $([IPython.events]).trigger('notebook_saved.Notebook');
1879 this.events.trigger('notebook_saved.Notebook');
1793 this._update_autosave_interval(start);
1880 this._update_autosave_interval(start);
1794 if (this._checkpoint_after_save) {
1881 if (this._checkpoint_after_save) {
1795 this.create_checkpoint();
1882 this.create_checkpoint();
@@ -1826,7 +1913,7 b' var IPython = (function (IPython) {'
1826 * @param {String} error HTTP error message
1913 * @param {String} error HTTP error message
1827 */
1914 */
1828 Notebook.prototype.save_notebook_error = function (xhr, status, error) {
1915 Notebook.prototype.save_notebook_error = function (xhr, status, error) {
1829 $([IPython.events]).trigger('notebook_save_failed.Notebook', [xhr, status, error]);
1916 this.events.trigger('notebook_save_failed.Notebook', [xhr, status, error]);
1830 };
1917 };
1831
1918
1832 /**
1919 /**
@@ -1851,7 +1938,9 b' var IPython = (function (IPython) {'
1851 );
1938 );
1852
1939
1853 var nb = this;
1940 var nb = this;
1854 IPython.dialog.modal({
1941 dialog.modal({
1942 notebook: this,
1943 keyboard_manager: this.keyboard_manager,
1855 title: "Trust this notebook?",
1944 title: "Trust this notebook?",
1856 body: body,
1945 body: body,
1857
1946
@@ -1867,7 +1956,7 b' var IPython = (function (IPython) {'
1867 cell.output_area.trusted = true;
1956 cell.output_area.trusted = true;
1868 }
1957 }
1869 }
1958 }
1870 $([IPython.events]).on('notebook_saved.Notebook', function () {
1959 this.events.on('notebook_saved.Notebook', function () {
1871 window.location.reload();
1960 window.location.reload();
1872 });
1961 });
1873 nb.save_notebook();
1962 nb.save_notebook();
@@ -1953,7 +2042,7 b' var IPython = (function (IPython) {'
1953 success : $.proxy(that.rename_success, this),
2042 success : $.proxy(that.rename_success, this),
1954 error : $.proxy(that.rename_error, this)
2043 error : $.proxy(that.rename_error, this)
1955 };
2044 };
1956 $([IPython.events]).trigger('rename_notebook.Notebook', data);
2045 this.events.trigger('rename_notebook.Notebook', data);
1957 var url = utils.url_join_encode(
2046 var url = utils.url_join_encode(
1958 this.base_url,
2047 this.base_url,
1959 'api/notebooks',
2048 'api/notebooks',
@@ -1986,32 +2075,34 b' var IPython = (function (IPython) {'
1986 var name = this.notebook_name = json.name;
2075 var name = this.notebook_name = json.name;
1987 var path = json.path;
2076 var path = json.path;
1988 this.session.rename_notebook(name, path);
2077 this.session.rename_notebook(name, path);
1989 $([IPython.events]).trigger('notebook_renamed.Notebook', json);
2078 this.events.trigger('notebook_renamed.Notebook', json);
1990 };
2079 };
1991
2080
1992 Notebook.prototype.rename_error = function (xhr, status, error) {
2081 Notebook.prototype.rename_error = function (xhr, status, error) {
1993 var that = this;
2082 var that = this;
1994 var dialog = $('<div/>').append(
2083 var dialog_body = $('<div/>').append(
1995 $("<p/>").addClass("rename-message")
2084 $("<p/>").addClass("rename-message")
1996 .text('This notebook name already exists.')
2085 .text('This notebook name already exists.')
1997 );
2086 );
1998 $([IPython.events]).trigger('notebook_rename_failed.Notebook', [xhr, status, error]);
2087 this.events.trigger('notebook_rename_failed.Notebook', [xhr, status, error]);
1999 IPython.dialog.modal({
2088 dialog.modal({
2089 notebook: this,
2090 keyboard_manager: this.keyboard_manager,
2000 title: "Notebook Rename Error!",
2091 title: "Notebook Rename Error!",
2001 body: dialog,
2092 body: dialog_body,
2002 buttons : {
2093 buttons : {
2003 "Cancel": {},
2094 "Cancel": {},
2004 "OK": {
2095 "OK": {
2005 class: "btn-primary",
2096 class: "btn-primary",
2006 click: function () {
2097 click: function () {
2007 IPython.save_widget.rename_notebook();
2098 this.save_widget.rename_notebook({notebook:that});
2008 }}
2099 }}
2009 },
2100 },
2010 open : function (event, ui) {
2101 open : function (event, ui) {
2011 var that = $(this);
2102 var that = $(this);
2012 // Upon ENTER, click the OK button.
2103 // Upon ENTER, click the OK button.
2013 that.find('input[type="text"]').keydown(function (event, ui) {
2104 that.find('input[type="text"]').keydown(function (event, ui) {
2014 if (event.which === IPython.keyboard.keycodes.enter) {
2105 if (event.which === this.keyboard.keycodes.enter) {
2015 that.find('.btn-primary').first().click();
2106 that.find('.btn-primary').first().click();
2016 }
2107 }
2017 });
2108 });
@@ -2039,7 +2130,7 b' var IPython = (function (IPython) {'
2039 success : $.proxy(this.load_notebook_success,this),
2130 success : $.proxy(this.load_notebook_success,this),
2040 error : $.proxy(this.load_notebook_error,this),
2131 error : $.proxy(this.load_notebook_error,this),
2041 };
2132 };
2042 $([IPython.events]).trigger('notebook_loading.Notebook');
2133 this.events.trigger('notebook_loading.Notebook');
2043 var url = utils.url_join_encode(
2134 var url = utils.url_join_encode(
2044 this.base_url,
2135 this.base_url,
2045 'api/notebooks',
2136 'api/notebooks',
@@ -2077,7 +2168,9 b' var IPython = (function (IPython) {'
2077 "newer notebook format will be used and older versions of IPython " +
2168 "newer notebook format will be used and older versions of IPython " +
2078 "may not be able to read it. To keep the older version, close the " +
2169 "may not be able to read it. To keep the older version, close the " +
2079 "notebook without saving it.";
2170 "notebook without saving it.";
2080 IPython.dialog.modal({
2171 dialog.modal({
2172 notebook: this,
2173 keyboard_manager: this.keyboard_manager,
2081 title : "Notebook converted",
2174 title : "Notebook converted",
2082 body : msg,
2175 body : msg,
2083 buttons : {
2176 buttons : {
@@ -2094,7 +2187,9 b' var IPython = (function (IPython) {'
2094 this_vs + ". You can still work with this notebook, but some features " +
2187 this_vs + ". You can still work with this notebook, but some features " +
2095 "introduced in later notebook versions may not be available.";
2188 "introduced in later notebook versions may not be available.";
2096
2189
2097 IPython.dialog.modal({
2190 dialog.modal({
2191 notebook: this,
2192 keyboard_manager: this.keyboard_manager,
2098 title : "Newer Notebook",
2193 title : "Newer Notebook",
2099 body : msg,
2194 body : msg,
2100 buttons : {
2195 buttons : {
@@ -2116,15 +2211,15 b' var IPython = (function (IPython) {'
2116
2211
2117 // load toolbar state
2212 // load toolbar state
2118 if (this.metadata.celltoolbar) {
2213 if (this.metadata.celltoolbar) {
2119 IPython.CellToolbar.global_show();
2214 celltoolbar.CellToolbar.global_show();
2120 IPython.CellToolbar.activate_preset(this.metadata.celltoolbar);
2215 celltoolbar.CellToolbar.activate_preset(this.metadata.celltoolbar, this.events);
2121 } else {
2216 } else {
2122 IPython.CellToolbar.global_hide();
2217 celltoolbar.CellToolbar.global_hide();
2123 }
2218 }
2124
2219
2125 // now that we're fully loaded, it is safe to restore save functionality
2220 // now that we're fully loaded, it is safe to restore save functionality
2126 delete(this.save_notebook);
2221 delete(this.save_notebook);
2127 $([IPython.events]).trigger('notebook_loaded.Notebook');
2222 this.events.trigger('notebook_loaded.Notebook');
2128 };
2223 };
2129
2224
2130 /**
2225 /**
@@ -2136,7 +2231,7 b' var IPython = (function (IPython) {'
2136 * @param {String} error HTTP error message
2231 * @param {String} error HTTP error message
2137 */
2232 */
2138 Notebook.prototype.load_notebook_error = function (xhr, status, error) {
2233 Notebook.prototype.load_notebook_error = function (xhr, status, error) {
2139 $([IPython.events]).trigger('notebook_load_failed.Notebook', [xhr, status, error]);
2234 this.events.trigger('notebook_load_failed.Notebook', [xhr, status, error]);
2140 var msg;
2235 var msg;
2141 if (xhr.status === 400) {
2236 if (xhr.status === 400) {
2142 msg = error;
2237 msg = error;
@@ -2145,7 +2240,9 b' var IPython = (function (IPython) {'
2145 "This version can load notebook formats " +
2240 "This version can load notebook formats " +
2146 "v" + this.nbformat + " or earlier.";
2241 "v" + this.nbformat + " or earlier.";
2147 }
2242 }
2148 IPython.dialog.modal({
2243 dialog.modal({
2244 notebook: this,
2245 keyboard_manager: this.keyboard_manager,
2149 title: "Error loading notebook",
2246 title: "Error loading notebook",
2150 body : msg,
2247 body : msg,
2151 buttons : {
2248 buttons : {
@@ -2224,7 +2321,7 b' var IPython = (function (IPython) {'
2224 } else {
2321 } else {
2225 this.last_checkpoint = null;
2322 this.last_checkpoint = null;
2226 }
2323 }
2227 $([IPython.events]).trigger('checkpoints_listed.Notebook', [data]);
2324 this.events.trigger('checkpoints_listed.Notebook', [data]);
2228 };
2325 };
2229
2326
2230 /**
2327 /**
@@ -2236,7 +2333,7 b' var IPython = (function (IPython) {'
2236 * @param {String} error_msg HTTP error message
2333 * @param {String} error_msg HTTP error message
2237 */
2334 */
2238 Notebook.prototype.list_checkpoints_error = function (xhr, status, error_msg) {
2335 Notebook.prototype.list_checkpoints_error = function (xhr, status, error_msg) {
2239 $([IPython.events]).trigger('list_checkpoints_failed.Notebook');
2336 this.events.trigger('list_checkpoints_failed.Notebook');
2240 };
2337 };
2241
2338
2242 /**
2339 /**
@@ -2270,7 +2367,7 b' var IPython = (function (IPython) {'
2270 Notebook.prototype.create_checkpoint_success = function (data, status, xhr) {
2367 Notebook.prototype.create_checkpoint_success = function (data, status, xhr) {
2271 data = $.parseJSON(data);
2368 data = $.parseJSON(data);
2272 this.add_checkpoint(data);
2369 this.add_checkpoint(data);
2273 $([IPython.events]).trigger('checkpoint_created.Notebook', data);
2370 this.events.trigger('checkpoint_created.Notebook', data);
2274 };
2371 };
2275
2372
2276 /**
2373 /**
@@ -2282,7 +2379,7 b' var IPython = (function (IPython) {'
2282 * @param {String} error_msg HTTP error message
2379 * @param {String} error_msg HTTP error message
2283 */
2380 */
2284 Notebook.prototype.create_checkpoint_error = function (xhr, status, error_msg) {
2381 Notebook.prototype.create_checkpoint_error = function (xhr, status, error_msg) {
2285 $([IPython.events]).trigger('checkpoint_failed.Notebook');
2382 this.events.trigger('checkpoint_failed.Notebook');
2286 };
2383 };
2287
2384
2288 Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) {
2385 Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) {
@@ -2309,7 +2406,9 b' var IPython = (function (IPython) {'
2309 ).css("text-align", "center")
2406 ).css("text-align", "center")
2310 );
2407 );
2311
2408
2312 IPython.dialog.modal({
2409 dialog.modal({
2410 notebook: this,
2411 keyboard_manager: this.keyboard_manager,
2313 title : "Revert notebook to checkpoint",
2412 title : "Revert notebook to checkpoint",
2314 body : body,
2413 body : body,
2315 buttons : {
2414 buttons : {
@@ -2331,7 +2430,7 b' var IPython = (function (IPython) {'
2331 * @param {String} checkpoint ID
2430 * @param {String} checkpoint ID
2332 */
2431 */
2333 Notebook.prototype.restore_checkpoint = function (checkpoint) {
2432 Notebook.prototype.restore_checkpoint = function (checkpoint) {
2334 $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
2433 this.events.trigger('notebook_restoring.Notebook', checkpoint);
2335 var url = utils.url_join_encode(
2434 var url = utils.url_join_encode(
2336 this.base_url,
2435 this.base_url,
2337 'api/notebooks',
2436 'api/notebooks',
@@ -2356,7 +2455,7 b' var IPython = (function (IPython) {'
2356 * @param {jqXHR} xhr jQuery Ajax object
2455 * @param {jqXHR} xhr jQuery Ajax object
2357 */
2456 */
2358 Notebook.prototype.restore_checkpoint_success = function (data, status, xhr) {
2457 Notebook.prototype.restore_checkpoint_success = function (data, status, xhr) {
2359 $([IPython.events]).trigger('checkpoint_restored.Notebook');
2458 this.events.trigger('checkpoint_restored.Notebook');
2360 this.load_notebook(this.notebook_name, this.notebook_path);
2459 this.load_notebook(this.notebook_name, this.notebook_path);
2361 };
2460 };
2362
2461
@@ -2369,7 +2468,7 b' var IPython = (function (IPython) {'
2369 * @param {String} error_msg HTTP error message
2468 * @param {String} error_msg HTTP error message
2370 */
2469 */
2371 Notebook.prototype.restore_checkpoint_error = function (xhr, status, error_msg) {
2470 Notebook.prototype.restore_checkpoint_error = function (xhr, status, error_msg) {
2372 $([IPython.events]).trigger('checkpoint_restore_failed.Notebook');
2471 this.events.trigger('checkpoint_restore_failed.Notebook');
2373 };
2472 };
2374
2473
2375 /**
2474 /**
@@ -2379,7 +2478,7 b' var IPython = (function (IPython) {'
2379 * @param {String} checkpoint ID
2478 * @param {String} checkpoint ID
2380 */
2479 */
2381 Notebook.prototype.delete_checkpoint = function (checkpoint) {
2480 Notebook.prototype.delete_checkpoint = function (checkpoint) {
2382 $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
2481 this.events.trigger('notebook_restoring.Notebook', checkpoint);
2383 var url = utils.url_join_encode(
2482 var url = utils.url_join_encode(
2384 this.base_url,
2483 this.base_url,
2385 'api/notebooks',
2484 'api/notebooks',
@@ -2404,7 +2503,7 b' var IPython = (function (IPython) {'
2404 * @param {jqXHR} xhr jQuery Ajax object
2503 * @param {jqXHR} xhr jQuery Ajax object
2405 */
2504 */
2406 Notebook.prototype.delete_checkpoint_success = function (data, status, xhr) {
2505 Notebook.prototype.delete_checkpoint_success = function (data, status, xhr) {
2407 $([IPython.events]).trigger('checkpoint_deleted.Notebook', data);
2506 this.events.trigger('checkpoint_deleted.Notebook', data);
2408 this.load_notebook(this.notebook_name, this.notebook_path);
2507 this.load_notebook(this.notebook_name, this.notebook_path);
2409 };
2508 };
2410
2509
@@ -2417,14 +2516,12 b' var IPython = (function (IPython) {'
2417 * @param {String} error_msg HTTP error message
2516 * @param {String} error_msg HTTP error message
2418 */
2517 */
2419 Notebook.prototype.delete_checkpoint_error = function (xhr, status, error_msg) {
2518 Notebook.prototype.delete_checkpoint_error = function (xhr, status, error_msg) {
2420 $([IPython.events]).trigger('checkpoint_delete_failed.Notebook');
2519 this.events.trigger('checkpoint_delete_failed.Notebook');
2421 };
2520 };
2422
2521
2423
2522
2523 // For backwards compatability.
2424 IPython.Notebook = Notebook;
2524 IPython.Notebook = Notebook;
2425
2525
2426
2526 return {'Notebook': Notebook};
2427 return IPython;
2527 });
2428
2429 }(IPython));
2430
@@ -1,21 +1,30 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'base/js/utils',
8 //============================================================================
8 'base/js/dialog',
9 // Notification widget
9 'notebook/js/notificationwidget',
10 //============================================================================
10 ], function(IPython, $, utils, dialog, notificationwidget) {
11
12 var IPython = (function (IPython) {
13 "use strict";
11 "use strict";
14 var utils = IPython.utils;
15
12
16
13 var NotificationArea = function (selector, options) {
17 var NotificationArea = function (selector) {
14 // Constructor
15 //
16 // Parameters:
17 // selector: string
18 // options: dictionary
19 // Dictionary of keyword arguments.
20 // notebook: Notebook instance
21 // events: $(Events) instance
22 // save_widget: SaveWidget instance
18 this.selector = selector;
23 this.selector = selector;
24 this.events = options.events;
25 this.save_widget = options.save_widget;
26 this.notebook = options.notebook;
27 this.keyboard_manager = options.keyboard_manager;
19 if (this.selector !== undefined) {
28 if (this.selector !== undefined) {
20 this.element = $(selector);
29 this.element = $(selector);
21 }
30 }
@@ -63,23 +72,24 b' var IPython = (function (IPython) {'
63 }
72 }
64 var div = $('<div/>').attr('id','notification_'+name);
73 var div = $('<div/>').attr('id','notification_'+name);
65 $(this.selector).append(div);
74 $(this.selector).append(div);
66 this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name);
75 this.widget_dict[name] = new notificationwidget.NotificationWidget('#notification_'+name);
67 return this.widget_dict[name];
76 return this.widget_dict[name];
68 };
77 };
69
78
70 NotificationArea.prototype.init_notification_widgets = function() {
79 NotificationArea.prototype.init_notification_widgets = function() {
80 var that = this;
71 var knw = this.new_notification_widget('kernel');
81 var knw = this.new_notification_widget('kernel');
72 var $kernel_ind_icon = $("#kernel_indicator_icon");
82 var $kernel_ind_icon = $("#kernel_indicator_icon");
73 var $modal_ind_icon = $("#modal_indicator_icon");
83 var $modal_ind_icon = $("#modal_indicator_icon");
74
84
75 // Command/Edit mode
85 // Command/Edit mode
76 $([IPython.events]).on('edit_mode.Notebook',function () {
86 this.events.on('edit_mode.Notebook',function () {
77 IPython.save_widget.update_document_title();
87 that.save_widget.update_document_title();
78 $modal_ind_icon.attr('class','edit_mode_icon').attr('title','Edit Mode');
88 $modal_ind_icon.attr('class','edit_mode_icon').attr('title','Edit Mode');
79 });
89 });
80
90
81 $([IPython.events]).on('command_mode.Notebook',function () {
91 this.events.on('command_mode.Notebook',function () {
82 IPython.save_widget.update_document_title();
92 that.save_widget.update_document_title();
83 $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
93 $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
84 });
94 });
85
95
@@ -87,22 +97,22 b' var IPython = (function (IPython) {'
87 $modal_ind_icon.attr('class','command-mode_icon').attr('title','Command Mode');
97 $modal_ind_icon.attr('class','command-mode_icon').attr('title','Command Mode');
88
98
89 // Kernel events
99 // Kernel events
90 $([IPython.events]).on('status_idle.Kernel',function () {
100 this.events.on('status_idle.Kernel',function () {
91 IPython.save_widget.update_document_title();
101 that.save_widget.update_document_title();
92 $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
102 $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
93 });
103 });
94
104
95 $([IPython.events]).on('status_busy.Kernel',function () {
105 this.events.on('status_busy.Kernel',function () {
96 window.document.title='(Busy) '+window.document.title;
106 window.document.title='(Busy) '+window.document.title;
97 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
107 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
98 });
108 });
99
109
100 $([IPython.events]).on('status_restarting.Kernel',function () {
110 this.events.on('status_restarting.Kernel',function () {
101 IPython.save_widget.update_document_title();
111 that.save_widget.update_document_title();
102 knw.set_message("Restarting kernel", 2000);
112 knw.set_message("Restarting kernel", 2000);
103 });
113 });
104
114
105 $([IPython.events]).on('status_interrupting.Kernel',function () {
115 this.events.on('status_interrupting.Kernel',function () {
106 knw.set_message("Interrupting kernel", 2000);
116 knw.set_message("Interrupting kernel", 2000);
107 });
117 });
108
118
@@ -110,28 +120,30 b' var IPython = (function (IPython) {'
110 // When the kernel_info reply arrives, the kernel is idle.
120 // When the kernel_info reply arrives, the kernel is idle.
111 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
121 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
112
122
113 $([IPython.events]).on('status_started.Kernel', function (evt, data) {
123 this.events.on('status_started.Kernel', function (evt, data) {
114 data.kernel.kernel_info(function () {
124 data.kernel.kernel_info(function () {
115 $([IPython.events]).trigger('status_idle.Kernel');
125 that.events.trigger('status_idle.Kernel');
116 });
126 });
117 });
127 });
118
128
119 $([IPython.events]).on('status_dead.Kernel',function () {
129 this.events.on('status_dead.Kernel',function () {
120 var msg = 'The kernel has died, and the automatic restart has failed.' +
130 var msg = 'The kernel has died, and the automatic restart has failed.' +
121 ' It is possible the kernel cannot be restarted.' +
131 ' It is possible the kernel cannot be restarted.' +
122 ' If you are not able to restart the kernel, you will still be able to save' +
132 ' If you are not able to restart the kernel, you will still be able to save' +
123 ' the notebook, but running code will no longer work until the notebook' +
133 ' the notebook, but running code will no longer work until the notebook' +
124 ' is reopened.';
134 ' is reopened.';
125
135
126 IPython.dialog.modal({
136 dialog.modal({
127 title: "Dead kernel",
137 title: "Dead kernel",
128 body : msg,
138 body : msg,
139 keyboard_manager: that.keyboard_manager,
140 notebook: that.notebook,
129 buttons : {
141 buttons : {
130 "Manual Restart": {
142 "Manual Restart": {
131 class: "btn-danger",
143 class: "btn-danger",
132 click: function () {
144 click: function () {
133 $([IPython.events]).trigger('status_restarting.Kernel');
145 that.events.trigger('status_restarting.Kernel');
134 IPython.notebook.start_kernel();
146 that.notebook.start_kernel();
135 }
147 }
136 },
148 },
137 "Don't restart": {}
149 "Don't restart": {}
@@ -139,7 +151,7 b' var IPython = (function (IPython) {'
139 });
151 });
140 });
152 });
141
153
142 $([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
154 this.events.on('websocket_closed.Kernel', function (event, data) {
143 var kernel = data.kernel;
155 var kernel = data.kernel;
144 var ws_url = data.ws_url;
156 var ws_url = data.ws_url;
145 var early = data.early;
157 var early = data.early;
@@ -155,9 +167,11 b' var IPython = (function (IPython) {'
155 msg = "A WebSocket connection could not be established." +
167 msg = "A WebSocket connection could not be established." +
156 " You will NOT be able to run code. Check your" +
168 " You will NOT be able to run code. Check your" +
157 " network connection or notebook server configuration.";
169 " network connection or notebook server configuration.";
158 IPython.dialog.modal({
170 dialog.modal({
159 title: "WebSocket connection failed",
171 title: "WebSocket connection failed",
160 body: msg,
172 body: msg,
173 keyboard_manager: that.keyboard_manager,
174 notebook: that.notebook,
161 buttons : {
175 buttons : {
162 "OK": {},
176 "OK": {},
163 "Reconnect": {
177 "Reconnect": {
@@ -176,24 +190,24 b' var IPython = (function (IPython) {'
176 var nnw = this.new_notification_widget('notebook');
190 var nnw = this.new_notification_widget('notebook');
177
191
178 // Notebook events
192 // Notebook events
179 $([IPython.events]).on('notebook_loading.Notebook', function () {
193 this.events.on('notebook_loading.Notebook', function () {
180 nnw.set_message("Loading notebook",500);
194 nnw.set_message("Loading notebook",500);
181 });
195 });
182 $([IPython.events]).on('notebook_loaded.Notebook', function () {
196 this.events.on('notebook_loaded.Notebook', function () {
183 nnw.set_message("Notebook loaded",500);
197 nnw.set_message("Notebook loaded",500);
184 });
198 });
185 $([IPython.events]).on('notebook_saving.Notebook', function () {
199 this.events.on('notebook_saving.Notebook', function () {
186 nnw.set_message("Saving notebook",500);
200 nnw.set_message("Saving notebook",500);
187 });
201 });
188 $([IPython.events]).on('notebook_saved.Notebook', function () {
202 this.events.on('notebook_saved.Notebook', function () {
189 nnw.set_message("Notebook saved",2000);
203 nnw.set_message("Notebook saved",2000);
190 });
204 });
191 $([IPython.events]).on('notebook_save_failed.Notebook', function (evt, xhr, status, data) {
205 this.events.on('notebook_save_failed.Notebook', function (evt, xhr, status, data) {
192 nnw.set_message(data || "Notebook save failed");
206 nnw.set_message(data || "Notebook save failed");
193 });
207 });
194
208
195 // Checkpoint events
209 // Checkpoint events
196 $([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
210 this.events.on('checkpoint_created.Notebook', function (evt, data) {
197 var msg = "Checkpoint created";
211 var msg = "Checkpoint created";
198 if (data.last_modified) {
212 if (data.last_modified) {
199 var d = new Date(data.last_modified);
213 var d = new Date(data.last_modified);
@@ -201,27 +215,27 b' var IPython = (function (IPython) {'
201 }
215 }
202 nnw.set_message(msg, 2000);
216 nnw.set_message(msg, 2000);
203 });
217 });
204 $([IPython.events]).on('checkpoint_failed.Notebook', function () {
218 this.events.on('checkpoint_failed.Notebook', function () {
205 nnw.set_message("Checkpoint failed");
219 nnw.set_message("Checkpoint failed");
206 });
220 });
207 $([IPython.events]).on('checkpoint_deleted.Notebook', function () {
221 this.events.on('checkpoint_deleted.Notebook', function () {
208 nnw.set_message("Checkpoint deleted", 500);
222 nnw.set_message("Checkpoint deleted", 500);
209 });
223 });
210 $([IPython.events]).on('checkpoint_delete_failed.Notebook', function () {
224 this.events.on('checkpoint_delete_failed.Notebook', function () {
211 nnw.set_message("Checkpoint delete failed");
225 nnw.set_message("Checkpoint delete failed");
212 });
226 });
213 $([IPython.events]).on('checkpoint_restoring.Notebook', function () {
227 this.events.on('checkpoint_restoring.Notebook', function () {
214 nnw.set_message("Restoring to checkpoint...", 500);
228 nnw.set_message("Restoring to checkpoint...", 500);
215 });
229 });
216 $([IPython.events]).on('checkpoint_restore_failed.Notebook', function () {
230 this.events.on('checkpoint_restore_failed.Notebook', function () {
217 nnw.set_message("Checkpoint restore failed");
231 nnw.set_message("Checkpoint restore failed");
218 });
232 });
219
233
220 // Autosave events
234 // Autosave events
221 $([IPython.events]).on('autosave_disabled.Notebook', function () {
235 this.events.on('autosave_disabled.Notebook', function () {
222 nnw.set_message("Autosave disabled", 2000);
236 nnw.set_message("Autosave disabled", 2000);
223 });
237 });
224 $([IPython.events]).on('autosave_enabled.Notebook', function (evt, interval) {
238 this.events.on('autosave_enabled.Notebook', function (evt, interval) {
225 nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
239 nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
226 });
240 });
227
241
@@ -229,7 +243,5 b' var IPython = (function (IPython) {'
229
243
230 IPython.NotificationArea = NotificationArea;
244 IPython.NotificationArea = NotificationArea;
231
245
232 return IPython;
246 return {'NotificationArea': NotificationArea};
233
247 });
234 }(IPython));
235
@@ -1,18 +1,11 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Notification widget
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11
7 ], function(IPython, $) {
12 var IPython = (function (IPython) {
13 "use strict";
8 "use strict";
14 var utils = IPython.utils;
15
16
9
17 var NotificationWidget = function (selector) {
10 var NotificationWidget = function (selector) {
18 this.selector = selector;
11 this.selector = selector;
@@ -31,7 +24,6 b' var IPython = (function (IPython) {'
31
24
32 };
25 };
33
26
34
35 NotificationWidget.prototype.style = function () {
27 NotificationWidget.prototype.style = function () {
36 this.element.addClass('notification_widget pull-right');
28 this.element.addClass('notification_widget pull-right');
37 this.element.addClass('border-box-sizing');
29 this.element.addClass('border-box-sizing');
@@ -43,12 +35,12 b' var IPython = (function (IPython) {'
43 // if timeout <= 0
35 // if timeout <= 0
44 // click_callback : function called if user click on notification
36 // click_callback : function called if user click on notification
45 // could return false to prevent the notification to be dismissed
37 // could return false to prevent the notification to be dismissed
46 NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, opts) {
38 NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) {
47 var opts = opts || {};
39 options = options || {};
48 var callback = click_callback || function() {return false;};
40 var callback = click_callback || function() {return false;};
49 var that = this;
41 var that = this;
50 this.inner.attr('class', opts.icon);
42 this.inner.attr('class', options.icon);
51 this.inner.attr('title', opts.title);
43 this.inner.attr('title', options.title);
52 this.inner.text(msg);
44 this.inner.text(msg);
53 this.element.fadeIn(100);
45 this.element.fadeIn(100);
54 if (this.timeout !== null) {
46 if (this.timeout !== null) {
@@ -62,7 +54,7 b' var IPython = (function (IPython) {'
62 }, timeout);
54 }, timeout);
63 } else {
55 } else {
64 this.element.click(function() {
56 this.element.click(function() {
65 if( callback() != false ) {
57 if( callback() !== false ) {
66 that.element.fadeOut(100, function () {that.inner.text('');});
58 that.element.fadeOut(100, function () {that.inner.text('');});
67 that.element.unbind('click');
59 that.element.unbind('click');
68 }
60 }
@@ -74,15 +66,12 b' var IPython = (function (IPython) {'
74 }
66 }
75 };
67 };
76
68
77
78 NotificationWidget.prototype.get_message = function () {
69 NotificationWidget.prototype.get_message = function () {
79 return this.inner.html();
70 return this.inner.html();
80 };
71 };
81
72
82
73 // For backwards compatability.
83 IPython.NotificationWidget = NotificationWidget;
74 IPython.NotificationWidget = NotificationWidget;
84
75
85 return IPython;
76 return {'NotificationWidget': NotificationWidget};
86
77 });
87 }(IPython));
88
@@ -1,38 +1,36 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 //============================================================================
4 define([
5 // OutputArea
5 'base/js/namespace',
6 //============================================================================
6 'jqueryui',
7
7 'base/js/utils',
8 /**
8 'base/js/security',
9 * @module IPython
9 'base/js/keyboard',
10 * @namespace IPython
10 'notebook/js/mathjaxutils',
11 * @submodule OutputArea
11 ], function(IPython, $, utils, security, keyboard, mathjaxutils) {
12 */
13 var IPython = (function (IPython) {
14 "use strict";
12 "use strict";
15
13
16 var utils = IPython.utils;
17
18 /**
14 /**
19 * @class OutputArea
15 * @class OutputArea
20 *
16 *
21 * @constructor
17 * @constructor
22 */
18 */
23
19
24 var OutputArea = function (selector, prompt_area) {
20 var OutputArea = function (options) {
25 this.selector = selector;
21 this.selector = options.selector;
26 this.wrapper = $(selector);
22 this.events = options.events;
23 this.keyboard_manager = options.keyboard_manager;
24 this.wrapper = $(options.selector);
27 this.outputs = [];
25 this.outputs = [];
28 this.collapsed = false;
26 this.collapsed = false;
29 this.scrolled = false;
27 this.scrolled = false;
30 this.trusted = true;
28 this.trusted = true;
31 this.clear_queued = null;
29 this.clear_queued = null;
32 if (prompt_area === undefined) {
30 if (options.prompt_area === undefined) {
33 this.prompt_area = true;
31 this.prompt_area = true;
34 } else {
32 } else {
35 this.prompt_area = prompt_area;
33 this.prompt_area = options.prompt_area;
36 }
34 }
37 this.create_elements();
35 this.create_elements();
38 this.style();
36 this.style();
@@ -101,7 +99,7 b' var IPython = (function (IPython) {'
101
99
102 this.element.resize(function () {
100 this.element.resize(function () {
103 // FIXME: Firefox on Linux misbehaves, so automatic scrolling is disabled
101 // FIXME: Firefox on Linux misbehaves, so automatic scrolling is disabled
104 if ( IPython.utils.browser[0] === "Firefox" ) {
102 if ( utils.browser[0] === "Firefox" ) {
105 return;
103 return;
106 }
104 }
107 // maybe scroll output,
105 // maybe scroll output,
@@ -515,7 +513,7 b' var IPython = (function (IPython) {'
515 if (!this.trusted && !OutputArea.safe_outputs[type]) {
513 if (!this.trusted && !OutputArea.safe_outputs[type]) {
516 // not trusted, sanitize HTML
514 // not trusted, sanitize HTML
517 if (type==='text/html' || type==='text/svg') {
515 if (type==='text/html' || type==='text/svg') {
518 value = IPython.security.sanitize_html(value);
516 value = security.sanitize_html(value);
519 } else {
517 } else {
520 // don't display if we don't know how to sanitize it
518 // don't display if we don't know how to sanitize it
521 console.log("Ignoring untrusted " + type + " output.");
519 console.log("Ignoring untrusted " + type + " output.");
@@ -531,7 +529,7 b' var IPython = (function (IPython) {'
531 if (['image/png', 'image/jpeg'].indexOf(type) < 0 && handle_inserted !== undefined) {
529 if (['image/png', 'image/jpeg'].indexOf(type) < 0 && handle_inserted !== undefined) {
532 setTimeout(handle_inserted, 0);
530 setTimeout(handle_inserted, 0);
533 }
531 }
534 $([IPython.events]).trigger('output_appended.OutputArea', [type, value, md, toinsert]);
532 this.events.trigger('output_appended.OutputArea', [type, value, md, toinsert]);
535 return toinsert;
533 return toinsert;
536 }
534 }
537 }
535 }
@@ -542,7 +540,7 b' var IPython = (function (IPython) {'
542 var append_html = function (html, md, element) {
540 var append_html = function (html, md, element) {
543 var type = 'text/html';
541 var type = 'text/html';
544 var toinsert = this.create_output_subarea(md, "output_html rendered_html", type);
542 var toinsert = this.create_output_subarea(md, "output_html rendered_html", type);
545 IPython.keyboard_manager.register_events(toinsert);
543 this.keyboard_manager.register_events(toinsert);
546 toinsert.append(html);
544 toinsert.append(html);
547 element.append(toinsert);
545 element.append(toinsert);
548 return toinsert;
546 return toinsert;
@@ -552,11 +550,11 b' var IPython = (function (IPython) {'
552 var append_markdown = function(markdown, md, element) {
550 var append_markdown = function(markdown, md, element) {
553 var type = 'text/markdown';
551 var type = 'text/markdown';
554 var toinsert = this.create_output_subarea(md, "output_markdown", type);
552 var toinsert = this.create_output_subarea(md, "output_markdown", type);
555 var text_and_math = IPython.mathjaxutils.remove_math(markdown);
553 var text_and_math = mathjaxutils.remove_math(markdown);
556 var text = text_and_math[0];
554 var text = text_and_math[0];
557 var math = text_and_math[1];
555 var math = text_and_math[1];
558 var html = marked.parser(marked.lexer(text));
556 var html = marked.parser(marked.lexer(text));
559 html = IPython.mathjaxutils.replace_math(html, math);
557 html = mathjaxutils.replace_math(html, math);
560 toinsert.append(html);
558 toinsert.append(html);
561 element.append(toinsert);
559 element.append(toinsert);
562 return toinsert;
560 return toinsert;
@@ -567,7 +565,7 b' var IPython = (function (IPython) {'
567 // We just eval the JS code, element appears in the local scope.
565 // We just eval the JS code, element appears in the local scope.
568 var type = 'application/javascript';
566 var type = 'application/javascript';
569 var toinsert = this.create_output_subarea(md, "output_javascript", type);
567 var toinsert = this.create_output_subarea(md, "output_javascript", type);
570 IPython.keyboard_manager.register_events(toinsert);
568 this.keyboard_manager.register_events(toinsert);
571 element.append(toinsert);
569 element.append(toinsert);
572
570
573 // Fix for ipython/issues/5293, make sure `element` is the area which
571 // Fix for ipython/issues/5293, make sure `element` is the area which
@@ -758,7 +756,7 b' var IPython = (function (IPython) {'
758 .keydown(function (event, ui) {
756 .keydown(function (event, ui) {
759 // make sure we submit on enter,
757 // make sure we submit on enter,
760 // and don't re-execute the *cell* on shift-enter
758 // and don't re-execute the *cell* on shift-enter
761 if (event.which === IPython.keyboard.keycodes.enter) {
759 if (event.which === keyboard.keycodes.enter) {
762 that._submit_raw_input();
760 that._submit_raw_input();
763 return false;
761 return false;
764 }
762 }
@@ -770,7 +768,7 b' var IPython = (function (IPython) {'
770 var raw_input = area.find('input.raw_input');
768 var raw_input = area.find('input.raw_input');
771 // Register events that enable/disable the keyboard manager while raw
769 // Register events that enable/disable the keyboard manager while raw
772 // input is focused.
770 // input is focused.
773 IPython.keyboard_manager.register_events(raw_input);
771 this.keyboard_manager.register_events(raw_input);
774 // Note, the following line used to read raw_input.focus().focus().
772 // Note, the following line used to read raw_input.focus().focus().
775 // This seemed to be needed otherwise only the cell would be focused.
773 // This seemed to be needed otherwise only the cell would be focused.
776 // But with the modal UI, this seems to work fine with one call to focus().
774 // But with the modal UI, this seems to work fine with one call to focus().
@@ -796,7 +794,7 b' var IPython = (function (IPython) {'
796 container.parent().remove();
794 container.parent().remove();
797 // replace with plaintext version in stdout
795 // replace with plaintext version in stdout
798 this.append_output(content, false);
796 this.append_output(content, false);
799 $([IPython.events]).trigger('send_input_reply.Kernel', value);
797 this.events.trigger('send_input_reply.Kernel', value);
800 }
798 }
801
799
802
800
@@ -987,8 +985,8 b' var IPython = (function (IPython) {'
987 "application/pdf" : append_pdf
985 "application/pdf" : append_pdf
988 };
986 };
989
987
988 // For backwards compatability.
990 IPython.OutputArea = OutputArea;
989 IPython.OutputArea = OutputArea;
991
990
992 return IPython;
991 return {'OutputArea': OutputArea};
993
992 });
994 }(IPython));
@@ -1,20 +1,29 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 //============================================================================
4 define([
5 // Pager
5 'base/js/namespace',
6 //============================================================================
6 'jqueryui',
7
7 'base/js/utils',
8 var IPython = (function (IPython) {
8 ], function(IPython, $, utils) {
9 "use strict";
9 "use strict";
10
10
11 var utils = IPython.utils;
11 var Pager = function (pager_selector, pager_splitter_selector, options) {
12
12 // Constructor
13 var Pager = function (pager_selector, pager_splitter_selector) {
13 //
14 // Parameters:
15 // pager_selector: string
16 // pager_splitter_selector: string
17 // options: dictionary
18 // Dictionary of keyword arguments.
19 // events: $(Events) instance
20 // layout_manager: LayoutManager instance
21 this.events = options.events;
14 this.pager_element = $(pager_selector);
22 this.pager_element = $(pager_selector);
15 this.pager_button_area = $('#pager_button_area');
23 this.pager_button_area = $('#pager_button_area');
16 var that = this;
24 var that = this;
17 this.percentage_height = 0.40;
25 this.percentage_height = 0.40;
26 options.layout_manager.pager = this;
18 this.pager_splitter_element = $(pager_splitter_selector)
27 this.pager_splitter_element = $(pager_splitter_selector)
19 .draggable({
28 .draggable({
20 containment: 'window',
29 containment: 'window',
@@ -23,7 +32,7 b' var IPython = (function (IPython) {'
23 drag: function(event, ui) {
32 drag: function(event, ui) {
24 // recalculate the amount of space the pager should take
33 // recalculate the amount of space the pager should take
25 var pheight = ($(document.body).height()-event.clientY-4);
34 var pheight = ($(document.body).height()-event.clientY-4);
26 var downprct = pheight/IPython.layout_manager.app_height();
35 var downprct = pheight/options.layout_manager.app_height();
27 downprct = Math.min(0.9, downprct);
36 downprct = Math.min(0.9, downprct);
28 if (downprct < 0.1) {
37 if (downprct < 0.1) {
29 that.percentage_height = 0.1;
38 that.percentage_height = 0.1;
@@ -32,7 +41,7 b' var IPython = (function (IPython) {'
32 that.percentage_height = downprct;
41 that.percentage_height = downprct;
33 that.expand({'duration':0});
42 that.expand({'duration':0});
34 }
43 }
35 IPython.layout_manager.do_resize();
44 options.layout_manager.do_resize();
36 }
45 }
37 });
46 });
38 this.expanded = false;
47 this.expanded = false;
@@ -47,22 +56,22 b' var IPython = (function (IPython) {'
47 $('<a>').attr('role', "button")
56 $('<a>').attr('role', "button")
48 .attr('title',"Open the pager in an external window")
57 .attr('title',"Open the pager in an external window")
49 .addClass('ui-button')
58 .addClass('ui-button')
50 .click(function(){that.detach()})
59 .click(function(){that.detach();})
51 .attr('style','position: absolute; right: 20px;')
60 .attr('style','position: absolute; right: 20px;')
52 .append(
61 .append(
53 $('<span>').addClass("ui-icon ui-icon-extlink")
62 $('<span>').addClass("ui-icon ui-icon-extlink")
54 )
63 )
55 )
64 );
56 this.pager_button_area.append(
65 this.pager_button_area.append(
57 $('<a>').attr('role', "button")
66 $('<a>').attr('role', "button")
58 .attr('title',"Close the pager")
67 .attr('title',"Close the pager")
59 .addClass('ui-button')
68 .addClass('ui-button')
60 .click(function(){that.collapse()})
69 .click(function(){that.collapse();})
61 .attr('style','position: absolute; right: 5px;')
70 .attr('style','position: absolute; right: 5px;')
62 .append(
71 .append(
63 $('<span>').addClass("ui-icon ui-icon-close")
72 $('<span>').addClass("ui-icon ui-icon-close")
64 )
73 )
65 )
74 );
66 };
75 };
67
76
68 Pager.prototype.style = function () {
77 Pager.prototype.style = function () {
@@ -105,7 +114,7 b' var IPython = (function (IPython) {'
105 that.toggle();
114 that.toggle();
106 });
115 });
107
116
108 $([IPython.events]).on('open_with_text.Pager', function (event, payload) {
117 this.events.on('open_with_text.Pager', function (event, payload) {
109 // FIXME: support other mime types
118 // FIXME: support other mime types
110 if (payload.data['text/plain'] && payload.data['text/plain'] !== "") {
119 if (payload.data['text/plain'] && payload.data['text/plain'] !== "") {
111 that.clear();
120 that.clear();
@@ -171,10 +180,8 b' var IPython = (function (IPython) {'
171 this.pager_element.find(".container").append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
180 this.pager_element.find(".container").append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
172 };
181 };
173
182
174
183 // Backwards compatability.
175 IPython.Pager = Pager;
184 IPython.Pager = Pager;
176
185
177 return IPython;
186 return {'Pager': Pager};
178
187 });
179 }(IPython));
180
@@ -1,16 +1,28 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 //============================================================================
4 define([
5 // QuickHelp button
5 'base/js/namespace',
6 //============================================================================
6 'jquery',
7
7 'base/js/utils',
8 var IPython = (function (IPython) {
8 'base/js/dialog',
9 ], function(IPython, $, utils, dialog) {
9 "use strict";
10 "use strict";
10
11 var platform = utils.platform;
11 var platform = IPython.utils.platform;
12
12
13 var QuickHelp = function (options) {
13 var QuickHelp = function (selector) {
14 // Constructor
15 //
16 // Parameters:
17 // options: dictionary
18 // Dictionary of keyword arguments.
19 // events: $(Events) instance
20 // keyboard_manager: KeyboardManager instance
21 // notebook: Notebook instance
22 this.keyboard_manager = options.keyboard_manager;
23 this.notebook = options.notebook;
24 this.keyboard_manager.quick_help = this;
25 this.events = options.events;
14 };
26 };
15
27
16 var cmd_ctrl = 'Ctrl-';
28 var cmd_ctrl = 'Ctrl-';
@@ -70,8 +82,8 b' var IPython = (function (IPython) {'
70 $(this.shortcut_dialog).modal("toggle");
82 $(this.shortcut_dialog).modal("toggle");
71 return;
83 return;
72 }
84 }
73 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
85 var command_shortcuts = this.keyboard_manager.command_shortcuts.help();
74 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
86 var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help();
75 var help, shortcut;
87 var help, shortcut;
76 var i, half, n;
88 var i, half, n;
77 var element = $('<div/>');
89 var element = $('<div/>');
@@ -96,21 +108,23 b' var IPython = (function (IPython) {'
96 var edit_div = this.build_edit_help(cm_shortcuts);
108 var edit_div = this.build_edit_help(cm_shortcuts);
97 element.append(edit_div);
109 element.append(edit_div);
98
110
99 this.shortcut_dialog = IPython.dialog.modal({
111 this.shortcut_dialog = dialog.modal({
100 title : "Keyboard shortcuts",
112 title : "Keyboard shortcuts",
101 body : element,
113 body : element,
102 destroy : false,
114 destroy : false,
103 buttons : {
115 buttons : {
104 Close : {}
116 Close : {}
105 }
117 },
118 notebook: this.notebook,
119 keyboard_manager: this.keyboard_manager,
106 });
120 });
107 this.shortcut_dialog.addClass("modal_stretch");
121 this.shortcut_dialog.addClass("modal_stretch");
108
122
109 $([IPython.events]).on('rebuild.QuickHelp', function() { that.force_rebuild = true;});
123 this.events.on('rebuild.QuickHelp', function() { that.force_rebuild = true;});
110 };
124 };
111
125
112 QuickHelp.prototype.build_command_help = function () {
126 QuickHelp.prototype.build_command_help = function () {
113 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
127 var command_shortcuts = this.keyboard_manager.command_shortcuts.help();
114 return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
128 return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
115 };
129 };
116
130
@@ -134,7 +148,7 b' var IPython = (function (IPython) {'
134 };
148 };
135
149
136 QuickHelp.prototype.build_edit_help = function (cm_shortcuts) {
150 QuickHelp.prototype.build_edit_help = function (cm_shortcuts) {
137 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
151 var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help();
138 jQuery.merge(cm_shortcuts, edit_shortcuts);
152 jQuery.merge(cm_shortcuts, edit_shortcuts);
139 return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', cm_shortcuts);
153 return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', cm_shortcuts);
140 };
154 };
@@ -163,9 +177,8 b' var IPython = (function (IPython) {'
163 return div;
177 return div;
164 };
178 };
165
179
166 // Set module variables
180 // Backwards compatability.
167 IPython.QuickHelp = QuickHelp;
181 IPython.QuickHelp = QuickHelp;
168
182
169 return IPython;
183 return {'QuickHelp': QuickHelp};
170
184 });
171 }(IPython));
@@ -1,21 +1,22 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'base/js/utils',
8 //============================================================================
8 'base/js/dialog',
9 // SaveWidget
9 'base/js/keyboard',
10 //============================================================================
10 'dateformat',
11
11 ], function(IPython, $, utils, dialog, keyboard) {
12 var IPython = (function (IPython) {
13 "use strict";
12 "use strict";
14
13
15 var utils = IPython.utils;
14 var SaveWidget = function (selector, options) {
16
15 // TODO: Remove circulat ref.
17 var SaveWidget = function (selector) {
16 this.notebook = undefined;
18 this.selector = selector;
17 this.selector = selector;
18 this.events = options.events;
19 this.keyboard_manager = options.keyboard_manager;
19 if (this.selector !== undefined) {
20 if (this.selector !== undefined) {
20 this.element = $(selector);
21 this.element = $(selector);
21 this.style();
22 this.style();
@@ -23,7 +24,6 b' var IPython = (function (IPython) {'
23 }
24 }
24 };
25 };
25
26
26
27 SaveWidget.prototype.style = function () {
27 SaveWidget.prototype.style = function () {
28 };
28 };
29
29
@@ -38,56 +38,59 b' var IPython = (function (IPython) {'
38 }, function () {
38 }, function () {
39 $(this).removeClass("ui-state-hover");
39 $(this).removeClass("ui-state-hover");
40 });
40 });
41 $([IPython.events]).on('notebook_loaded.Notebook', function () {
41 this.events.on('notebook_loaded.Notebook', function () {
42 that.update_notebook_name();
42 that.update_notebook_name();
43 that.update_document_title();
43 that.update_document_title();
44 });
44 });
45 $([IPython.events]).on('notebook_saved.Notebook', function () {
45 this.events.on('notebook_saved.Notebook', function () {
46 that.update_notebook_name();
46 that.update_notebook_name();
47 that.update_document_title();
47 that.update_document_title();
48 });
48 });
49 $([IPython.events]).on('notebook_renamed.Notebook', function () {
49 this.events.on('notebook_renamed.Notebook', function () {
50 that.update_notebook_name();
50 that.update_notebook_name();
51 that.update_document_title();
51 that.update_document_title();
52 that.update_address_bar();
52 that.update_address_bar();
53 });
53 });
54 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
54 this.events.on('notebook_save_failed.Notebook', function () {
55 that.set_save_status('Autosave Failed!');
55 that.set_save_status('Autosave Failed!');
56 });
56 });
57 $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
57 this.events.on('checkpoints_listed.Notebook', function (event, data) {
58 that.set_last_checkpoint(data[0]);
58 that.set_last_checkpoint(data[0]);
59 });
59 });
60
60
61 $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
61 this.events.on('checkpoint_created.Notebook', function (event, data) {
62 that.set_last_checkpoint(data);
62 that.set_last_checkpoint(data);
63 });
63 });
64 $([IPython.events]).on('set_dirty.Notebook', function (event, data) {
64 this.events.on('set_dirty.Notebook', function (event, data) {
65 that.set_autosaved(data.value);
65 that.set_autosaved(data.value);
66 });
66 });
67 };
67 };
68
68
69
69
70 SaveWidget.prototype.rename_notebook = function () {
70 SaveWidget.prototype.rename_notebook = function (options) {
71 options = options || {};
71 var that = this;
72 var that = this;
72 var dialog = $('<div/>').append(
73 var dialog_body = $('<div/>').append(
73 $("<p/>").addClass("rename-message")
74 $("<p/>").addClass("rename-message")
74 .text('Enter a new notebook name:')
75 .text('Enter a new notebook name:')
75 ).append(
76 ).append(
76 $("<br/>")
77 $("<br/>")
77 ).append(
78 ).append(
78 $('<input/>').attr('type','text').attr('size','25').addClass('form-control')
79 $('<input/>').attr('type','text').attr('size','25').addClass('form-control')
79 .val(IPython.notebook.get_notebook_name())
80 .val(that.notebook.get_notebook_name())
80 );
81 );
81 IPython.dialog.modal({
82 dialog.modal({
82 title: "Rename Notebook",
83 title: "Rename Notebook",
83 body: dialog,
84 body: dialog_body,
85 notebook: options.notebook,
86 keyboard_manager: this.keyboard_manager,
84 buttons : {
87 buttons : {
85 "Cancel": {},
88 "Cancel": {},
86 "OK": {
89 "OK": {
87 class: "btn-primary",
90 class: "btn-primary",
88 click: function () {
91 click: function () {
89 var new_name = $(this).find('input').val();
92 var new_name = $(this).find('input').val();
90 if (!IPython.notebook.test_notebook_name(new_name)) {
93 if (!that.notebook.test_notebook_name(new_name)) {
91 $(this).find('.rename-message').text(
94 $(this).find('.rename-message').text(
92 "Invalid notebook name. Notebook names must "+
95 "Invalid notebook name. Notebook names must "+
93 "have 1 or more characters and can contain any characters " +
96 "have 1 or more characters and can contain any characters " +
@@ -95,7 +98,7 b' var IPython = (function (IPython) {'
95 );
98 );
96 return false;
99 return false;
97 } else {
100 } else {
98 IPython.notebook.rename(new_name);
101 that.notebook.rename(new_name);
99 }
102 }
100 }}
103 }}
101 },
104 },
@@ -103,7 +106,7 b' var IPython = (function (IPython) {'
103 var that = $(this);
106 var that = $(this);
104 // Upon ENTER, click the OK button.
107 // Upon ENTER, click the OK button.
105 that.find('input[type="text"]').keydown(function (event, ui) {
108 that.find('input[type="text"]').keydown(function (event, ui) {
106 if (event.which === IPython.keyboard.keycodes.enter) {
109 if (event.which === keyboard.keycodes.enter) {
107 that.find('.btn-primary').first().click();
110 that.find('.btn-primary').first().click();
108 return false;
111 return false;
109 }
112 }
@@ -111,24 +114,24 b' var IPython = (function (IPython) {'
111 that.find('input[type="text"]').focus().select();
114 that.find('input[type="text"]').focus().select();
112 }
115 }
113 });
116 });
114 }
117 };
115
118
116
119
117 SaveWidget.prototype.update_notebook_name = function () {
120 SaveWidget.prototype.update_notebook_name = function () {
118 var nbname = IPython.notebook.get_notebook_name();
121 var nbname = this.notebook.get_notebook_name();
119 this.element.find('span#notebook_name').text(nbname);
122 this.element.find('span#notebook_name').text(nbname);
120 };
123 };
121
124
122
125
123 SaveWidget.prototype.update_document_title = function () {
126 SaveWidget.prototype.update_document_title = function () {
124 var nbname = IPython.notebook.get_notebook_name();
127 var nbname = this.notebook.get_notebook_name();
125 document.title = nbname;
128 document.title = nbname;
126 };
129 };
127
130
128 SaveWidget.prototype.update_address_bar = function(){
131 SaveWidget.prototype.update_address_bar = function(){
129 var base_url = IPython.notebook.base_url;
132 var base_url = this.notebook.base_url;
130 var nbname = IPython.notebook.notebook_name;
133 var nbname = this.notebook.notebook_name;
131 var path = IPython.notebook.notebook_path;
134 var path = this.notebook.notebook_path;
132 var state = {path : path, name: nbname};
135 var state = {path : path, name: nbname};
133 window.history.replaceState(state, "", utils.url_join_encode(
136 window.history.replaceState(state, "", utils.url_join_encode(
134 base_url,
137 base_url,
@@ -141,11 +144,11 b' var IPython = (function (IPython) {'
141
144
142 SaveWidget.prototype.set_save_status = function (msg) {
145 SaveWidget.prototype.set_save_status = function (msg) {
143 this.element.find('span#autosave_status').text(msg);
146 this.element.find('span#autosave_status').text(msg);
144 }
147 };
145
148
146 SaveWidget.prototype.set_checkpoint_status = function (msg) {
149 SaveWidget.prototype.set_checkpoint_status = function (msg) {
147 this.element.find('span#checkpoint_status').text(msg);
150 this.element.find('span#checkpoint_status').text(msg);
148 }
151 };
149
152
150 SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
153 SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
151 if (!checkpoint) {
154 if (!checkpoint) {
@@ -156,7 +159,7 b' var IPython = (function (IPython) {'
156 this.set_checkpoint_status(
159 this.set_checkpoint_status(
157 "Last Checkpoint: " + d.format('mmm dd HH:MM')
160 "Last Checkpoint: " + d.format('mmm dd HH:MM')
158 );
161 );
159 }
162 };
160
163
161 SaveWidget.prototype.set_autosaved = function (dirty) {
164 SaveWidget.prototype.set_autosaved = function (dirty) {
162 if (dirty) {
165 if (dirty) {
@@ -166,10 +169,9 b' var IPython = (function (IPython) {'
166 }
169 }
167 };
170 };
168
171
169
172 // Backwards compatability.
170 IPython.SaveWidget = SaveWidget;
173 IPython.SaveWidget = SaveWidget;
171
174
172 return IPython;
175 return {'SaveWidget': SaveWidget};
173
174 }(IPython));
175
176
177 });
@@ -1,60 +1,57 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2012 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'notebook/js/cell',
8 //============================================================================
8 'base/js/security',
9 // TextCell
9 'notebook/js/mathjaxutils',
10 //============================================================================
10 'notebook/js/celltoolbar',
11
11 'components/marked/lib/marked',
12
12 ], function(IPython, $, cell, security, mathjaxutils, celltoolbar, marked) {
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) {
20 "use strict";
13 "use strict";
14 var Cell = cell.Cell;
21
15
22 // TextCell base class
23 var keycodes = IPython.keyboard.keycodes;
24 var security = IPython.security;
25
26 /**
27 * Construct a new TextCell, codemirror mode is by default 'htmlmixed', and cell type is 'text'
28 * cell start as not redered.
29 *
30 * @class TextCell
31 * @constructor TextCell
32 * @extend IPython.Cell
33 * @param {object|undefined} [options]
34 * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config
35 * @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass)
36 */
37 var TextCell = function (options) {
16 var TextCell = function (options) {
17 // Constructor
18 //
19 // Construct a new TextCell, codemirror mode is by default 'htmlmixed',
20 // and cell type is 'text' cell start as not redered.
21 //
22 // Parameters:
23 // options: dictionary
24 // Dictionary of keyword arguments.
25 // events: $(Events) instance
26 // config: dictionary
27 // keyboard_manager: KeyboardManager instance
28 // notebook: Notebook instance
29 options = options || {};
30
38 // in all TextCell/Cell subclasses
31 // in all TextCell/Cell subclasses
39 // do not assign most of members here, just pass it down
32 // do not assign most of members here, just pass it down
40 // in the options dict potentially overwriting what you wish.
33 // in the options dict potentially overwriting what you wish.
41 // they will be assigned in the base class.
34 // they will be assigned in the base class.
42
35 this.notebook = options.notebook;
36 this.events = options.events;
37 this.config = options.config;
38
43 // we cannot put this as a class key as it has handle to "this".
39 // we cannot put this as a class key as it has handle to "this".
44 var cm_overwrite_options = {
40 var cm_overwrite_options = {
45 onKeyEvent: $.proxy(this.handle_keyevent,this)
41 onKeyEvent: $.proxy(this.handle_keyevent,this)
46 };
42 };
47
43 var config = this.mergeopt(TextCell, this.config, {cm_config:cm_overwrite_options});
48 options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options});
44 Cell.apply(this, [{
45 config: config,
46 keyboard_manager: options.keyboard_manager,
47 events: this.events}]);
49
48
50 this.cell_type = this.cell_type || 'text';
49 this.cell_type = this.cell_type || 'text';
51
50 mathjaxutils = mathjaxutils;
52 IPython.Cell.apply(this, [options]);
53
54 this.rendered = false;
51 this.rendered = false;
55 };
52 };
56
53
57 TextCell.prototype = new IPython.Cell();
54 TextCell.prototype = new Cell();
58
55
59 TextCell.options_default = {
56 TextCell.options_default = {
60 cm_config : {
57 cm_config : {
@@ -71,7 +68,7 b' var IPython = (function (IPython) {'
71 * @private
68 * @private
72 */
69 */
73 TextCell.prototype.create_element = function () {
70 TextCell.prototype.create_element = function () {
74 IPython.Cell.prototype.create_element.apply(this, arguments);
71 Cell.prototype.create_element.apply(this, arguments);
75
72
76 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
73 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
77 cell.attr('tabindex','2');
74 cell.attr('tabindex','2');
@@ -79,7 +76,10 b' var IPython = (function (IPython) {'
79 var prompt = $('<div/>').addClass('prompt input_prompt');
76 var prompt = $('<div/>').addClass('prompt input_prompt');
80 cell.append(prompt);
77 cell.append(prompt);
81 var inner_cell = $('<div/>').addClass('inner_cell');
78 var inner_cell = $('<div/>').addClass('inner_cell');
82 this.celltoolbar = new IPython.CellToolbar(this);
79 this.celltoolbar = new celltoolbar.CellToolbar({
80 cell: this,
81 events: this.events,
82 notebook: this.notebook});
83 inner_cell.append(this.celltoolbar.element);
83 inner_cell.append(this.celltoolbar.element);
84 var input_area = $('<div/>').addClass('input_area');
84 var input_area = $('<div/>').addClass('input_area');
85 this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
85 this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
@@ -99,12 +99,12 b' var IPython = (function (IPython) {'
99 * @method bind_event
99 * @method bind_event
100 */
100 */
101 TextCell.prototype.bind_events = function () {
101 TextCell.prototype.bind_events = function () {
102 IPython.Cell.prototype.bind_events.apply(this);
102 Cell.prototype.bind_events.apply(this);
103 var that = this;
103 var that = this;
104
104
105 this.element.dblclick(function () {
105 this.element.dblclick(function () {
106 if (that.selected === false) {
106 if (that.selected === false) {
107 $([IPython.events]).trigger('select.Cell', {'cell':that});
107 this.events.trigger('select.Cell', {'cell':that});
108 }
108 }
109 var cont = that.unrender();
109 var cont = that.unrender();
110 if (cont) {
110 if (cont) {
@@ -116,7 +116,7 b' var IPython = (function (IPython) {'
116 // Cell level actions
116 // Cell level actions
117
117
118 TextCell.prototype.select = function () {
118 TextCell.prototype.select = function () {
119 var cont = IPython.Cell.prototype.select.apply(this);
119 var cont = Cell.prototype.select.apply(this);
120 if (cont) {
120 if (cont) {
121 if (this.mode === 'edit') {
121 if (this.mode === 'edit') {
122 this.code_mirror.refresh();
122 this.code_mirror.refresh();
@@ -127,7 +127,7 b' var IPython = (function (IPython) {'
127
127
128 TextCell.prototype.unrender = function () {
128 TextCell.prototype.unrender = function () {
129 if (this.read_only) return;
129 if (this.read_only) return;
130 var cont = IPython.Cell.prototype.unrender.apply(this);
130 var cont = Cell.prototype.unrender.apply(this);
131 if (cont) {
131 if (cont) {
132 var text_cell = this.element;
132 var text_cell = this.element;
133 var output = text_cell.find("div.text_cell_render");
133 var output = text_cell.find("div.text_cell_render");
@@ -170,7 +170,6 b' var IPython = (function (IPython) {'
170 /**
170 /**
171 * setter :{{#crossLink "TextCell/set_rendered"}}{{/crossLink}}
171 * setter :{{#crossLink "TextCell/set_rendered"}}{{/crossLink}}
172 * @method get_rendered
172 * @method get_rendered
173 * @return {html} html of rendered element
174 * */
173 * */
175 TextCell.prototype.get_rendered = function() {
174 TextCell.prototype.get_rendered = function() {
176 return this.element.find('div.text_cell_render').html();
175 return this.element.find('div.text_cell_render').html();
@@ -191,7 +190,7 b' var IPython = (function (IPython) {'
191 * @method fromJSON
190 * @method fromJSON
192 */
191 */
193 TextCell.prototype.fromJSON = function (data) {
192 TextCell.prototype.fromJSON = function (data) {
194 IPython.Cell.prototype.fromJSON.apply(this, arguments);
193 Cell.prototype.fromJSON.apply(this, arguments);
195 if (data.cell_type === this.cell_type) {
194 if (data.cell_type === this.cell_type) {
196 if (data.source !== undefined) {
195 if (data.source !== undefined) {
197 this.set_text(data.source);
196 this.set_text(data.source);
@@ -211,7 +210,7 b' var IPython = (function (IPython) {'
211 * @return {object} cell data serialised to json
210 * @return {object} cell data serialised to json
212 */
211 */
213 TextCell.prototype.toJSON = function () {
212 TextCell.prototype.toJSON = function () {
214 var data = IPython.Cell.prototype.toJSON.apply(this);
213 var data = Cell.prototype.toJSON.apply(this);
215 data.source = this.get_text();
214 data.source = this.get_text();
216 if (data.source == this.placeholder) {
215 if (data.source == this.placeholder) {
217 data.source = "";
216 data.source = "";
@@ -220,16 +219,21 b' var IPython = (function (IPython) {'
220 };
219 };
221
220
222
221
223 /**
224 * @class MarkdownCell
225 * @constructor MarkdownCell
226 * @extends IPython.HTMLCell
227 */
228 var MarkdownCell = function (options) {
222 var MarkdownCell = function (options) {
229 options = this.mergeopt(MarkdownCell, options);
223 // Constructor
224 //
225 // Parameters:
226 // options: dictionary
227 // Dictionary of keyword arguments.
228 // events: $(Events) instance
229 // config: dictionary
230 // keyboard_manager: KeyboardManager instance
231 // notebook: Notebook instance
232 options = options || {};
233 var config = this.mergeopt(MarkdownCell, options.config);
234 TextCell.apply(this, [$.extend({}, options, {config: config})]);
230
235
231 this.cell_type = 'markdown';
236 this.cell_type = 'markdown';
232 TextCell.apply(this, [options]);
233 };
237 };
234
238
235 MarkdownCell.options_default = {
239 MarkdownCell.options_default = {
@@ -245,16 +249,16 b' var IPython = (function (IPython) {'
245 * @method render
249 * @method render
246 */
250 */
247 MarkdownCell.prototype.render = function () {
251 MarkdownCell.prototype.render = function () {
248 var cont = IPython.TextCell.prototype.render.apply(this);
252 var cont = TextCell.prototype.render.apply(this);
249 if (cont) {
253 if (cont) {
250 var text = this.get_text();
254 var text = this.get_text();
251 var math = null;
255 var math = null;
252 if (text === "") { text = this.placeholder; }
256 if (text === "") { text = this.placeholder; }
253 var text_and_math = IPython.mathjaxutils.remove_math(text);
257 var text_and_math = mathjaxutils.remove_math(text);
254 text = text_and_math[0];
258 text = text_and_math[0];
255 math = text_and_math[1];
259 math = text_and_math[1];
256 var html = marked.parser(marked.lexer(text));
260 var html = marked.parser(marked.lexer(text));
257 html = IPython.mathjaxutils.replace_math(html, math);
261 html = mathjaxutils.replace_math(html, math);
258 html = security.sanitize_html(html);
262 html = security.sanitize_html(html);
259 html = $($.parseHTML(html));
263 html = $($.parseHTML(html));
260 // links in markdown cells should open in new tabs
264 // links in markdown cells should open in new tabs
@@ -268,20 +272,23 b' var IPython = (function (IPython) {'
268 };
272 };
269
273
270
274
271 // RawCell
272
273 /**
274 * @class RawCell
275 * @constructor RawCell
276 * @extends IPython.TextCell
277 */
278 var RawCell = function (options) {
275 var RawCell = function (options) {
276 // Constructor
277 //
278 // Parameters:
279 // options: dictionary
280 // Dictionary of keyword arguments.
281 // events: $(Events) instance
282 // config: dictionary
283 // keyboard_manager: KeyboardManager instance
284 // notebook: Notebook instance
285 options = options || {};
286 var config = this.mergeopt(RawCell, options.config);
287 TextCell.apply(this, [$.extend({}, options, {config: config})]);
279
288
280 options = this.mergeopt(RawCell,options);
281 TextCell.apply(this, [options]);
282 this.cell_type = 'raw';
283 // RawCell should always hide its rendered div
289 // RawCell should always hide its rendered div
284 this.element.find('div.text_cell_render').hide();
290 this.element.find('div.text_cell_render').hide();
291 this.cell_type = 'raw';
285 };
292 };
286
293
287 RawCell.options_default = {
294 RawCell.options_default = {
@@ -309,12 +316,12 b' var IPython = (function (IPython) {'
309 * @method auto_highlight
316 * @method auto_highlight
310 */
317 */
311 RawCell.prototype.auto_highlight = function () {
318 RawCell.prototype.auto_highlight = function () {
312 this._auto_highlight(IPython.config.raw_cell_highlight);
319 this._auto_highlight(this.config.raw_cell_highlight);
313 };
320 };
314
321
315 /** @method render **/
322 /** @method render **/
316 RawCell.prototype.render = function () {
323 RawCell.prototype.render = function () {
317 var cont = IPython.TextCell.prototype.render.apply(this);
324 var cont = TextCell.prototype.render.apply(this);
318 if (cont){
325 if (cont){
319 var text = this.get_text();
326 var text = this.get_text();
320 if (text === "") { text = this.placeholder; }
327 if (text === "") { text = this.placeholder; }
@@ -325,26 +332,22 b' var IPython = (function (IPython) {'
325 };
332 };
326
333
327
334
328 /**
329 * @class HeadingCell
330 * @extends IPython.TextCell
331 */
332
333 /**
334 * @constructor HeadingCell
335 * @extends IPython.TextCell
336 */
337 var HeadingCell = function (options) {
335 var HeadingCell = function (options) {
338 options = this.mergeopt(HeadingCell, options);
336 // Constructor
337 //
338 // Parameters:
339 // options: dictionary
340 // Dictionary of keyword arguments.
341 // events: $(Events) instance
342 // config: dictionary
343 // keyboard_manager: KeyboardManager instance
344 // notebook: Notebook instance
345 options = options || {};
346 var config = this.mergeopt(HeadingCell, options.config);
347 TextCell.apply(this, [$.extend({}, options, {config: config})]);
339
348
340 this.level = 1;
349 this.level = 1;
341 this.cell_type = 'heading';
350 this.cell_type = 'heading';
342 TextCell.apply(this, [options]);
343
344 /**
345 * heading level of the cell, use getter and setter to access
346 * @property level
347 */
348 };
351 };
349
352
350 HeadingCell.options_default = {
353 HeadingCell.options_default = {
@@ -412,21 +415,20 b' var IPython = (function (IPython) {'
412 return r.children().first().html();
415 return r.children().first().html();
413 };
416 };
414
417
415
416 HeadingCell.prototype.render = function () {
418 HeadingCell.prototype.render = function () {
417 var cont = IPython.TextCell.prototype.render.apply(this);
419 var cont = TextCell.prototype.render.apply(this);
418 if (cont) {
420 if (cont) {
419 var text = this.get_text();
421 var text = this.get_text();
420 var math = null;
422 var math = null;
421 // Markdown headings must be a single line
423 // Markdown headings must be a single line
422 text = text.replace(/\n/g, ' ');
424 text = text.replace(/\n/g, ' ');
423 if (text === "") { text = this.placeholder; }
425 if (text === "") { text = this.placeholder; }
424 text = Array(this.level + 1).join("#") + " " + text;
426 text = new Array(this.level + 1).join("#") + " " + text;
425 var text_and_math = IPython.mathjaxutils.remove_math(text);
427 var text_and_math = mathjaxutils.remove_math(text);
426 text = text_and_math[0];
428 text = text_and_math[0];
427 math = text_and_math[1];
429 math = text_and_math[1];
428 var html = marked.parser(marked.lexer(text));
430 var html = marked.parser(marked.lexer(text));
429 html = IPython.mathjaxutils.replace_math(html, math);
431 html = mathjaxutils.replace_math(html, math);
430 html = security.sanitize_html(html);
432 html = security.sanitize_html(html);
431 var h = $($.parseHTML(html));
433 var h = $($.parseHTML(html));
432 // add id and linkback anchor
434 // add id and linkback anchor
@@ -446,13 +448,17 b' var IPython = (function (IPython) {'
446 return cont;
448 return cont;
447 };
449 };
448
450
451 // Backwards compatability.
449 IPython.TextCell = TextCell;
452 IPython.TextCell = TextCell;
450 IPython.MarkdownCell = MarkdownCell;
453 IPython.MarkdownCell = MarkdownCell;
451 IPython.RawCell = RawCell;
454 IPython.RawCell = RawCell;
452 IPython.HeadingCell = HeadingCell;
455 IPython.HeadingCell = HeadingCell;
453
456
454
457 var textcell = {
455 return IPython;
458 'TextCell': TextCell,
456
459 'MarkdownCell': MarkdownCell,
457 }(IPython));
460 'RawCell': RawCell,
458
461 'HeadingCell': HeadingCell,
462 };
463 return textcell;
464 });
@@ -1,20 +1,10 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // ToolBar
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11 /**
7 ], function(IPython, $) {
12 * @module IPython
13 * @namespace IPython
14 * @submodule ToolBar
15 */
16
17 var IPython = (function (IPython) {
18 "use strict";
8 "use strict";
19
9
20 /**
10 /**
@@ -23,8 +13,9 b' var IPython = (function (IPython) {'
23 * @constructor
13 * @constructor
24 * @param {Dom object} selector
14 * @param {Dom object} selector
25 */
15 */
26 var ToolBar = function (selector) {
16 var ToolBar = function (selector, layout_manager) {
27 this.selector = selector;
17 this.selector = selector;
18 this.layout_manager = layout_manager;
28 if (this.selector !== undefined) {
19 if (this.selector !== undefined) {
29 this.element = $(selector);
20 this.element = $(selector);
30 this.style();
21 this.style();
@@ -98,14 +89,13 b' var IPython = (function (IPython) {'
98 */
89 */
99 ToolBar.prototype.toggle = function () {
90 ToolBar.prototype.toggle = function () {
100 this.element.toggle();
91 this.element.toggle();
101 if (IPython.layout_manager !== undefined) {
92 if (this.layout_manager !== undefined) {
102 IPython.layout_manager.do_resize();
93 this.layout_manager.do_resize();
103 }
94 }
104 };
95 };
105
96
106
97 // Backwards compatability.
107 IPython.ToolBar = ToolBar;
98 IPython.ToolBar = ToolBar;
108
99
109 return IPython;
100 return {'ToolBar': ToolBar};
110
101 });
111 }(IPython));
@@ -1,125 +1,115 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 //============================================================================
4 define([
5 // Tooltip
5 'base/js/namespace',
6 //============================================================================
6 'jquery',
7 //
7 'base/js/utils',
8 // you can set the autocall time by setting `IPython.tooltip.time_before_tooltip` in ms
8 ], function(IPython, $, utils) {
9 //
10 // you can configure the differents action of pressing shift-tab several times in a row by
11 // setting/appending different fonction in the array
12 // IPython.tooltip.tabs_functions
13 //
14 // eg :
15 // IPython.tooltip.tabs_functions[4] = function (){console.log('this is the action of the 4th tab pressing')}
16 //
17 var IPython = (function (IPython) {
18 "use strict";
9 "use strict";
19
10
20 var utils = IPython.utils;
21
22 // tooltip constructor
11 // tooltip constructor
23 var Tooltip = function () {
12 var Tooltip = function (events) {
24 var that = this;
13 var that = this;
25 this.time_before_tooltip = 1200;
14 this.events = events;
26
15 this.time_before_tooltip = 1200;
27 // handle to html
28 this.tooltip = $('#tooltip');
29 this._hidden = true;
30
31 // variable for consecutive call
32 this._old_cell = null;
33 this._old_request = null;
34 this._consecutive_counter = 0;
35
36 // 'sticky ?'
37 this._sticky = false;
38
39 // display tooltip if the docstring is empty?
40 this._hide_if_no_docstring = false;
41
16
42 // contain the button in the upper right corner
17 // handle to html
43 this.buttons = $('<div/>').addClass('tooltipbuttons');
18 this.tooltip = $('#tooltip');
19 this._hidden = true;
44
20
45 // will contain the docstring
21 // variable for consecutive call
46 this.text = $('<div/>').addClass('tooltiptext').addClass('smalltooltip');
22 this._old_cell = null;
23 this._old_request = null;
24 this._consecutive_counter = 0;
47
25
48 // build the buttons menu on the upper right
26 // 'sticky ?'
49 // expand the tooltip to see more
27 this._sticky = false;
50 var expandlink = $('<a/>').attr('href', "#").addClass("ui-corner-all") //rounded corner
51 .attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press shift-tab twice)').click(function () {
52 that.expand();
53 }).append(
54 $('<span/>').text('Expand').addClass('ui-icon').addClass('ui-icon-plus'));
55
28
56 // open in pager
29 // display tooltip if the docstring is empty?
57 var morelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button').attr('title', 'show the current docstring in pager (press shift-tab 4 times)');
30 this._hide_if_no_docstring = false;
58 var morespan = $('<span/>').text('Open in Pager').addClass('ui-icon').addClass('ui-icon-arrowstop-l-n');
31
59 morelink.append(morespan);
32 // contain the button in the upper right corner
60 morelink.click(function () {
33 this.buttons = $('<div/>').addClass('tooltipbuttons');
61 that.showInPager(that._old_cell);
34
62 });
35 // will contain the docstring
36 this.text = $('<div/>').addClass('tooltiptext').addClass('smalltooltip');
37
38 // build the buttons menu on the upper right
39 // expand the tooltip to see more
40 var expandlink = $('<a/>').attr('href', "#").addClass("ui-corner-all") //rounded corner
41 .attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press shift-tab twice)').click(function () {
42 that.expand();
43 }).append(
44 $('<span/>').text('Expand').addClass('ui-icon').addClass('ui-icon-plus'));
45
46 // open in pager
47 var morelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button').attr('title', 'show the current docstring in pager (press shift-tab 4 times)');
48 var morespan = $('<span/>').text('Open in Pager').addClass('ui-icon').addClass('ui-icon-arrowstop-l-n');
49 morelink.append(morespan);
50 morelink.click(function () {
51 that.showInPager(that._old_cell);
52 });
63
53
64 // close the tooltip
54 // close the tooltip
65 var closelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button');
55 var closelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button');
66 var closespan = $('<span/>').text('Close').addClass('ui-icon').addClass('ui-icon-close');
56 var closespan = $('<span/>').text('Close').addClass('ui-icon').addClass('ui-icon-close');
67 closelink.append(closespan);
57 closelink.append(closespan);
68 closelink.click(function () {
58 closelink.click(function () {
69 that.remove_and_cancel_tooltip(true);
59 that.remove_and_cancel_tooltip(true);
70 });
60 });
71
61
72 this._clocklink = $('<a/>').attr('href', "#");
62 this._clocklink = $('<a/>').attr('href', "#");
73 this._clocklink.attr('role', "button");
63 this._clocklink.attr('role', "button");
74 this._clocklink.addClass('ui-button');
64 this._clocklink.addClass('ui-button');
75 this._clocklink.attr('title', 'Tootip is not dismissed while typing for 10 seconds');
65 this._clocklink.attr('title', 'Tootip is not dismissed while typing for 10 seconds');
76 var clockspan = $('<span/>').text('Close');
66 var clockspan = $('<span/>').text('Close');
77 clockspan.addClass('ui-icon');
67 clockspan.addClass('ui-icon');
78 clockspan.addClass('ui-icon-clock');
68 clockspan.addClass('ui-icon-clock');
79 this._clocklink.append(clockspan);
69 this._clocklink.append(clockspan);
80 this._clocklink.click(function () {
70 this._clocklink.click(function () {
81 that.cancel_stick();
71 that.cancel_stick();
82 });
72 });
83
73
84
74
85
75
86
76
87 //construct the tooltip
77 //construct the tooltip
88 // add in the reverse order you want them to appear
78 // add in the reverse order you want them to appear
89 this.buttons.append(closelink);
79 this.buttons.append(closelink);
90 this.buttons.append(expandlink);
80 this.buttons.append(expandlink);
91 this.buttons.append(morelink);
81 this.buttons.append(morelink);
92 this.buttons.append(this._clocklink);
82 this.buttons.append(this._clocklink);
93 this._clocklink.hide();
83 this._clocklink.hide();
94
84
95
85
96 // we need a phony element to make the small arrow
86 // we need a phony element to make the small arrow
97 // of the tooltip in css
87 // of the tooltip in css
98 // we will move the arrow later
88 // we will move the arrow later
99 this.arrow = $('<div/>').addClass('pretooltiparrow');
89 this.arrow = $('<div/>').addClass('pretooltiparrow');
100 this.tooltip.append(this.buttons);
90 this.tooltip.append(this.buttons);
101 this.tooltip.append(this.arrow);
91 this.tooltip.append(this.arrow);
102 this.tooltip.append(this.text);
92 this.tooltip.append(this.text);
103
93
104 // function that will be called if you press tab 1, 2, 3... times in a row
94 // function that will be called if you press tab 1, 2, 3... times in a row
105 this.tabs_functions = [function (cell, text, cursor) {
95 this.tabs_functions = [function (cell, text, cursor) {
106 that._request_tooltip(cell, text, cursor);
96 that._request_tooltip(cell, text, cursor);
107 }, function () {
97 }, function () {
108 that.expand();
98 that.expand();
109 }, function () {
99 }, function () {
110 that.stick();
100 that.stick();
111 }, function (cell) {
101 }, function (cell) {
112 that.cancel_stick();
102 that.cancel_stick();
113 that.showInPager(cell);
103 that.showInPager(cell);
114 }];
104 }];
115 // call after all the tabs function above have bee call to clean their effects
105 // call after all the tabs function above have bee call to clean their effects
116 // if necessary
106 // if necessary
117 this.reset_tabs_function = function (cell, text) {
107 this.reset_tabs_function = function (cell, text) {
118 this._old_cell = (cell) ? cell : null;
108 this._old_cell = (cell) ? cell : null;
119 this._old_request = (text) ? text : null;
109 this._old_request = (text) ? text : null;
120 this._consecutive_counter = 0;
110 this._consecutive_counter = 0;
121 };
122 };
111 };
112 };
123
113
124 Tooltip.prototype.is_visible = function () {
114 Tooltip.prototype.is_visible = function () {
125 return !this._hidden;
115 return !this._hidden;
@@ -131,7 +121,7 b' var IPython = (function (IPython) {'
131 var payload = {};
121 var payload = {};
132 payload.text = that._reply.content.data['text/plain'];
122 payload.text = that._reply.content.data['text/plain'];
133
123
134 $([IPython.events]).trigger('open_with_text.Pager', payload);
124 this.events.trigger('open_with_text.Pager', payload);
135 this.remove_and_cancel_tooltip();
125 this.remove_and_cancel_tooltip();
136 };
126 };
137
127
@@ -338,8 +328,8 b' var IPython = (function (IPython) {'
338 this.text.scrollTop(0);
328 this.text.scrollTop(0);
339 };
329 };
340
330
331 // Backwards compatability.
341 IPython.Tooltip = Tooltip;
332 IPython.Tooltip = Tooltip;
342
333
343 return IPython;
334 return {'Tooltip': Tooltip};
344
335 });
345 }(IPython));
@@ -1,135 +1,124 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Tour of IPython Notebok UI (with Bootstrap Tour)
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
7 'bootstraptour',
8 ], function(IPython, $, Tour) {
9 "use strict";
11
10
12 var tour_steps = [
11 var tour_style = "<div class='popover tour'>\n" +
13 {
12 "<div class='arrow'></div>\n" +
14 title: "Welcome to the Notebook Tour",
13 "<div style='position:absolute; top:7px; right:7px'>\n" +
15 placement: 'bottom',
14 "<button class='btn btn-default btn-sm icon-remove' data-role='end'></button>\n" +
16 orphan: true,
15 "</div><h3 class='popover-title'></h3>\n" +
17 content: "This tour will take 2 minutes.",
16 "<div class='popover-content'></div>\n" +
18 }, {
17 "<div class='popover-navigation'>\n" +
19 element: "#notebook_name",
18 "<button class='btn btn-default icon-step-backward' data-role='prev'></button>\n" +
20 title: "Filename",
19 "<button class='btn btn-default icon-step-forward pull-right' data-role='next'></button>\n" +
21 placement: 'bottom',
20 "<button id='tour-pause' class='btn btn-sm btn-default icon-pause' data-resume-text='' data-pause-text='' data-role='pause-resume'></button>\n" +
22 content: "Click here to change the filename for this notebook."
21 "</div>\n" +
23 }, {
22 "</div>";
24 element: $("#menus").parent(),
25 placement: 'bottom',
26 backdrop: true,
27 title: "Notebook Menubar",
28 content: "The menubar has menus for actions on the notebook, its cells, and the kernel it communicates with."
29 }, {
30 element: "#maintoolbar",
31 placement: 'bottom',
32 backdrop: true,
33 title: "Notebook Toolbar",
34 content: "The toolbar has buttons for the most common actions. Hover your mouse over each button for more information."
35 }, {
36 element: "#modal_indicator",
37 title: "Mode Indicator",
38 placement: 'bottom',
39 content: "The Notebook has two modes: Edit Mode and Command Mode. In this area, an indicator can appear to tell you which mode you are in.",
40 onShow: function(tour) { command_icon_hack(); }
41 }, {
42 element: "#modal_indicator",
43 title: "Command Mode",
44 placement: 'bottom',
45 onShow: function(tour) { IPython.notebook.command_mode(); command_icon_hack(); },
46 onNext: function(tour) { edit_mode(); },
47 content: "Right now you are in Command Mode, and many keyboard shortcuts are available. In this mode, no icon is displayed in the indicator area."
48 }, {
49 element: "#modal_indicator",
50 title: "Edit Mode",
51 placement: 'bottom',
52 onShow: function(tour) { edit_mode(); },
53 content: "Pressing <code>Enter</code> or clicking in the input text area of the cell switches to Edit Mode."
54 }, {
55 element: '.selected',
56 title: "Edit Mode",
57 placement: 'bottom',
58 onShow: function(tour) { edit_mode(); },
59 content: "Notice that the border around the currently active cell changed color. Typing will insert text into the currently active cell."
60 }, {
61 element: '.selected',
62 title: "Back to Command Mode",
63 placement: 'bottom',
64 onShow: function(tour) { IPython.notebook.command_mode(); },
65 onHide: function(tour) { $('#help_menu').parent().children('a').click(); },
66 content: "Pressing <code>Esc</code> or clicking outside of the input text area takes you back to Command Mode."
67 }, {
68 element: '#keyboard_shortcuts',
69 title: "Keyboard Shortcuts",
70 placement: 'bottom',
71 onHide: function(tour) { $('#help_menu').parent().children('a').click(); },
72 content: "You can click here to get a list of all of the keyboard shortcuts."
73 }, {
74 element: "#kernel_indicator",
75 title: "Kernel Indicator",
76 placement: 'bottom',
77 onShow: function(tour) { $([IPython.events]).trigger('status_idle.Kernel');},
78 content: "This is the Kernel indicator. It looks like this when the Kernel is idle.",
79 }, {
80 element: "#kernel_indicator",
81 title: "Kernel Indicator",
82 placement: 'bottom',
83 onShow: function(tour) { $([IPython.events]).trigger('status_busy.Kernel'); },
84 content: "The Kernel indicator looks like this when the Kernel is busy.",
85 }, {
86 element: ".icon-stop",
87 placement: 'bottom',
88 title: "Interrupting the Kernel",
89 onHide: function(tour) { $([IPython.events]).trigger('status_idle.Kernel'); },
90 content: "To cancel a computation in progress, you can click here."
91 }, {
92 element: "#notification_kernel",
93 placement: 'bottom',
94 onShow: function(tour) { $('.icon-stop').click(); },
95 title: "Notification Area",
96 content: "Messages in response to user actions (Save, Interrupt, etc) appear here."
97 }, {
98 title: "Fin.",
99 placement: 'bottom',
100 orphan: true,
101 content: "This concludes the IPython Notebook User Interface Tour. Happy hacking!",
102 }
103 ];
104
23
105 var tour_style = "<div class='popover tour'>\
24 var NotebookTour = function (notebook, events) {
106 <div class='arrow'></div>\
25 var that = this;
107 <div style='position:absolute; top:7px; right:7px'>\
26 this.notebook = notebook;
108 <button class='btn btn-default btn-sm icon-remove' data-role='end'></button></div>\
109 <h3 class='popover-title'></h3>\
110 <div class='popover-content'></div>\
111 <div class='popover-navigation'>\
112 <button class='btn btn-default icon-step-backward' data-role='prev'></button>\
113 <button class='btn btn-default icon-step-forward pull-right' data-role='next'></button>\
114 <button id='tour-pause' class='btn btn-sm btn-default icon-pause' data-resume-text='' data-pause-text='' data-role='pause-resume'></button>\
115 </div>\
116 </div>";
117
118 var command_icon_hack = function() {$('#modal_indicator').css('min-height', 20);}
119 var toggle_pause_play = function () { $('#tour-pause').toggleClass('icon-pause icon-play'); };
120 var edit_mode = function() {
121 IPython.notebook.focus_cell();
122 IPython.notebook.edit_mode();
123 ;}
124
125 IPython = (function (IPython) {
126 "use strict";
127
128
129 var NotebookTour = function () {
130 this.step_duration = 0;
27 this.step_duration = 0;
131 this.tour_steps = tour_steps ;
28 this.events = events;
132 this.tour_steps[0].content = "You can use the left and right arrow keys to go backwards and forwards.";
29 this.tour_steps = [
30 {
31 title: "Welcome to the Notebook Tour",
32 placement: 'bottom',
33 orphan: true,
34 content: "You can use the left and right arrow keys to go backwards and forwards.",
35 }, {
36 element: "#notebook_name",
37 title: "Filename",
38 placement: 'bottom',
39 content: "Click here to change the filename for this notebook."
40 }, {
41 element: $("#menus").parent(),
42 placement: 'bottom',
43 backdrop: true,
44 title: "Notebook Menubar",
45 content: "The menubar has menus for actions on the notebook, its cells, and the kernel it communicates with."
46 }, {
47 element: "#maintoolbar",
48 placement: 'bottom',
49 backdrop: true,
50 title: "Notebook Toolbar",
51 content: "The toolbar has buttons for the most common actions. Hover your mouse over each button for more information."
52 }, {
53 element: "#modal_indicator",
54 title: "Mode Indicator",
55 placement: 'bottom',
56 content: "The Notebook has two modes: Edit Mode and Command Mode. In this area, an indicator can appear to tell you which mode you are in.",
57 onShow: function(tour) { that.command_icon_hack(); }
58 }, {
59 element: "#modal_indicator",
60 title: "Command Mode",
61 placement: 'bottom',
62 onShow: function(tour) { notebook.command_mode(); that.command_icon_hack(); },
63 onNext: function(tour) { that.edit_mode(); },
64 content: "Right now you are in Command Mode, and many keyboard shortcuts are available. In this mode, no icon is displayed in the indicator area."
65 }, {
66 element: "#modal_indicator",
67 title: "Edit Mode",
68 placement: 'bottom',
69 onShow: function(tour) { that.edit_mode(); },
70 content: "Pressing <code>Enter</code> or clicking in the input text area of the cell switches to Edit Mode."
71 }, {
72 element: '.selected',
73 title: "Edit Mode",
74 placement: 'bottom',
75 onShow: function(tour) { that.edit_mode(); },
76 content: "Notice that the border around the currently active cell changed color. Typing will insert text into the currently active cell."
77 }, {
78 element: '.selected',
79 title: "Back to Command Mode",
80 placement: 'bottom',
81 onShow: function(tour) { notebook.command_mode(); },
82 onHide: function(tour) { $('#help_menu').parent().children('a').click(); },
83 content: "Pressing <code>Esc</code> or clicking outside of the input text area takes you back to Command Mode."
84 }, {
85 element: '#keyboard_shortcuts',
86 title: "Keyboard Shortcuts",
87 placement: 'bottom',
88 onHide: function(tour) { $('#help_menu').parent().children('a').click(); },
89 content: "You can click here to get a list of all of the keyboard shortcuts."
90 }, {
91 element: "#kernel_indicator",
92 title: "Kernel Indicator",
93 placement: 'bottom',
94 onShow: function(tour) { events.trigger('status_idle.Kernel');},
95 content: "This is the Kernel indicator. It looks like this when the Kernel is idle.",
96 }, {
97 element: "#kernel_indicator",
98 title: "Kernel Indicator",
99 placement: 'bottom',
100 onShow: function(tour) { events.trigger('status_busy.Kernel'); },
101 content: "The Kernel indicator looks like this when the Kernel is busy.",
102 }, {
103 element: ".icon-stop",
104 placement: 'bottom',
105 title: "Interrupting the Kernel",
106 onHide: function(tour) { events.trigger('status_idle.Kernel'); },
107 content: "To cancel a computation in progress, you can click here."
108 }, {
109 element: "#notification_kernel",
110 placement: 'bottom',
111 onShow: function(tour) { $('.icon-stop').click(); },
112 title: "Notification Area",
113 content: "Messages in response to user actions (Save, Interrupt, etc) appear here."
114 }, {
115 title: "Fin.",
116 placement: 'bottom',
117 orphan: true,
118 content: "This concludes the IPython Notebook User Interface tour.Tour. Happy hacking!",
119 }
120 ];
121
133 this.tour = new Tour({
122 this.tour = new Tour({
134 //orphan: true,
123 //orphan: true,
135 storage: false, // start tour from beginning every time
124 storage: false, // start tour from beginning every time
@@ -143,8 +132,8 b' IPython = (function (IPython) {'
143 // TODO: remove the onPause/onResume logic once pi's patch has been
132 // TODO: remove the onPause/onResume logic once pi's patch has been
144 // merged upstream to make this work via data-resume-class and
133 // merged upstream to make this work via data-resume-class and
145 // data-resume-text attributes.
134 // data-resume-text attributes.
146 onPause: toggle_pause_play,
135 onPause: this.toggle_pause_play,
147 onResume: toggle_pause_play,
136 onResume: this.toggle_pause_play,
148 steps: this.tour_steps,
137 steps: this.tour_steps,
149 template: tour_style,
138 template: tour_style,
150 orphan: true
139 orphan: true
@@ -162,9 +151,23 b' IPython = (function (IPython) {'
162 }
151 }
163 };
152 };
164
153
165 // Set module variables
154 NotebookTour.prototype.command_icon_hack = function() {
155 $('#modal_indicator').css('min-height', 20);
156 };
157
158 NotebookTour.prototype.toggle_pause_play = function () {
159 $('#tour-pause').toggleClass('icon-pause icon-play');
160 };
161
162 NotebookTour.prototype.edit_mode = function() {
163 this.notebook.focus_cell();
164 this.notebook.edit_mode();
165 };
166
167 // For backwards compatability.
166 IPython.NotebookTour = NotebookTour;
168 IPython.NotebookTour = NotebookTour;
167
169
168 return IPython;
170 return {'Tour': NotebookTour};
171
172 });
169
173
170 }(IPython));
@@ -1,21 +1,11 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Comm and CommManager bases
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11 /**
7 'base/js/utils',
12 * Base Comm classes
8 ], function(IPython, $, utils) {
13 * @module IPython
14 * @namespace IPython
15 * @submodule comm
16 */
17
18 var IPython = (function (IPython) {
19 "use strict";
9 "use strict";
20
10
21 //-----------------------------------------------------------------------
11 //-----------------------------------------------------------------------
@@ -125,7 +115,7 b' var IPython = (function (IPython) {'
125
115
126 var Comm = function (target_name, comm_id) {
116 var Comm = function (target_name, comm_id) {
127 this.target_name = target_name;
117 this.target_name = target_name;
128 this.comm_id = comm_id || IPython.utils.uuid();
118 this.comm_id = comm_id || utils.uuid();
129 this._msg_callback = this._close_callback = null;
119 this._msg_callback = this._close_callback = null;
130 };
120 };
131
121
@@ -189,10 +179,12 b' var IPython = (function (IPython) {'
189 this._maybe_callback('close', msg);
179 this._maybe_callback('close', msg);
190 };
180 };
191
181
182 // For backwards compatability.
192 IPython.CommManager = CommManager;
183 IPython.CommManager = CommManager;
193 IPython.Comm = Comm;
184 IPython.Comm = Comm;
194
195 return IPython;
196
197 }(IPython));
198
185
186 return {
187 'CommManager': CommManager,
188 'Comm': Comm
189 };
190 });
@@ -1,27 +1,22 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 //============================================================================
4 define([
5 // Kernel
5 'base/js/namespace',
6 //============================================================================
6 'jquery',
7
7 'base/js/utils',
8 /**
8 'services/kernels/js/comm',
9 * @module IPython
9 'widgets/js/init',
10 * @namespace IPython
10 ], function(IPython, $, utils, comm, widgetmanager) {
11 * @submodule Kernel
12 */
13
14 var IPython = (function (IPython) {
15 "use strict";
11 "use strict";
16
17 var utils = IPython.utils;
18
12
19 // Initialization and connection.
13 // Initialization and connection.
20 /**
14 /**
21 * A Kernel Class to communicate with the Python kernel
15 * A Kernel Class to communicate with the Python kernel
22 * @Class Kernel
16 * @Class Kernel
23 */
17 */
24 var Kernel = function (kernel_service_url) {
18 var Kernel = function (kernel_service_url, notebook) {
19 this.events = notebook.events;
25 this.kernel_id = null;
20 this.kernel_id = null;
26 this.shell_channel = null;
21 this.shell_channel = null;
27 this.iopub_channel = null;
22 this.iopub_channel = null;
@@ -43,8 +38,8 b' var IPython = (function (IPython) {'
43
38
44 this.bind_events();
39 this.bind_events();
45 this.init_iopub_handlers();
40 this.init_iopub_handlers();
46 this.comm_manager = new IPython.CommManager(this);
41 this.comm_manager = new comm.CommManager(this);
47 this.widget_manager = new IPython.WidgetManager(this.comm_manager);
42 this.widget_manager = new widgetmanager.WidgetManager(this.comm_manager, notebook);
48
43
49 this.last_msg_id = null;
44 this.last_msg_id = null;
50 this.last_msg_callbacks = {};
45 this.last_msg_callbacks = {};
@@ -69,7 +64,7 b' var IPython = (function (IPython) {'
69
64
70 Kernel.prototype.bind_events = function () {
65 Kernel.prototype.bind_events = function () {
71 var that = this;
66 var that = this;
72 $([IPython.events]).on('send_input_reply.Kernel', function(evt, data) {
67 this.events.on('send_input_reply.Kernel', function(evt, data) {
73 that.send_input_reply(data);
68 that.send_input_reply(data);
74 });
69 });
75 };
70 };
@@ -111,7 +106,7 b' var IPython = (function (IPython) {'
111 * @method restart
106 * @method restart
112 */
107 */
113 Kernel.prototype.restart = function () {
108 Kernel.prototype.restart = function () {
114 $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this});
109 this.events.trigger('status_restarting.Kernel', {kernel: this});
115 if (this.running) {
110 if (this.running) {
116 this.stop_channels();
111 this.stop_channels();
117 this.post(utils.url_join_encode(this.kernel_url, "restart"),
112 this.post(utils.url_join_encode(this.kernel_url, "restart"),
@@ -135,7 +130,7 b' var IPython = (function (IPython) {'
135
130
136 Kernel.prototype._websocket_closed = function(ws_url, early) {
131 Kernel.prototype._websocket_closed = function(ws_url, early) {
137 this.stop_channels();
132 this.stop_channels();
138 $([IPython.events]).trigger('websocket_closed.Kernel',
133 this.events.trigger('websocket_closed.Kernel',
139 {ws_url: ws_url, kernel: this, early: early}
134 {ws_url: ws_url, kernel: this, early: early}
140 );
135 );
141 };
136 };
@@ -215,7 +210,7 b' var IPython = (function (IPython) {'
215 if ( !channels[i].readyState ) return;
210 if ( !channels[i].readyState ) return;
216 }
211 }
217 // all events ready, trigger started event.
212 // all events ready, trigger started event.
218 $([IPython.events]).trigger('status_started.Kernel', {kernel: this});
213 this.events.trigger('status_started.Kernel', {kernel: this});
219 };
214 };
220
215
221 /**
216 /**
@@ -348,7 +343,7 b' var IPython = (function (IPython) {'
348 content.allow_stdin = true;
343 content.allow_stdin = true;
349 }
344 }
350 $.extend(true, content, options);
345 $.extend(true, content, options);
351 $([IPython.events]).trigger('execution_request.Kernel', {kernel: this, content:content});
346 this.events.trigger('execution_request.Kernel', {kernel: this, content:content});
352 return this.send_shell_message("execute_request", content, callbacks);
347 return this.send_shell_message("execute_request", content, callbacks);
353 };
348 };
354
349
@@ -380,7 +375,7 b' var IPython = (function (IPython) {'
380
375
381 Kernel.prototype.interrupt = function () {
376 Kernel.prototype.interrupt = function () {
382 if (this.running) {
377 if (this.running) {
383 $([IPython.events]).trigger('status_interrupting.Kernel', {kernel: this});
378 this.events.trigger('status_interrupting.Kernel', {kernel: this});
384 this.post(utils.url_join_encode(this.kernel_url, "interrupt"));
379 this.post(utils.url_join_encode(this.kernel_url, "interrupt"));
385 }
380 }
386 };
381 };
@@ -402,7 +397,7 b' var IPython = (function (IPython) {'
402 var content = {
397 var content = {
403 value : input,
398 value : input,
404 };
399 };
405 $([IPython.events]).trigger('input_reply.Kernel', {kernel: this, content:content});
400 this.events.trigger('input_reply.Kernel', {kernel: this, content:content});
406 var msg = this._get_msg("input_reply", content);
401 var msg = this._get_msg("input_reply", content);
407 this.stdin_channel.send(JSON.stringify(msg));
402 this.stdin_channel.send(JSON.stringify(msg));
408 return msg.header.msg_id;
403 return msg.header.msg_id;
@@ -482,7 +477,7 b' var IPython = (function (IPython) {'
482
477
483 Kernel.prototype._handle_shell_reply = function (e) {
478 Kernel.prototype._handle_shell_reply = function (e) {
484 var reply = $.parseJSON(e.data);
479 var reply = $.parseJSON(e.data);
485 $([IPython.events]).trigger('shell_reply.Kernel', {kernel: this, reply:reply});
480 this.events.trigger('shell_reply.Kernel', {kernel: this, reply:reply});
486 var content = reply.content;
481 var content = reply.content;
487 var metadata = reply.metadata;
482 var metadata = reply.metadata;
488 var parent_id = reply.parent_header.msg_id;
483 var parent_id = reply.parent_header.msg_id;
@@ -532,7 +527,7 b' var IPython = (function (IPython) {'
532 }
527 }
533
528
534 if (execution_state === 'busy') {
529 if (execution_state === 'busy') {
535 $([IPython.events]).trigger('status_busy.Kernel', {kernel: this});
530 this.events.trigger('status_busy.Kernel', {kernel: this});
536 } else if (execution_state === 'idle') {
531 } else if (execution_state === 'idle') {
537 // signal that iopub callbacks are (probably) done
532 // signal that iopub callbacks are (probably) done
538 // async output may still arrive,
533 // async output may still arrive,
@@ -540,17 +535,17 b' var IPython = (function (IPython) {'
540 this._finish_iopub(parent_id);
535 this._finish_iopub(parent_id);
541
536
542 // trigger status_idle event
537 // trigger status_idle event
543 $([IPython.events]).trigger('status_idle.Kernel', {kernel: this});
538 this.events.trigger('status_idle.Kernel', {kernel: this});
544 } else if (execution_state === 'restarting') {
539 } else if (execution_state === 'restarting') {
545 // autorestarting is distinct from restarting,
540 // autorestarting is distinct from restarting,
546 // in that it means the kernel died and the server is restarting it.
541 // in that it means the kernel died and the server is restarting it.
547 // status_restarting sets the notification widget,
542 // status_restarting sets the notification widget,
548 // autorestart shows the more prominent dialog.
543 // autorestart shows the more prominent dialog.
549 $([IPython.events]).trigger('status_autorestarting.Kernel', {kernel: this});
544 this.events.trigger('status_autorestarting.Kernel', {kernel: this});
550 $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this});
545 this.events.trigger('status_restarting.Kernel', {kernel: this});
551 } else if (execution_state === 'dead') {
546 } else if (execution_state === 'dead') {
552 this.stop_channels();
547 this.stop_channels();
553 $([IPython.events]).trigger('status_dead.Kernel', {kernel: this});
548 this.events.trigger('status_dead.Kernel', {kernel: this});
554 }
549 }
555 };
550 };
556
551
@@ -610,10 +605,8 b' var IPython = (function (IPython) {'
610 }
605 }
611 };
606 };
612
607
613
608 // Backwards compatability.
614 IPython.Kernel = Kernel;
609 IPython.Kernel = Kernel;
615
610
616 return IPython;
611 return {'Kernel': Kernel};
617
612 });
618 }(IPython));
619
@@ -1,26 +1,21 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Notebook
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11
7 'base/js/utils',
12 var IPython = (function (IPython) {
8 'services/kernels/js/kernel',
9 ], function(IPython, $, utils, kernel) {
13 "use strict";
10 "use strict";
14
11
15 var utils = IPython.utils;
12 var Session = function(options){
16
17 var Session = function(notebook, options){
18 this.kernel = null;
13 this.kernel = null;
19 this.id = null;
14 this.id = null;
20 this.notebook = notebook;
15 this.notebook = options.notebook;
21 this.name = notebook.notebook_name;
16 this.name = options.notebook_name;
22 this.path = notebook.notebook_path;
17 this.path = options.notebook_path;
23 this.base_url = notebook.base_url;
18 this.base_url = options.base_url;
24 };
19 };
25
20
26 Session.prototype.start = function(callback) {
21 Session.prototype.start = function(callback) {
@@ -92,7 +87,7 b' var IPython = (function (IPython) {'
92 Session.prototype._handle_start_success = function (data, status, xhr) {
87 Session.prototype._handle_start_success = function (data, status, xhr) {
93 this.id = data.id;
88 this.id = data.id;
94 var kernel_service_url = utils.url_path_join(this.base_url, "api/kernels");
89 var kernel_service_url = utils.url_path_join(this.base_url, "api/kernels");
95 this.kernel = new IPython.Kernel(kernel_service_url);
90 this.kernel = new kernel.Kernel(kernel_service_url, this.notebook);
96 this.kernel._kernel_started(data.kernel);
91 this.kernel._kernel_started(data.kernel);
97 };
92 };
98
93
@@ -114,8 +109,8 b' var IPython = (function (IPython) {'
114 this.kernel.kill();
109 this.kernel.kill();
115 };
110 };
116
111
112 // For backwards compatability.
117 IPython.Session = Session;
113 IPython.Session = Session;
118
114
119 return IPython;
115 return {'Session': Session};
120
116 });
121 }(IPython));
@@ -1,18 +1,12 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'base/js/utils',
8 //============================================================================
8 ], function(IPython, $, utils) {
9 // NotebookList
10 //============================================================================
11
12 var IPython = (function (IPython) {
13 "use strict";
9 "use strict";
14
15 var utils = IPython.utils;
16
10
17 var ClusterList = function (selector, options) {
11 var ClusterList = function (selector, options) {
18 this.selector = selector;
12 this.selector = selector;
@@ -188,11 +182,12 b' var IPython = (function (IPython) {'
188 });
182 });
189 };
183 };
190
184
191
185 // For backwards compatability.
192 IPython.ClusterList = ClusterList;
186 IPython.ClusterList = ClusterList;
193 IPython.ClusterItem = ClusterItem;
187 IPython.ClusterItem = ClusterItem;
194
188
195 return IPython;
189 return {
196
190 'ClusterList': ClusterList,
197 }(IPython));
191 'ClusterItem': ClusterItem,
198
192 };
193 });
@@ -1,24 +1,29 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2014 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'tree/js/notebooklist',
8 //============================================================================
8 ], function(IPython, $, notebooklist) {
9 // Running Kernels List
10 //============================================================================
11
12 var IPython = (function (IPython) {
13 "use strict";
9 "use strict";
14
10
15 var utils = IPython.utils;
16
17 var KernelList = function (selector, options) {
11 var KernelList = function (selector, options) {
18 IPython.NotebookList.call(this, selector, options, 'running');
12 // Constructor
13 //
14 // Parameters:
15 // selector: string
16 // options: dictionary
17 // Dictionary of keyword arguments.
18 // session_list: SessionList instance
19 // base_url: string
20 // notebook_path: string
21 notebooklist.NotebookList.call(this, selector, $.extend({
22 element_name: 'running'},
23 options));
19 };
24 };
20
25
21 KernelList.prototype = Object.create(IPython.NotebookList.prototype);
26 KernelList.prototype = Object.create(notebooklist.NotebookList.prototype);
22
27
23 KernelList.prototype.sessions_loaded = function (d) {
28 KernelList.prototype.sessions_loaded = function (d) {
24 this.sessions = d;
29 this.sessions = d;
@@ -31,10 +36,10 b' var IPython = (function (IPython) {'
31 }
36 }
32
37
33 $('#running_list_header').toggle($.isEmptyObject(d));
38 $('#running_list_header').toggle($.isEmptyObject(d));
34 }
39 };
35
40
41 // Backwards compatability.
36 IPython.KernelList = KernelList;
42 IPython.KernelList = KernelList;
37
43
38 return IPython;
44 return {'KernelList': KernelList};
39
45 });
40 }(IPython));
@@ -1,32 +1,53 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 require([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'base/js/events',
8 //============================================================================
8 'base/js/page',
9 // On document ready
9 'base/js/utils',
10 //============================================================================
10 'tree/js/notebooklist',
11
11 'tree/js/clusterlist',
12
12 'tree/js/sessionlist',
13 $(document).ready(function () {
13 'tree/js/kernellist',
14
14 'auth/js/loginwidget',
15 IPython.page = new IPython.Page();
15 'components/jquery-ui/ui/minified/jquery-ui.min',
16 'components/bootstrap/js/bootstrap.min',
17 ], function(
18 IPython,
19 $,
20 events,
21 page,
22 utils,
23 notebooklist,
24 clusterlist,
25 sesssionlist,
26 kernellist,
27 loginwidget){
28
29 page = new page.Page();
30
31 var common_options = {
32 base_url: utils.get_body_data("baseUrl"),
33 notebook_path: utils.get_body_data("notebookPath"),
34 };
35 events = $([new events.Events()]);
36 session_list = new sesssionlist.SesssionList($.extend({
37 events: events},
38 common_options));
39 notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
40 session_list: session_list},
41 common_options));
42 cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
43 kernel_list = new kernellist.KernelList('#running_list', $.extend({
44 session_list: session_list},
45 common_options));
46 login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
16
47
17 $('#new_notebook').button().click(function (e) {
48 $('#new_notebook').button().click(function (e) {
18 IPython.notebook_list.new_notebook()
49 notebook_list.new_notebook();
19 });
50 });
20
21 var opts = {
22 base_url : IPython.utils.get_body_data("baseUrl"),
23 notebook_path : IPython.utils.get_body_data("notebookPath"),
24 };
25 IPython.session_list = new IPython.SesssionList(opts);
26 IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts);
27 IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts);
28 IPython.kernel_list = new IPython.KernelList('#running_list', opts);
29 IPython.login_widget = new IPython.LoginWidget('#login_widget', opts);
30
51
31 var interval_id=0;
52 var interval_id=0;
32 // auto refresh every xx secondes, no need to be fast,
53 // auto refresh every xx secondes, no need to be fast,
@@ -35,31 +56,31 b' $(document).ready(function () {'
35
56
36 var enable_autorefresh = function(){
57 var enable_autorefresh = function(){
37 //refresh immediately , then start interval
58 //refresh immediately , then start interval
38 if($('.upload_button').length == 0)
59 if($('.upload_button').length === 0)
39 {
60 {
40 IPython.session_list.load_sessions();
61 session_list.load_sessions();
41 IPython.cluster_list.load_list();
62 cluster_list.load_list();
42 }
63 }
43 if (!interval_id){
64 if (!interval_id){
44 interval_id = setInterval(function(){
65 interval_id = setInterval(function(){
45 if($('.upload_button').length == 0)
66 if($('.upload_button').length === 0)
46 {
67 {
47 IPython.session_list.load_sessions();
68 session_list.load_sessions();
48 IPython.cluster_list.load_list();
69 cluster_list.load_list();
49 }
70 }
50 }, time_refresh*1000);
71 }, time_refresh*1000);
51 }
72 }
52 }
73 };
53
74
54 var disable_autorefresh = function(){
75 var disable_autorefresh = function(){
55 clearInterval(interval_id);
76 clearInterval(interval_id);
56 interval_id = 0;
77 interval_id = 0;
57 }
78 };
58
79
59 // stop autorefresh when page lose focus
80 // stop autorefresh when page lose focus
60 $(window).blur(function() {
81 $(window).blur(function() {
61 disable_autorefresh();
82 disable_autorefresh();
62 })
83 });
63
84
64 //re-enable when page get focus back
85 //re-enable when page get focus back
65 $(window).focus(function() {
86 $(window).focus(function() {
@@ -69,24 +90,30 b' $(document).ready(function () {'
69 // finally start it, it will refresh immediately
90 // finally start it, it will refresh immediately
70 enable_autorefresh();
91 enable_autorefresh();
71
92
72 IPython.page.show();
93 page.show();
73 $([IPython.events]).trigger('app_initialized.DashboardApp');
94 events.trigger('app_initialized.DashboardApp');
74
95
75 // bound the upload method to the on change of the file select list
96 // bound the upload method to the on change of the file select list
76 $("#alternate_upload").change(function (event){
97 $("#alternate_upload").change(function (event){
77 IPython.notebook_list.handleFilesUpload(event,'form');
98 notebook_list.handleFilesUpload(event,'form');
78 });
99 });
79
100
80 // set hash on tab click
101 // set hash on tab click
81 $("#tabs").find("a").click(function() {
102 $("#tabs").find("a").click(function() {
82 window.location.hash = $(this).attr("href");
103 window.location.hash = $(this).attr("href");
83 })
104 });
84
105
85 // load tab if url hash
106 // load tab if url hash
86 if (window.location.hash) {
107 if (window.location.hash) {
87 $("#tabs").find("a[href=" + window.location.hash + "]").click();
108 $("#tabs").find("a[href=" + window.location.hash + "]").click();
88 }
109 }
89
110
90
111 // For backwards compatability.
112 IPython.page = page;
113 IPython.notebook_list = notebook_list;
114 IPython.cluster_list = cluster_list;
115 IPython.session_list = session_list;
116 IPython.kernel_list = kernel_list;
117 IPython.login_widget = login_widget;
118 IPython.events = events;
91 });
119 });
92
@@ -1,23 +1,29 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 'base/js/namespace',
6 //----------------------------------------------------------------------------
6 'jquery',
7
7 'base/js/utils',
8 //============================================================================
8 'base/js/dialog',
9 // NotebookList
9 ], function(IPython, $, utils, dialog) {
10 //============================================================================
11
12 var IPython = (function (IPython) {
13 "use strict";
10 "use strict";
14
11
15 var utils = IPython.utils;
12 var NotebookList = function (selector, options) {
16
13 // Constructor
17 var NotebookList = function (selector, options, element_name) {
14 //
18 var that = this
15 // Parameters:
16 // selector: string
17 // options: dictionary
18 // Dictionary of keyword arguments.
19 // session_list: SessionList instance
20 // element_name: string
21 // base_url: string
22 // notebook_path: string
23 var that = this;
24 this.session_list = options.session_list;
19 // allow code re-use by just changing element_name in kernellist.js
25 // allow code re-use by just changing element_name in kernellist.js
20 this.element_name = element_name || 'notebook';
26 this.element_name = options.element_name || 'notebook';
21 this.selector = selector;
27 this.selector = selector;
22 if (this.selector !== undefined) {
28 if (this.selector !== undefined) {
23 this.element = $(selector);
29 this.element = $(selector);
@@ -28,12 +34,14 b' var IPython = (function (IPython) {'
28 this.sessions = {};
34 this.sessions = {};
29 this.base_url = options.base_url || utils.get_body_data("baseUrl");
35 this.base_url = options.base_url || utils.get_body_data("baseUrl");
30 this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath");
36 this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath");
31 $([IPython.events]).on('sessions_loaded.Dashboard',
37 if (this.session_list && this.session_list.events) {
32 function(e, d) { that.sessions_loaded(d); });
38 this.session_list.events.on('sessions_loaded.Dashboard',
39 function(e, d) { that.sessions_loaded(d); });
40 }
33 };
41 };
34
42
35 NotebookList.prototype.style = function () {
43 NotebookList.prototype.style = function () {
36 var prefix = '#' + this.element_name
44 var prefix = '#' + this.element_name;
37 $(prefix + '_toolbar').addClass('list_toolbar');
45 $(prefix + '_toolbar').addClass('list_toolbar');
38 $(prefix + '_list_info').addClass('toolbar_info');
46 $(prefix + '_list_info').addClass('toolbar_info');
39 $(prefix + '_buttons').addClass('toolbar_buttons');
47 $(prefix + '_buttons').addClass('toolbar_buttons');
@@ -84,10 +92,10 b' var IPython = (function (IPython) {'
84 that.add_upload_button(nbitem);
92 that.add_upload_button(nbitem);
85 };
93 };
86 } else {
94 } else {
87 var dialog = 'Uploaded notebooks must be .ipynb files';
95 var dialog_body = 'Uploaded notebooks must be .ipynb files';
88 IPython.dialog.modal({
96 dialog.modal({
89 title : 'Invalid file type',
97 title : 'Invalid file type',
90 body : dialog,
98 body : dialog_body,
91 buttons : {'OK' : {'class' : 'btn-primary'}}
99 buttons : {'OK' : {'class' : 'btn-primary'}}
92 });
100 });
93 }
101 }
@@ -114,7 +122,7 b' var IPython = (function (IPython) {'
114 };
122 };
115
123
116 NotebookList.prototype.load_sessions = function(){
124 NotebookList.prototype.load_sessions = function(){
117 IPython.session_list.load_sessions();
125 this.session_list.load_sessions();
118 };
126 };
119
127
120
128
@@ -301,7 +309,7 b' var IPython = (function (IPython) {'
301 var parent_item = that.parents('div.list_item');
309 var parent_item = that.parents('div.list_item');
302 var nbname = parent_item.data('nbname');
310 var nbname = parent_item.data('nbname');
303 var message = 'Are you sure you want to permanently delete the notebook: ' + nbname + '?';
311 var message = 'Are you sure you want to permanently delete the notebook: ' + nbname + '?';
304 IPython.dialog.modal({
312 dialog.modal({
305 title : "Delete notebook",
313 title : "Delete notebook",
306 body : message,
314 body : message,
307 buttons : {
315 buttons : {
@@ -426,16 +434,15 b' var IPython = (function (IPython) {'
426 } else {
434 } else {
427 msg = xhr.statusText;
435 msg = xhr.statusText;
428 }
436 }
429 IPython.dialog.modal({
437 dialog.modal({
430 title : 'Creating Notebook Failed',
438 title : 'Creating Notebook Failed',
431 body : "The error was: " + msg,
439 body : "The error was: " + msg,
432 buttons : {'OK' : {'class' : 'btn-primary'}}
440 buttons : {'OK' : {'class' : 'btn-primary'}}
433 });
441 });
434 }
442 };
435
436
443
444 // Backwards compatability.
437 IPython.NotebookList = NotebookList;
445 IPython.NotebookList = NotebookList;
438
446
439 return IPython;
447 return {'NotebookList': NotebookList};
440
448 });
441 }(IPython));
@@ -1,20 +1,22 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2014 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // Running Kernels List
5 'base/js/namespace',
10 //============================================================================
6 'jquery',
11
7 'base/js/utils',
12 var IPython = (function (IPython) {
8 ], function(IPython, $, utils) {
13 "use strict";
9 "use strict";
14
10
15 var utils = IPython.utils;
16
17 var SesssionList = function (options) {
11 var SesssionList = function (options) {
12 // Constructor
13 //
14 // Parameters:
15 // options: dictionary
16 // Dictionary of keyword arguments.
17 // events: $(Events) instance
18 // base_url : string
19 this.events = options.events;
18 this.sessions = {};
20 this.sessions = {};
19 this.base_url = options.base_url || utils.get_body_data("baseUrl");
21 this.base_url = options.base_url || utils.get_body_data("baseUrl");
20 };
22 };
@@ -44,10 +46,11 b' var IPython = (function (IPython) {'
44 );
46 );
45 this.sessions[nb_path] = data[i].id;
47 this.sessions[nb_path] = data[i].id;
46 }
48 }
47 $([IPython.events]).trigger('sessions_loaded.Dashboard', this.sessions);
49 this.events.trigger('sessions_loaded.Dashboard', this.sessions);
48 };
50 };
49 IPython.SesssionList = SesssionList;
50
51
51 return IPython;
52 // Backwards compatability.
53 IPython.SesssionList = SesssionList;
52
54
53 }(IPython));
55 return {'SesssionList': SesssionList};
56 });
@@ -1,15 +1,8 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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 // Basic Widgets
10 //============================================================================
11
3
12 define([
4 define([
5 "widgets/js/manager",
13 "widgets/js/widget_bool",
6 "widgets/js/widget_bool",
14 "widgets/js/widget_button",
7 "widgets/js/widget_button",
15 "widgets/js/widget_container",
8 "widgets/js/widget_container",
@@ -19,4 +12,16 b' define(['
19 "widgets/js/widget_selection",
12 "widgets/js/widget_selection",
20 "widgets/js/widget_selectioncontainer",
13 "widgets/js/widget_selectioncontainer",
21 "widgets/js/widget_string",
14 "widgets/js/widget_string",
22 ], function(){ return true; });
15 ], function(widgetmanager) {
16
17 // Register all of the loaded views with the widget manager.
18 for (var i = 1; i < arguments.length; i++) {
19 for (var target_name in arguments[i]) {
20 if (arguments[i].hasOwnProperty(target_name)) {
21 widgetmanager.WidgetManager.register_widget_view(target_name, arguments[i][target_name]);
22 }
23 }
24 }
25
26 return {'WidgetManager': widgetmanager.WidgetManager};
27 });
@@ -1,214 +1,201 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
3
4 // Distributed under the terms of the BSD License. The full license is in
4 define([
5 // the file COPYING, distributed as part of this software.
5 "underscore",
6 //----------------------------------------------------------------------------
6 "backbone",
7
7 "base/js/namespace"
8 //============================================================================
8 ], function (_, Backbone, IPython) {
9 // WidgetModel, WidgetView, and WidgetManager
9
10 //============================================================================
10 //--------------------------------------------------------------------
11 /**
11 // WidgetManager class
12 * Base Widget classes
12 //--------------------------------------------------------------------
13 * @module IPython
13 var WidgetManager = function (comm_manager, notebook) {
14 * @namespace IPython
14 // Public constructor
15 * @submodule widget
15 WidgetManager._managers.push(this);
16 */
16
17
17 // Attach a comm manager to the
18 (function () {
18 this.keyboard_manager = notebook.keyboard_manager;
19 "use strict";
19 this.notebook = notebook;
20
20 this.comm_manager = comm_manager;
21 // Use require.js 'define' method so that require.js is intelligent enough to
21 this._models = {}; /* Dictionary of model ids and model instances */
22 // syncronously load everything within this file when it is being 'required'
22
23 // elsewhere.
23 // Register already-registered widget model types with the comm manager.
24 define(["underscore",
24 var that = this;
25 "backbone",
25 _.each(WidgetManager._model_types, function(model_type, model_name) {
26 ], function (_, Backbone) {
26 that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that));
27
27 });
28 //--------------------------------------------------------------------
28 };
29 // WidgetManager class
29
30 //--------------------------------------------------------------------
30 //--------------------------------------------------------------------
31 var WidgetManager = function (comm_manager) {
31 // Class level
32 // Public constructor
32 //--------------------------------------------------------------------
33 WidgetManager._managers.push(this);
33 WidgetManager._model_types = {}; /* Dictionary of model type names (target_name) and model types. */
34
34 WidgetManager._view_types = {}; /* Dictionary of view names and view types. */
35 // Attach a comm manager to the
35 WidgetManager._managers = []; /* List of widget managers */
36 this.comm_manager = comm_manager;
36
37 this._models = {}; /* Dictionary of model ids and model instances */
37 WidgetManager.register_widget_model = function (model_name, model_type) {
38
38 // Registers a widget model by name.
39 // Register already-registered widget model types with the comm manager.
39 WidgetManager._model_types[model_name] = model_type;
40 var that = this;
40
41 _.each(WidgetManager._model_types, function(model_type, model_name) {
41 // Register the widget with the comm manager. Make sure to pass this object's context
42 that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that));
42 // in so `this` works in the call back.
43 });
43 _.each(WidgetManager._managers, function(instance, i) {
44 };
44 if (instance.comm_manager !== null) {
45
45 instance.comm_manager.register_target(model_name, $.proxy(instance._handle_comm_open, instance));
46 //--------------------------------------------------------------------
47 // Class level
48 //--------------------------------------------------------------------
49 WidgetManager._model_types = {}; /* Dictionary of model type names (target_name) and model types. */
50 WidgetManager._view_types = {}; /* Dictionary of view names and view types. */
51 WidgetManager._managers = []; /* List of widget managers */
52
53 WidgetManager.register_widget_model = function (model_name, model_type) {
54 // Registers a widget model by name.
55 WidgetManager._model_types[model_name] = model_type;
56
57 // Register the widget with the comm manager. Make sure to pass this object's context
58 // in so `this` works in the call back.
59 _.each(WidgetManager._managers, function(instance, i) {
60 if (instance.comm_manager !== null) {
61 instance.comm_manager.register_target(model_name, $.proxy(instance._handle_comm_open, instance));
62 }
63 });
64 };
65
66 WidgetManager.register_widget_view = function (view_name, view_type) {
67 // Registers a widget view by name.
68 WidgetManager._view_types[view_name] = view_type;
69 };
70
71 //--------------------------------------------------------------------
72 // Instance level
73 //--------------------------------------------------------------------
74 WidgetManager.prototype.display_view = function(msg, model) {
75 // Displays a view for a particular model.
76 var cell = this.get_msg_cell(msg.parent_header.msg_id);
77 if (cell === null) {
78 console.log("Could not determine where the display" +
79 " message was from. Widget will not be displayed");
80 } else {
81 var view = this.create_view(model, {cell: cell});
82 if (view === null) {
83 console.error("View creation failed", model);
84 }
85 if (cell.widget_subarea) {
86 cell.widget_area.show();
87 this._handle_display_view(view);
88 cell.widget_subarea.append(view.$el);
89 view.trigger('displayed');
90 }
91 }
46 }
92 };
47 });
93
48 };
94 WidgetManager.prototype._handle_display_view = function (view) {
49
95 // Have the IPython keyboard manager disable its event
50 WidgetManager.register_widget_view = function (view_name, view_type) {
96 // handling so the widget can capture keyboard input.
51 // Registers a widget view by name.
97 // Note, this is only done on the outer most widgets.
52 WidgetManager._view_types[view_name] = view_type;
98 IPython.keyboard_manager.register_events(view.$el);
53 };
99
54
100 if (view.additional_elements) {
55 //--------------------------------------------------------------------
101 for (var i = 0; i < view.additional_elements.length; i++) {
56 // Instance level
102 IPython.keyboard_manager.register_events(view.additional_elements[i]);
57 //--------------------------------------------------------------------
103 }
58 WidgetManager.prototype.display_view = function(msg, model) {
104 }
59 // Displays a view for a particular model.
105 };
60 var cell = this.get_msg_cell(msg.parent_header.msg_id);
106
61 if (cell === null) {
107 WidgetManager.prototype.create_view = function(model, options, view) {
62 console.log("Could not determine where the display" +
108 // Creates a view for a particular model.
63 " message was from. Widget will not be displayed");
109 var view_name = model.get('_view_name');
64 } else {
110 var ViewType = WidgetManager._view_types[view_name];
65 var view = this.create_view(model, {cell: cell});
111 if (ViewType) {
66 if (view === null) {
112
67 console.error("View creation failed", model);
113 // If a view is passed into the method, use that view's cell as
114 // the cell for the view that is created.
115 options = options || {};
116 if (view !== undefined) {
117 options.cell = view.options.cell;
118 }
119
120 // Create and render the view...
121 var parameters = {model: model, options: options};
122 view = new ViewType(parameters);
123 view.render();
124 model.on('destroy', view.remove, view);
125 return view;
126 }
68 }
127 return null;
69 if (cell.widget_subarea) {
128 };
70 cell.widget_area.show();
129
71 this._handle_display_view(view);
130 WidgetManager.prototype.get_msg_cell = function (msg_id) {
72 cell.widget_subarea.append(view.$el);
131 var cell = null;
73 view.trigger('displayed');
132 // First, check to see if the msg was triggered by cell execution.
133 if (IPython.notebook) {
134 cell = IPython.notebook.get_msg_cell(msg_id);
135 }
74 }
136 if (cell !== null) {
75 }
137 return cell;
76 };
77
78 WidgetManager.prototype._handle_display_view = function (view) {
79 // Have the IPython keyboard manager disable its event
80 // handling so the widget can capture keyboard input.
81 // Note, this is only done on the outer most widgets.
82 if (this.keyboard_manager) {
83 this.keyboard_manager.register_events(view.$el);
84
85 if (view.additional_elements) {
86 for (var i = 0; i < view.additional_elements.length; i++) {
87 this.keyboard_manager.register_events(view.additional_elements[i]);
138 }
88 }
139 // Second, check to see if a get_cell callback was defined
89 }
140 // for the message. get_cell callbacks are registered for
90 }
141 // widget messages, so this block is actually checking to see if the
91 };
142 // message was triggered by a widget.
92
143 var kernel = this.comm_manager.kernel;
93 WidgetManager.prototype.create_view = function(model, options, view) {
144 if (kernel) {
94 // Creates a view for a particular model.
145 var callbacks = kernel.get_callbacks_for_msg(msg_id);
95 var view_name = model.get('_view_name');
146 if (callbacks && callbacks.iopub &&
96 var ViewType = WidgetManager._view_types[view_name];
147 callbacks.iopub.get_cell !== undefined) {
97 if (ViewType) {
148 return callbacks.iopub.get_cell();
98
149 }
99 // If a view is passed into the method, use that view's cell as
100 // the cell for the view that is created.
101 options = options || {};
102 if (view !== undefined) {
103 options.cell = view.options.cell;
150 }
104 }
151
105
152 // Not triggered by a cell or widget (no get_cell callback
106 // Create and render the view...
153 // exists).
107 var parameters = {model: model, options: options};
154 return null;
108 view = new ViewType(parameters);
155 };
109 view.render();
156
110 model.on('destroy', view.remove, view);
157 WidgetManager.prototype.callbacks = function (view) {
111 return view;
158 // callback handlers specific a view
112 }
159 var callbacks = {};
113 return null;
160 if (view && view.options.cell) {
114 };
161
115
162 // Try to get output handlers
116 WidgetManager.prototype.get_msg_cell = function (msg_id) {
163 var cell = view.options.cell;
117 var cell = null;
164 var handle_output = null;
118 // First, check to see if the msg was triggered by cell execution.
165 var handle_clear_output = null;
119 if (this.notebook) {
166 if (cell.output_area) {
120 cell = this.notebook.get_msg_cell(msg_id);
167 handle_output = $.proxy(cell.output_area.handle_output, cell.output_area);
121 }
168 handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area);
122 if (cell !== null) {
169 }
123 return cell;
170
124 }
171 // Create callback dict using what is known
125 // Second, check to see if a get_cell callback was defined
172 var that = this;
126 // for the message. get_cell callbacks are registered for
173 callbacks = {
127 // widget messages, so this block is actually checking to see if the
174 iopub : {
128 // message was triggered by a widget.
175 output : handle_output,
129 var kernel = this.comm_manager.kernel;
176 clear_output : handle_clear_output,
130 if (kernel) {
177
131 var callbacks = kernel.get_callbacks_for_msg(msg_id);
178 // Special function only registered by widget messages.
132 if (callbacks && callbacks.iopub &&
179 // Allows us to get the cell for a message so we know
133 callbacks.iopub.get_cell !== undefined) {
180 // where to add widgets if the code requires it.
134 return callbacks.iopub.get_cell();
181 get_cell : function () {
182 return cell;
183 },
184 },
185 };
186 }
135 }
187 return callbacks;
136 }
188 };
137
189
138 // Not triggered by a cell or widget (no get_cell callback
190 WidgetManager.prototype.get_model = function (model_id) {
139 // exists).
191 // Look-up a model instance by its id.
140 return null;
192 var model = this._models[model_id];
141 };
193 if (model !== undefined && model.id == model_id) {
142
194 return model;
143 WidgetManager.prototype.callbacks = function (view) {
144 // callback handlers specific a view
145 var callbacks = {};
146 if (view && view.options.cell) {
147
148 // Try to get output handlers
149 var cell = view.options.cell;
150 var handle_output = null;
151 var handle_clear_output = null;
152 if (cell.output_area) {
153 handle_output = $.proxy(cell.output_area.handle_output, cell.output_area);
154 handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area);
195 }
155 }
196 return null;
197 };
198
156
199 WidgetManager.prototype._handle_comm_open = function (comm, msg) {
157 // Create callback dict using what is known
200 // Handle when a comm is opened.
201 var that = this;
158 var that = this;
202 var model_id = comm.comm_id;
159 callbacks = {
203 var widget_type_name = msg.content.target_name;
160 iopub : {
204 var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm);
161 output : handle_output,
205 widget_model.on('comm:close', function () {
162 clear_output : handle_clear_output,
206 delete that._models[model_id];
163
207 });
164 // Special function only registered by widget messages.
208 this._models[model_id] = widget_model;
165 // Allows us to get the cell for a message so we know
209 };
166 // where to add widgets if the code requires it.
210
167 get_cell : function () {
211 IPython.WidgetManager = WidgetManager;
168 return cell;
212 return IPython.WidgetManager;
169 },
213 });
170 },
214 }());
171 };
172 }
173 return callbacks;
174 };
175
176 WidgetManager.prototype.get_model = function (model_id) {
177 // Look-up a model instance by its id.
178 var model = this._models[model_id];
179 if (model !== undefined && model.id == model_id) {
180 return model;
181 }
182 return null;
183 };
184
185 WidgetManager.prototype._handle_comm_open = function (comm, msg) {
186 // Handle when a comm is opened.
187 var that = this;
188 var model_id = comm.comm_id;
189 var widget_type_name = msg.content.target_name;
190 var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm);
191 widget_model.on('comm:close', function () {
192 delete that._models[model_id];
193 });
194 this._models[model_id] = widget_model;
195 };
196
197 // Backwards compatability.
198 IPython.WidgetManager = WidgetManager;
199
200 return {'WidgetManager': WidgetManager};
201 });
@@ -1,23 +1,12 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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 // Base Widget Model and View classes
10 //============================================================================
11
12 /**
13 * @module IPython
14 * @namespace IPython
15 **/
16
3
17 define(["widgets/js/manager",
4 define(["widgets/js/manager",
18 "underscore",
5 "underscore",
19 "backbone"],
6 "backbone",
20 function(WidgetManager, _, Backbone){
7 "jquery",
8 "base/js/namespace",
9 ], function(widgetmanager, _, Backbone, $, IPython){
21
10
22 var WidgetModel = Backbone.Model.extend({
11 var WidgetModel = Backbone.Model.extend({
23 constructor: function (widget_manager, model_id, comm) {
12 constructor: function (widget_manager, model_id, comm) {
@@ -221,20 +210,20 b' function(WidgetManager, _, Backbone){'
221
210
222 _pack_models: function(value) {
211 _pack_models: function(value) {
223 // Replace models with model ids recursively.
212 // Replace models with model ids recursively.
213 var that = this;
214 var packed;
224 if (value instanceof Backbone.Model) {
215 if (value instanceof Backbone.Model) {
225 return value.id;
216 return value.id;
226
217
227 } else if ($.isArray(value)) {
218 } else if ($.isArray(value)) {
228 var packed = [];
219 packed = [];
229 var that = this;
230 _.each(value, function(sub_value, key) {
220 _.each(value, function(sub_value, key) {
231 packed.push(that._pack_models(sub_value));
221 packed.push(that._pack_models(sub_value));
232 });
222 });
233 return packed;
223 return packed;
234
224
235 } else if (value instanceof Object) {
225 } else if (value instanceof Object) {
236 var packed = {};
226 packed = {};
237 var that = this;
238 _.each(value, function(sub_value, key) {
227 _.each(value, function(sub_value, key) {
239 packed[key] = that._pack_models(sub_value);
228 packed[key] = that._pack_models(sub_value);
240 });
229 });
@@ -247,17 +236,17 b' function(WidgetManager, _, Backbone){'
247
236
248 _unpack_models: function(value) {
237 _unpack_models: function(value) {
249 // Replace model ids with models recursively.
238 // Replace model ids with models recursively.
239 var that = this;
240 var unpacked;
250 if ($.isArray(value)) {
241 if ($.isArray(value)) {
251 var unpacked = [];
242 unpacked = [];
252 var that = this;
253 _.each(value, function(sub_value, key) {
243 _.each(value, function(sub_value, key) {
254 unpacked.push(that._unpack_models(sub_value));
244 unpacked.push(that._unpack_models(sub_value));
255 });
245 });
256 return unpacked;
246 return unpacked;
257
247
258 } else if (value instanceof Object) {
248 } else if (value instanceof Object) {
259 var unpacked = {};
249 unpacked = {};
260 var that = this;
261 _.each(value, function(sub_value, key) {
250 _.each(value, function(sub_value, key) {
262 unpacked[key] = that._unpack_models(sub_value);
251 unpacked[key] = that._unpack_models(sub_value);
263 });
252 });
@@ -274,7 +263,7 b' function(WidgetManager, _, Backbone){'
274 },
263 },
275
264
276 });
265 });
277 WidgetManager.register_widget_model('WidgetModel', WidgetModel);
266 widgetmanager.WidgetManager.register_widget_model('WidgetModel', WidgetModel);
278
267
279
268
280 var WidgetView = Backbone.View.extend({
269 var WidgetView = Backbone.View.extend({
@@ -471,10 +460,14 b' function(WidgetManager, _, Backbone){'
471 },
460 },
472 });
461 });
473
462
474 IPython.WidgetModel = WidgetModel;
463 var widget = {
475 IPython.WidgetView = WidgetView;
464 'WidgetModel': WidgetModel,
476 IPython.DOMWidgetView = DOMWidgetView;
465 'WidgetView': WidgetView,
466 'DOMWidgetView': DOMWidgetView,
467 };
468
469 // For backwards compatability.
470 $.extend(IPython, widget);
477
471
478 // Pass through WidgetManager namespace.
472 return widget;
479 return WidgetManager;
480 });
473 });
@@ -1,22 +1,13 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // BoolWidget
5 "widgets/js/widget",
10 //============================================================================
6 "jquery",
7 "components/bootstrap/js/bootstrap.min",
8 ], function(widget, $){
11
9
12 /**
10 var CheckboxView = widget.DOMWidgetView.extend({
13 * @module IPython
14 * @namespace IPython
15 **/
16
17 define(["widgets/js/widget"], function(WidgetManager){
18
19 var CheckboxView = IPython.DOMWidgetView.extend({
20 render : function(){
11 render : function(){
21 // Called when view is rendered.
12 // Called when view is rendered.
22 this.$el
13 this.$el
@@ -68,10 +59,9 b' define(["widgets/js/widget"], function(WidgetManager){'
68 },
59 },
69
60
70 });
61 });
71 WidgetManager.register_widget_view('CheckboxView', CheckboxView);
72
62
73
63
74 var ToggleButtonView = IPython.DOMWidgetView.extend({
64 var ToggleButtonView = widget.DOMWidgetView.extend({
75 render : function() {
65 render : function() {
76 // Called when view is rendered.
66 // Called when view is rendered.
77 var that = this;
67 var that = this;
@@ -122,5 +112,9 b' define(["widgets/js/widget"], function(WidgetManager){'
122 this.touch();
112 this.touch();
123 },
113 },
124 });
114 });
125 WidgetManager.register_widget_view('ToggleButtonView', ToggleButtonView);
115
116 return {
117 'CheckboxView': CheckboxView,
118 'ToggleButtonView': ToggleButtonView,
119 };
126 });
120 });
@@ -1,22 +1,13 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // ButtonWidget
5 "widgets/js/widget",
10 //============================================================================
6 "jquery",
7 "components/bootstrap/js/bootstrap.min",
8 ], function(widget, $){
11
9
12 /**
10 var ButtonView = widget.DOMWidgetView.extend({
13 * @module IPython
14 * @namespace IPython
15 **/
16
17 define(["widgets/js/widget"], function(WidgetManager){
18
19 var ButtonView = IPython.DOMWidgetView.extend({
20 render : function(){
11 render : function(){
21 // Called when view is rendered.
12 // Called when view is rendered.
22 this.setElement($("<button />")
13 this.setElement($("<button />")
@@ -56,5 +47,8 b' define(["widgets/js/widget"], function(WidgetManager){'
56 this.send({event: 'click'});
47 this.send({event: 'click'});
57 },
48 },
58 });
49 });
59 WidgetManager.register_widget_view('ButtonView', ButtonView);
50
51 return {
52 'ButtonView': ButtonView,
53 };
60 });
54 });
@@ -1,22 +1,13 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // ContainerWidget
5 "widgets/js/widget",
10 //============================================================================
6 "jqueryui",
7 "components/bootstrap/js/bootstrap.min",
8 ], function(widget, $){
11
9
12 /**
10 var ContainerView = widget.DOMWidgetView.extend({
13 * @module IPython
14 * @namespace IPython
15 **/
16
17 define(["widgets/js/widget"], function(WidgetManager) {
18
19 var ContainerView = IPython.DOMWidgetView.extend({
20 render: function(){
11 render: function(){
21 // Called when view is rendered.
12 // Called when view is rendered.
22 this.$el.addClass('widget-container')
13 this.$el.addClass('widget-container')
@@ -73,9 +64,8 b' define(["widgets/js/widget"], function(WidgetManager) {'
73 },
64 },
74 });
65 });
75
66
76 WidgetManager.register_widget_view('ContainerView', ContainerView);
67
77
68 var PopupView = widget.DOMWidgetView.extend({
78 var PopupView = IPython.DOMWidgetView.extend({
79 render: function(){
69 render: function(){
80 // Called when view is rendered.
70 // Called when view is rendered.
81 var that = this;
71 var that = this;
@@ -317,5 +307,9 b' define(["widgets/js/widget"], function(WidgetManager) {'
317 }
307 }
318 },
308 },
319 });
309 });
320 WidgetManager.register_widget_view('PopupView', PopupView);
310
311 return {
312 'ContainerView': ContainerView,
313 'PopupView': PopupView,
314 };
321 });
315 });
@@ -1,26 +1,12 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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 // FloatWidget
10 //============================================================================
11
12 /**
13 * @module IPython
14 * @namespace IPython
15 **/
16
17 define(["widgets/js/widget",
18 "widgets/js/widget_int"],
19 function(WidgetManager, int_widgets){
20
21 var IntSliderView = int_widgets[0];
22 var IntTextView = int_widgets[1];
23
3
4 define([
5 "widgets/js/widget",
6 "widgets/js/widget_int",
7 ], function(widget, int_widgets){
8 var IntSliderView = int_widgets.IntSliderView;
9 var IntTextView = int_widgets.IntTextView;
24
10
25 var FloatSliderView = IntSliderView.extend({
11 var FloatSliderView = IntSliderView.extend({
26 _validate_slide_value: function(x) {
12 _validate_slide_value: function(x) {
@@ -29,8 +15,6 b' define(["widgets/js/widget",'
29 return x;
15 return x;
30 },
16 },
31 });
17 });
32 WidgetManager.register_widget_view('FloatSliderView', FloatSliderView);
33
34
18
35 var FloatTextView = IntTextView.extend({
19 var FloatTextView = IntTextView.extend({
36 _parse_value: function(value) {
20 _parse_value: function(value) {
@@ -38,5 +22,9 b' define(["widgets/js/widget",'
38 return parseFloat(value);
22 return parseFloat(value);
39 },
23 },
40 });
24 });
41 WidgetManager.register_widget_view('FloatTextView', FloatTextView);
25
26 return {
27 'FloatSliderView': FloatSliderView,
28 'FloatTextView': FloatTextView,
29 };
42 });
30 });
@@ -1,22 +1,12 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // ImageWidget
5 "widgets/js/widget",
10 //============================================================================
6 "jquery",
11
7 ], function(widget, $){
12 /**
8
13 * @module IPython
9 var ImageView = widget.DOMWidgetView.extend({
14 * @namespace IPython
15 **/
16
17 define(["widgets/js/widget"], function(WidgetManager){
18
19 var ImageView = IPython.DOMWidgetView.extend({
20 render : function(){
10 render : function(){
21 // Called when view is rendered.
11 // Called when view is rendered.
22 this.setElement($("<img />"));
12 this.setElement($("<img />"));
@@ -47,5 +37,8 b' define(["widgets/js/widget"], function(WidgetManager){'
47 return ImageView.__super__.update.apply(this);
37 return ImageView.__super__.update.apply(this);
48 },
38 },
49 });
39 });
50 WidgetManager.register_widget_view('ImageView', ImageView);
40
41 return {
42 'ImageView': ImageView,
43 };
51 });
44 });
@@ -1,22 +1,13 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // IntWidget
5 "widgets/js/widget",
10 //============================================================================
6 "jqueryui",
11
7 "components/bootstrap/js/bootstrap.min",
12 /**
8 ], function(widget, $){
13 * @module IPython
9
14 * @namespace IPython
10 var IntSliderView = widget.DOMWidgetView.extend({
15 **/
16
17 define(["widgets/js/widget"], function(WidgetManager){
18
19 var IntSliderView = IPython.DOMWidgetView.extend({
20 render : function(){
11 render : function(){
21 // Called when view is rendered.
12 // Called when view is rendered.
22 this.$el
13 this.$el
@@ -152,10 +143,9 b' define(["widgets/js/widget"], function(WidgetManager){'
152 return ~~x;
143 return ~~x;
153 },
144 },
154 });
145 });
155 WidgetManager.register_widget_view('IntSliderView', IntSliderView);
156
146
157
147
158 var IntTextView = IPython.DOMWidgetView.extend({
148 var IntTextView = widget.DOMWidgetView.extend({
159 render : function(){
149 render : function(){
160 // Called when view is rendered.
150 // Called when view is rendered.
161 this.$el
151 this.$el
@@ -257,10 +247,9 b' define(["widgets/js/widget"], function(WidgetManager){'
257 return parseInt(value);
247 return parseInt(value);
258 },
248 },
259 });
249 });
260 WidgetManager.register_widget_view('IntTextView', IntTextView);
261
250
262
251
263 var ProgressView = IPython.DOMWidgetView.extend({
252 var ProgressView = widget.DOMWidgetView.extend({
264 render : function(){
253 render : function(){
265 // Called when view is rendered.
254 // Called when view is rendered.
266 this.$el
255 this.$el
@@ -303,10 +292,10 b' define(["widgets/js/widget"], function(WidgetManager){'
303 return ProgressView.__super__.update.apply(this);
292 return ProgressView.__super__.update.apply(this);
304 },
293 },
305 });
294 });
306 WidgetManager.register_widget_view('ProgressView', ProgressView);
307
308
295
309 // Return the slider and text views so they can be inheritted to create the
296 return {
310 // float versions.
297 'IntSliderView': IntSliderView,
311 return [IntSliderView, IntTextView];
298 'IntTextView': IntTextView,
299 'ProgressView': ProgressView,
300 };
312 });
301 });
@@ -1,22 +1,14 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // SelectionWidget
5 "widgets/js/widget",
10 //============================================================================
6 "base/js/utils",
7 "jquery",
8 "components/bootstrap/js/bootstrap.min",
9 ], function(widget, utils, $){
11
10
12 /**
11 var DropdownView = widget.DOMWidgetView.extend({
13 * @module IPython
14 * @namespace IPython
15 **/
16
17 define(["widgets/js/widget"], function(WidgetManager){
18
19 var DropdownView = IPython.DOMWidgetView.extend({
20 render : function(){
12 render : function(){
21 // Called when view is rendered.
13 // Called when view is rendered.
22 this.$el
14 this.$el
@@ -113,10 +105,9 b' define(["widgets/js/widget"], function(WidgetManager){'
113 },
105 },
114
106
115 });
107 });
116 WidgetManager.register_widget_view('DropdownView', DropdownView);
117
108
118
109
119 var RadioButtonsView = IPython.DOMWidgetView.extend({
110 var RadioButtonsView = widget.DOMWidgetView.extend({
120 render : function(){
111 render : function(){
121 // Called when view is rendered.
112 // Called when view is rendered.
122 this.$el
113 this.$el
@@ -204,10 +195,9 b' define(["widgets/js/widget"], function(WidgetManager){'
204 this.touch();
195 this.touch();
205 },
196 },
206 });
197 });
207 WidgetManager.register_widget_view('RadioButtonsView', RadioButtonsView);
198
208
199
209
200 var ToggleButtonsView = widget.DOMWidgetView.extend({
210 var ToggleButtonsView = IPython.DOMWidgetView.extend({
211 render : function(){
201 render : function(){
212 // Called when view is rendered.
202 // Called when view is rendered.
213 this.$el
203 this.$el
@@ -239,7 +229,7 b' define(["widgets/js/widget"], function(WidgetManager){'
239 if (item.trim().length == 0) {
229 if (item.trim().length == 0) {
240 item_html = "&nbsp;";
230 item_html = "&nbsp;";
241 } else {
231 } else {
242 item_html = IPython.utils.escape_html(item);
232 item_html = utils.escape_html(item);
243 }
233 }
244 var item_query = '[data-value="' + item + '"]';
234 var item_query = '[data-value="' + item + '"]';
245 var $item_element = that.$buttongroup.find(item_query);
235 var $item_element = that.$buttongroup.find(item_query);
@@ -297,10 +287,9 b' define(["widgets/js/widget"], function(WidgetManager){'
297 this.touch();
287 this.touch();
298 },
288 },
299 });
289 });
300 WidgetManager.register_widget_view('ToggleButtonsView', ToggleButtonsView);
290
301
302
291
303 var SelectView = IPython.DOMWidgetView.extend({
292 var SelectView = widget.DOMWidgetView.extend({
304 render : function(){
293 render : function(){
305 // Called when view is rendered.
294 // Called when view is rendered.
306 this.$el
295 this.$el
@@ -381,5 +370,11 b' define(["widgets/js/widget"], function(WidgetManager){'
381 this.touch();
370 this.touch();
382 },
371 },
383 });
372 });
384 WidgetManager.register_widget_view('SelectView', SelectView);
373
374 return {
375 'DropdownView': DropdownView,
376 'RadioButtonsView': RadioButtonsView,
377 'ToggleButtonsView': ToggleButtonsView,
378 'SelectView': SelectView,
379 };
385 });
380 });
@@ -1,25 +1,17 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // SelectionContainerWidget
5 "widgets/js/widget",
10 //============================================================================
6 "base/js/utils",
7 "jquery",
8 "components/bootstrap/js/bootstrap.min",
9 ], function(widget, utils, $){
11
10
12 /**
11 var AccordionView = widget.DOMWidgetView.extend({
13 * @module IPython
14 * @namespace IPython
15 **/
16
17 define(["widgets/js/widget"], function(WidgetManager){
18
19 var AccordionView = IPython.DOMWidgetView.extend({
20 render: function(){
12 render: function(){
21 // Called when view is rendered.
13 // Called when view is rendered.
22 var guid = 'panel-group' + IPython.utils.uuid();
14 var guid = 'panel-group' + utils.uuid();
23 this.$el
15 this.$el
24 .attr('id', guid)
16 .attr('id', guid)
25 .addClass('panel-group');
17 .addClass('panel-group');
@@ -99,7 +91,7 b' define(["widgets/js/widget"], function(WidgetManager){'
99 // Called when a child is added to children list.
91 // Called when a child is added to children list.
100 var view = this.create_child_view(model);
92 var view = this.create_child_view(model);
101 var index = this.containers.length;
93 var index = this.containers.length;
102 var uuid = IPython.utils.uuid();
94 var uuid = utils.uuid();
103 var accordion_group = $('<div />')
95 var accordion_group = $('<div />')
104 .addClass('panel panel-default')
96 .addClass('panel panel-default')
105 .appendTo(this.$el);
97 .appendTo(this.$el);
@@ -141,10 +133,9 b' define(["widgets/js/widget"], function(WidgetManager){'
141 }
133 }
142 },
134 },
143 });
135 });
144 WidgetManager.register_widget_view('AccordionView', AccordionView);
145
136
146
137
147 var TabView = IPython.DOMWidgetView.extend({
138 var TabView = widget.DOMWidgetView.extend({
148 initialize: function() {
139 initialize: function() {
149 // Public constructor.
140 // Public constructor.
150 this.containers = [];
141 this.containers = [];
@@ -153,7 +144,7 b' define(["widgets/js/widget"], function(WidgetManager){'
153
144
154 render: function(){
145 render: function(){
155 // Called when view is rendered.
146 // Called when view is rendered.
156 var uuid = 'tabs'+IPython.utils.uuid();
147 var uuid = 'tabs'+utils.uuid();
157 var that = this;
148 var that = this;
158 this.$tabs = $('<div />', {id: uuid})
149 this.$tabs = $('<div />', {id: uuid})
159 .addClass('nav')
150 .addClass('nav')
@@ -201,7 +192,7 b' define(["widgets/js/widget"], function(WidgetManager){'
201 // Called when a child is added to children list.
192 // Called when a child is added to children list.
202 var view = this.create_child_view(model);
193 var view = this.create_child_view(model);
203 var index = this.containers.length;
194 var index = this.containers.length;
204 var uuid = IPython.utils.uuid();
195 var uuid = utils.uuid();
205
196
206 var that = this;
197 var that = this;
207 var tab = $('<li />')
198 var tab = $('<li />')
@@ -268,5 +259,9 b' define(["widgets/js/widget"], function(WidgetManager){'
268 this.containers[index].tab('show');
259 this.containers[index].tab('show');
269 },
260 },
270 });
261 });
271 WidgetManager.register_widget_view('TabView', TabView);
262
263 return {
264 'AccordionView': AccordionView,
265 'TabView': TabView,
266 };
272 });
267 });
@@ -1,22 +1,13 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2013 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
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
3
8 //============================================================================
4 define([
9 // StringWidget
5 "widgets/js/widget",
10 //============================================================================
6 "jquery",
7 "components/bootstrap/js/bootstrap.min",
8 ], function(widget, $){
11
9
12 /**
10 var HTMLView = widget.DOMWidgetView.extend({
13 * @module IPython
14 * @namespace IPython
15 **/
16
17 define(["widgets/js/widget"], function(WidgetManager){
18
19 var HTMLView = IPython.DOMWidgetView.extend({
20 render : function(){
11 render : function(){
21 // Called when view is rendered.
12 // Called when view is rendered.
22 this.update(); // Set defaults.
13 this.update(); // Set defaults.
@@ -31,10 +22,9 b' define(["widgets/js/widget"], function(WidgetManager){'
31 return HTMLView.__super__.update.apply(this);
22 return HTMLView.__super__.update.apply(this);
32 },
23 },
33 });
24 });
34 WidgetManager.register_widget_view('HTMLView', HTMLView);
35
25
36
26
37 var LatexView = IPython.DOMWidgetView.extend({
27 var LatexView = widget.DOMWidgetView.extend({
38 render : function(){
28 render : function(){
39 // Called when view is rendered.
29 // Called when view is rendered.
40 this.update(); // Set defaults.
30 this.update(); // Set defaults.
@@ -51,10 +41,9 b' define(["widgets/js/widget"], function(WidgetManager){'
51 return LatexView.__super__.update.apply(this);
41 return LatexView.__super__.update.apply(this);
52 },
42 },
53 });
43 });
54 WidgetManager.register_widget_view('LatexView', LatexView);
55
44
56
45
57 var TextareaView = IPython.DOMWidgetView.extend({
46 var TextareaView = widget.DOMWidgetView.extend({
58 render: function(){
47 render: function(){
59 // Called when view is rendered.
48 // Called when view is rendered.
60 this.$el
49 this.$el
@@ -136,10 +125,9 b' define(["widgets/js/widget"], function(WidgetManager){'
136 this.touch();
125 this.touch();
137 },
126 },
138 });
127 });
139 WidgetManager.register_widget_view('TextareaView', TextareaView);
140
128
141
129
142 var TextView = IPython.DOMWidgetView.extend({
130 var TextView = widget.DOMWidgetView.extend({
143 render: function(){
131 render: function(){
144 // Called when view is rendered.
132 // Called when view is rendered.
145 this.$el
133 this.$el
@@ -244,5 +232,11 b' define(["widgets/js/widget"], function(WidgetManager){'
244 }
232 }
245 },
233 },
246 });
234 });
247 WidgetManager.register_widget_view('TextView', TextView);
235
236 return {
237 'HTMLView': HTMLView,
238 'LatexView': LatexView,
239 'TextareaView': TextareaView,
240 'TextView': TextView,
241 };
248 });
242 });
@@ -46,6 +46,7 b''
46
46
47
47
48 {% block script %}
48 {% block script %}
49 {{super()}}
49
50
50 <script src="{{static_url("auth/js/loginmain.js") }}" type="text/javascript" charset="utf-8"></script>
51 <script src="{{static_url("auth/js/loginmain.js") }}" type="text/javascript" charset="utf-8"></script>
51
52
@@ -32,6 +32,7 b''
32 {% endblock %}
32 {% endblock %}
33
33
34 {% block script %}
34 {% block script %}
35 {{super()}}
35
36
36 <script src="{{static_url("auth/js/logoutmain.js") }}" type="text/javascript" charset="utf-8"></script>
37 <script src="{{static_url("auth/js/logoutmain.js") }}" type="text/javascript" charset="utf-8"></script>
37
38
@@ -293,10 +293,8 b' class="notebook_app"'
293
293
294
294
295 {% block script %}
295 {% block script %}
296
297 {{super()}}
296 {{super()}}
298
297
299 <script src="{{ static_url("components/google-caja/html-css-sanitizer-minified.js") }}" charset="utf-8"></script>
300 <script src="{{ static_url("components/codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
298 <script src="{{ static_url("components/codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
301 <script type="text/javascript">
299 <script type="text/javascript">
302 CodeMirror.modeURL = "{{ static_url("components/codemirror/mode/%N/%N.js", include_version=False) }}";
300 CodeMirror.modeURL = "{{ static_url("components/codemirror/mode/%N/%N.js", include_version=False) }}";
@@ -317,46 +315,6 b' class="notebook_app"'
317 <script src="{{ static_url("notebook/js/codemirror-ipython.js") }}" charset="utf-8"></script>
315 <script src="{{ static_url("notebook/js/codemirror-ipython.js") }}" charset="utf-8"></script>
318 <script src="{{ static_url("notebook/js/codemirror-ipythongfm.js") }}" charset="utf-8"></script>
316 <script src="{{ static_url("notebook/js/codemirror-ipythongfm.js") }}" charset="utf-8"></script>
319
317
320 <script src="{{ static_url("components/highlight.js/build/highlight.pack.js") }}" charset="utf-8"></script>
318 <script src="{{ static_url("notebook/js/main.js") }}" charset="utf-8"></script>
321
322 <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
323
324 <script src="{{ static_url("base/js/events.js") }}" type="text/javascript" charset="utf-8"></script>
325 <script src="{{ static_url("base/js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
326 <script src="{{ static_url("base/js/keyboard.js") }}" type="text/javascript" charset="utf-8"></script>
327 <script src="{{ static_url("base/js/security.js") }}" type="text/javascript" charset="utf-8"></script>
328 <script src="{{ static_url("base/js/dialog.js") }}" type="text/javascript" charset="utf-8"></script>
329 <script src="{{ static_url("services/kernels/js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
330 <script src="{{ static_url("services/kernels/js/comm.js") }}" type="text/javascript" charset="utf-8"></script>
331 <script src="{{ static_url("services/sessions/js/session.js") }}" type="text/javascript" charset="utf-8"></script>
332 <script src="{{ static_url("notebook/js/layoutmanager.js") }}" type="text/javascript" charset="utf-8"></script>
333 <script src="{{ static_url("notebook/js/mathjaxutils.js") }}" type="text/javascript" charset="utf-8"></script>
334 <script src="{{ static_url("notebook/js/outputarea.js") }}" type="text/javascript" charset="utf-8"></script>
335 <script src="{{ static_url("notebook/js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
336 <script src="{{ static_url("notebook/js/celltoolbar.js") }}" type="text/javascript" charset="utf-8"></script>
337 <script src="{{ static_url("notebook/js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
338 <script src="{{ static_url("notebook/js/completer.js") }}" type="text/javascript" charset="utf-8"></script>
339 <script src="{{ static_url("notebook/js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
340 <script src="{{ static_url("notebook/js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script>
341 <script src="{{ static_url("notebook/js/quickhelp.js") }}" type="text/javascript" charset="utf-8"></script>
342 <script src="{{ static_url("notebook/js/pager.js") }}" type="text/javascript" charset="utf-8"></script>
343 <script src="{{ static_url("notebook/js/menubar.js") }}" type="text/javascript" charset="utf-8"></script>
344 <script src="{{ static_url("notebook/js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script>
345 <script src="{{ static_url("notebook/js/maintoolbar.js") }}" type="text/javascript" charset="utf-8"></script>
346 <script src="{{ static_url("notebook/js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
347 <script src="{{ static_url("notebook/js/keyboardmanager.js") }}" type="text/javascript" charset="utf-8"></script>
348 <script src="{{ static_url("notebook/js/notificationwidget.js") }}" type="text/javascript" charset="utf-8"></script>
349 <script src="{{ static_url("notebook/js/notificationarea.js") }}" type="text/javascript" charset="utf-8"></script>
350 <script src="{{ static_url("notebook/js/tooltip.js") }}" type="text/javascript" charset="utf-8"></script>
351 <script src="{{ static_url("notebook/js/tour.js") }}" type="text/javascript" charset="utf-8"></script>
352
353 <script src="{{ static_url("notebook/js/config.js") }}" type="text/javascript" charset="utf-8"></script>
354 <script src="{{ static_url("notebook/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
355
356 <script src="{{ static_url("notebook/js/contexthint.js") }}" charset="utf-8"></script>
357
358 <script src="{{ static_url("notebook/js/celltoolbarpresets/default.js") }}" type="text/javascript" charset="utf-8"></script>
359 <script src="{{ static_url("notebook/js/celltoolbarpresets/rawcell.js") }}" type="text/javascript" charset="utf-8"></script>
360 <script src="{{ static_url("notebook/js/celltoolbarpresets/slideshow.js") }}" type="text/javascript" charset="utf-8"></script>
361
319
362 {% endblock %}
320 {% endblock %}
@@ -20,8 +20,12 b''
20 baseUrl: '{{static_url("", include_version=False)}}',
20 baseUrl: '{{static_url("", include_version=False)}}',
21 paths: {
21 paths: {
22 nbextensions : '{{ base_url }}nbextensions',
22 nbextensions : '{{ base_url }}nbextensions',
23 underscore : '{{static_url("components/underscore/underscore-min.js")}}',
23 underscore : 'components/underscore/underscore-min',
24 backbone : '{{static_url("components/backbone/backbone-min.js")}}',
24 backbone : 'components/backbone/backbone-min',
25 jquery: 'components/jquery/jquery.min',
26 bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min',
27 dateformat: 'dateformat/date.format',
28 jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min',
25 },
29 },
26 shim: {
30 shim: {
27 underscore: {
31 underscore: {
@@ -30,6 +34,16 b''
30 backbone: {
34 backbone: {
31 deps: ["underscore", "jquery"],
35 deps: ["underscore", "jquery"],
32 exports: "Backbone"
36 exports: "Backbone"
37 },
38 bootstraptour: {
39 exports: "Tour"
40 },
41 dateformat: {
42 exports: "dateFormat"
43 },
44 jqueryui: {
45 deps: ["jquery"],
46 exports: "$"
33 }
47 }
34 }
48 }
35 });
49 });
@@ -75,14 +89,8 b''
75 {% endblock %}
89 {% endblock %}
76 </div>
90 </div>
77
91
78 <script src="{{static_url("components/jquery/jquery.min.js") }}" type="text/javascript" charset="utf-8"></script>
79 <script src="{{static_url("components/jquery-ui/ui/minified/jquery-ui.min.js") }}" type="text/javascript" charset="utf-8"></script>
80 <script src="{{static_url("components/bootstrap/js/bootstrap.min.js") }}" type="text/javascript" charset="utf-8"></script>
81 <script src="{{static_url("base/js/namespace.js") }}" type="text/javascript" charset="utf-8"></script>
82 <script src="{{static_url("base/js/page.js") }}" type="text/javascript" charset="utf-8"></script>
83 <script src="{{static_url("auth/js/loginwidget.js") }}" type="text/javascript" charset="utf-8"></script>
84
85 {% block script %}
92 {% block script %}
93 <script src="{{static_url("base/js/pagemain.js") }}" type="text/javascript" charset="utf-8"></script>
86 {% endblock %}
94 {% endblock %}
87
95
88 <script src="{{static_url("custom/custom.js") }}" type="text/javascript" charset="utf-8"></script>
96 <script src="{{static_url("custom/custom.js") }}" type="text/javascript" charset="utf-8"></script>
@@ -111,11 +111,6 b' data-notebook-path="{{notebook_path}}"'
111
111
112 {% block script %}
112 {% block script %}
113 {{super()}}
113 {{super()}}
114 <script src="{{ static_url("base/js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
114
115 <script src="{{static_url("base/js/dialog.js") }}" type="text/javascript" charset="utf-8"></script>
115 <script src="{{ static_url("tree/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
116 <script src="{{static_url("tree/js/sessionlist.js") }}" type="text/javascript" charset="utf-8"></script>
117 <script src="{{static_url("tree/js/notebooklist.js") }}" type="text/javascript" charset="utf-8"></script>
118 <script src="{{static_url("tree/js/kernellist.js") }}" type="text/javascript" charset="utf-8"></script>
119 <script src="{{static_url("tree/js/clusterlist.js") }}" type="text/javascript" charset="utf-8"></script>
120 <script src="{{static_url("tree/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
121 {% endblock %}
116 {% endblock %}
@@ -11,10 +11,10 b' casper.notebook_test(function () {'
11 this.evaluate(function (nbname) {
11 this.evaluate(function (nbname) {
12 IPython.notebook.notebook_name = nbname;
12 IPython.notebook.notebook_name = nbname;
13 IPython._save_success = IPython._save_failed = false;
13 IPython._save_success = IPython._save_failed = false;
14 $([IPython.events]).on('notebook_saved.Notebook', function () {
14 IPython.events.on('notebook_saved.Notebook', function () {
15 IPython._save_success = true;
15 IPython._save_success = true;
16 });
16 });
17 $([IPython.events]).on('notebook_save_failed.Notebook',
17 IPython.events.on('notebook_save_failed.Notebook',
18 function (event, xhr, status, error) {
18 function (event, xhr, status, error) {
19 IPython._save_failed = "save failed with " + xhr.status + xhr.responseText;
19 IPython._save_failed = "save failed with " + xhr.status + xhr.responseText;
20 });
20 });
@@ -41,7 +41,7 b' casper.notebook_test(function () {'
41 });
41 });
42
42
43 this.thenEvaluate(function(){
43 this.thenEvaluate(function(){
44 $([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
44 IPython.events.on('checkpoint_created.Notebook', function (evt, data) {
45 IPython._checkpoint_created = true;
45 IPython._checkpoint_created = true;
46 });
46 });
47 IPython._checkpoint_created = false;
47 IPython._checkpoint_created = false;
@@ -12,6 +12,7 b' casper.open_new_notebook = function () {'
12 // Create and open a new notebook.
12 // Create and open a new notebook.
13 var baseUrl = this.get_notebook_server();
13 var baseUrl = this.get_notebook_server();
14 this.start(baseUrl);
14 this.start(baseUrl);
15 this.waitFor(this.page_loaded);
15 this.thenClick('button#new_notebook');
16 this.thenClick('button#new_notebook');
16 this.waitForPopup('');
17 this.waitForPopup('');
17
18
@@ -19,15 +20,16 b' casper.open_new_notebook = function () {'
19 this.then(function () {
20 this.then(function () {
20 this.open(this.popups[0].url);
21 this.open(this.popups[0].url);
21 });
22 });
23 this.waitFor(this.page_loaded);
22
24
23 // Make sure the kernel has started
25 // Make sure the kernel has started
24 this.waitFor( this.kernel_running );
26 this.waitFor(this.kernel_running);
25 // track the IPython busy/idle state
27 // track the IPython busy/idle state
26 this.thenEvaluate(function () {
28 this.thenEvaluate(function () {
27 $([IPython.events]).on('status_idle.Kernel',function () {
29 IPython.events.on('status_idle.Kernel',function () {
28 IPython._status = 'idle';
30 IPython._status = 'idle';
29 });
31 });
30 $([IPython.events]).on('status_busy.Kernel',function () {
32 IPython.events.on('status_busy.Kernel',function () {
31 IPython._status = 'busy';
33 IPython._status = 'busy';
32 });
34 });
33 });
35 });
@@ -42,9 +44,18 b' casper.open_new_notebook = function () {'
42 });
44 });
43 };
45 };
44
46
45 casper.kernel_running = function kernel_running() {
47 casper.page_loaded = function() {
46 // Return whether or not the kernel is running.
48 // Return whether or not the kernel is running.
47 return this.evaluate(function kernel_running() {
49 return this.evaluate(function() {
50 return IPython !== undefined &&
51 IPython.page !== undefined &&
52 IPython.events !== undefined;
53 });
54 };
55
56 casper.kernel_running = function() {
57 // Return whether or not the kernel is running.
58 return this.evaluate(function() {
48 return IPython.notebook.kernel.running;
59 return IPython.notebook.kernel.running;
49 });
60 });
50 };
61 };
@@ -503,6 +514,7 b' casper.open_dashboard = function () {'
503 // Start casper by opening the dashboard page.
514 // Start casper by opening the dashboard page.
504 var baseUrl = this.get_notebook_server();
515 var baseUrl = this.get_notebook_server();
505 this.start(baseUrl);
516 this.start(baseUrl);
517 this.waitFor(this.page_loaded);
506 this.wait_for_dashboard();
518 this.wait_for_dashboard();
507 };
519 };
508
520
@@ -5,50 +5,59 b''
5 // IPython static_path dir relative to here:
5 // IPython static_path dir relative to here:
6 var static_path = __dirname + "/../../html/static/";
6 var static_path = __dirname + "/../../html/static/";
7
7
8 var fs = require('fs');
8 // Excerpt from the example in require.js docs
9 var IPython;
9 // http://requirejs.org/docs/node.html
10 // marked can be loaded with require,
10 var requirejs = require('requirejs');
11 // the others must be execfiled
11 requirejs.config({
12 var marked = require(static_path + 'components/marked/lib/marked.js');
12 //Pass the top-level main.js/index.js require
13
13 //function to requirejs so that node modules
14 eval(fs.readFileSync(static_path + "components/highlight.js/build/highlight.pack.js", 'utf8'));
14 //are loaded relative to the top-level JS file.
15 eval(fs.readFileSync(static_path + "base/js/namespace.js", 'utf8'));
15 nodeRequire: require,
16 baseUrl: static_path,
17 });
16
18
17 eval(fs.readFileSync(static_path + "base/js/utils.js", 'utf8'));
19 requirejs([
18 eval(fs.readFileSync(static_path + "notebook/js/mathjaxutils.js", 'utf8'));
20 'fs',
21 'components/marked/lib/marked',
22 'components/highlight.js/build/highlight.pack',
23 'base/js/utils',
24 'notebook/js/mathjaxutils',
25 ], function(fs, marked, hljs, utils, mathjaxutils) {
19
26
20 // this is copied from notebook.main. Should it be moved somewhere we can reuse it?
27 // this is copied from notebook.main. Should it be moved somewhere we can reuse it?
21 marked.setOptions({
28 marked.setOptions({
22 gfm : true,
29 gfm : true,
23 tables: true,
30 tables: true,
24 langPrefix: "language-",
31 langPrefix: "language-",
25 highlight: function(code, lang) {
32 highlight: function(code, lang) {
26 if (!lang) {
33 if (!lang) {
27 // no language, no highlight
34 // no language, no highlight
28 return code;
35 return code;
29 }
36 }
30 var highlighted;
37 var highlighted;
31 try {
38 try {
32 highlighted = hljs.highlight(lang, code, false);
39 highlighted = hljs.highlight(lang, code, false);
33 } catch(err) {
40 } catch(err) {
34 highlighted = hljs.highlightAuto(code);
41 highlighted = hljs.highlightAuto(code);
42 }
43 return highlighted.value;
35 }
44 }
36 return highlighted.value;
45 });
37 }
38 });
39
46
40 // read the markdown from stdin
47 // read the markdown from stdin
41 var md='';
48 var md='';
42 process.stdin.on("data", function (data) {
49 process.stdin.on("data", function (data) {
43 md += data;
50 md += data;
44 });
51 });
52
53 // perform the md2html transform once stdin is complete
54 process.stdin.on("end", function () {
55 var text_and_math = mathjaxutils.remove_math(md);
56 var text = text_and_math[0];
57 var math = text_and_math[1];
58 var html = marked.parser(marked.lexer(text));
59 html = mathjaxutils.replace_math(html, math);
60 process.stdout.write(html);
61 });
45
62
46 // perform the md2html transform once stdin is complete
47 process.stdin.on("end", function () {
48 var text_and_math = IPython.mathjaxutils.remove_math(md);
49 var text = text_and_math[0];
50 var math = text_and_math[1];
51 var html = marked.parser(marked.lexer(text));
52 html = IPython.mathjaxutils.replace_math(html, math);
53 process.stdout.write(html);
54 });
63 });
General Comments 0
You need to be logged in to leave comments. Login now