Show More
@@ -1,7 +1,7 | |||
|
1 | 1 | // function completer. |
|
2 | 2 | // |
|
3 | 3 | // completer should be a class that take an cell instance |
|
4 | var IPython = (function(IPython) { | |
|
4 | var IPython = (function (IPython) { | |
|
5 | 5 | // that will prevent us from misspelling |
|
6 | 6 | "use strict"; |
|
7 | 7 | |
@@ -42,13 +42,13 var IPython = (function(IPython) { | |||
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | |
|
45 | var Completer = function(cell) { | |
|
45 | var Completer = function (cell) { | |
|
46 | 46 | this.editor = cell.code_mirror; |
|
47 | 47 | var that = this; |
|
48 | $([IPython.events]).on('status_busy.Kernel', function() { | |
|
48 | $([IPython.events]).on('status_busy.Kernel', function () { | |
|
49 | 49 | that.skip_kernel_completion = true; |
|
50 | 50 | }); |
|
51 | $([IPython.events]).on('status_idle.Kernel', function() { | |
|
51 | $([IPython.events]).on('status_idle.Kernel', function () { | |
|
52 | 52 | that.skip_kernel_completion = false; |
|
53 | 53 | }); |
|
54 | 54 | |
@@ -57,7 +57,7 var IPython = (function(IPython) { | |||
|
57 | 57 | |
|
58 | 58 | |
|
59 | 59 | |
|
60 | Completer.prototype.startCompletion = function() { | |
|
60 | Completer.prototype.startCompletion = function () { | |
|
61 | 61 | // call for a 'first' completion, that will set the editor and do some |
|
62 | 62 | // special behaviour like autopicking if only one completion availlable |
|
63 | 63 | // |
@@ -67,7 +67,7 var IPython = (function(IPython) { | |||
|
67 | 67 | this.carryOnCompletion(true); |
|
68 | 68 | }; |
|
69 | 69 | |
|
70 | Completer.prototype.carryOnCompletion = function(ff) { | |
|
70 | Completer.prototype.carryOnCompletion = function (ff) { | |
|
71 | 71 | // Pass true as parameter if you want the commpleter to autopick when |
|
72 | 72 | // only one completion. This function is automatically reinvoked at |
|
73 | 73 | // each keystroke with ff = false |
@@ -108,7 +108,7 var IPython = (function(IPython) { | |||
|
108 | 108 | } |
|
109 | 109 | }; |
|
110 | 110 | |
|
111 | Completer.prototype.finish_completing = function(content) { | |
|
111 | Completer.prototype.finish_completing = function (content) { | |
|
112 | 112 | // let's build a function that wrap all that stuff into what is needed |
|
113 | 113 | // for the new completer: |
|
114 | 114 | var matched_text = content.matched_text; |
@@ -176,11 +176,11 var IPython = (function(IPython) { | |||
|
176 | 176 | $('body').append(this.complete); |
|
177 | 177 | //build the container |
|
178 | 178 | var that = this; |
|
179 | this.sel.dblclick(function() { | |
|
179 | this.sel.dblclick(function () { | |
|
180 | 180 | that.pick(); |
|
181 | 181 | }); |
|
182 | 182 | this.sel.blur(this.close); |
|
183 | this.sel.keydown(function(event) { | |
|
183 | this.sel.keydown(function (event) { | |
|
184 | 184 | that.keydown(event); |
|
185 | 185 | }); |
|
186 | 186 | |
@@ -188,17 +188,17 var IPython = (function(IPython) { | |||
|
188 | 188 | |
|
189 | 189 | this.sel.focus(); |
|
190 | 190 | // Opera sometimes ignores focusing a freshly created node |
|
191 | if (window.opera) setTimeout(function() { | |
|
191 | if (window.opera) setTimeout(function () { | |
|
192 | 192 | if (!this.done) this.sel.focus(); |
|
193 | 193 | }, 100); |
|
194 | 194 | return true; |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | Completer.prototype.insert = function(completion) { | |
|
197 | Completer.prototype.insert = function (completion) { | |
|
198 | 198 | this.editor.replaceRange(completion.str, completion.from, completion.to); |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | Completer.prototype.build_gui_list = function(completions) { | |
|
201 | Completer.prototype.build_gui_list = function (completions) { | |
|
202 | 202 | // Need to clear the all list |
|
203 | 203 | for (var i = 0; i < completions.length; ++i) { |
|
204 | 204 | var opt = $('<option/>').text(completions[i].str).addClass(completions[i].type); |
@@ -207,23 +207,23 var IPython = (function(IPython) { | |||
|
207 | 207 | this.sel.children().first().attr('selected', 'true'); |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | Completer.prototype.close = function() { | |
|
210 | Completer.prototype.close = function () { | |
|
211 | 211 | if (this.done) return; |
|
212 | 212 | this.done = true; |
|
213 | 213 | $('.completions').remove(); |
|
214 | 214 | } |
|
215 | 215 | |
|
216 | Completer.prototype.pick = function() { | |
|
216 | Completer.prototype.pick = function () { | |
|
217 | 217 | this.insert(this.raw_result[this.sel[0].selectedIndex]); |
|
218 | 218 | this.close(); |
|
219 | 219 | var that = this; |
|
220 | setTimeout(function() { | |
|
220 | setTimeout(function () { | |
|
221 | 221 | that.editor.focus(); |
|
222 | 222 | }, 50); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | |
|
226 | Completer.prototype.keydown = function(event) { | |
|
226 | Completer.prototype.keydown = function (event) { | |
|
227 | 227 | var code = event.keyCode; |
|
228 | 228 | var that = this; |
|
229 | 229 | // Enter |
@@ -252,7 +252,7 var IPython = (function(IPython) { | |||
|
252 | 252 | CodeMirror.e_stop(event); |
|
253 | 253 | this.editor.focus(); |
|
254 | 254 | //reinvoke self |
|
255 | setTimeout(function() { | |
|
255 | setTimeout(function () { | |
|
256 | 256 | that.carryOnCompletion(); |
|
257 | 257 | }, 50); |
|
258 | 258 | } else if (code == key.upArrow || code == key.downArrow) { |
@@ -263,7 +263,7 var IPython = (function(IPython) { | |||
|
263 | 263 | this.close(); |
|
264 | 264 | this.editor.focus(); |
|
265 | 265 | //we give focus to the editor immediately and call sell in 50 ms |
|
266 | setTimeout(function() { | |
|
266 | setTimeout(function () { | |
|
267 | 267 | that.carryOnCompletion(); |
|
268 | 268 | }, 50); |
|
269 | 269 | } |
@@ -15,15 +15,15 | |||
|
15 | 15 | // IPython.tooltip.tabs_functions |
|
16 | 16 | // |
|
17 | 17 | // eg : |
|
18 | // IPython.tooltip.tabs_functions[4] = function(){console.log('this is the action of the 4th tab pressing')} | |
|
18 | // IPython.tooltip.tabs_functions[4] = function (){console.log('this is the action of the 4th tab pressing')} | |
|
19 | 19 | // |
|
20 | var IPython = (function(IPython) { | |
|
20 | var IPython = (function (IPython) { | |
|
21 | 21 | "use strict"; |
|
22 | 22 | |
|
23 | 23 | var utils = IPython.utils; |
|
24 | 24 | |
|
25 | 25 | // tooltip constructor |
|
26 | var Tooltip = function() { | |
|
26 | var Tooltip = function () { | |
|
27 | 27 | var that = this; |
|
28 | 28 | this.time_before_tooltip = 1200; |
|
29 | 29 | |
@@ -48,7 +48,7 var IPython = (function(IPython) { | |||
|
48 | 48 | // build the buttons menu on the upper right |
|
49 | 49 | // expand the tooltip to see more |
|
50 | 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 tab 2 times)').click(function() { | |
|
51 | .attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press tab 2 times)').click(function () { | |
|
52 | 52 | that.expand() |
|
53 | 53 | }).append( |
|
54 | 54 | $('<span/>').text('Expand').addClass('ui-icon').addClass('ui-icon-plus')); |
@@ -57,7 +57,7 var IPython = (function(IPython) { | |||
|
57 | 57 | var morelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button').attr('title', 'show the current docstring in pager (press tab 4 times)'); |
|
58 | 58 | var morespan = $('<span/>').text('Open in Pager').addClass('ui-icon').addClass('ui-icon-arrowstop-l-n'); |
|
59 | 59 | morelink.append(morespan); |
|
60 | morelink.click(function() { | |
|
60 | morelink.click(function () { | |
|
61 | 61 | that.showInPager(); |
|
62 | 62 | }); |
|
63 | 63 | |
@@ -65,7 +65,7 var IPython = (function(IPython) { | |||
|
65 | 65 | var closelink = $('<a/>').attr('href', "#").attr('role', "button").addClass('ui-button'); |
|
66 | 66 | var closespan = $('<span/>').text('Close').addClass('ui-icon').addClass('ui-icon-close'); |
|
67 | 67 | closelink.append(closespan); |
|
68 | closelink.click(function() { | |
|
68 | closelink.click(function () { | |
|
69 | 69 | that.remove_and_cancel_tooltip(true); |
|
70 | 70 | }); |
|
71 | 71 | |
@@ -77,7 +77,7 var IPython = (function(IPython) { | |||
|
77 | 77 | clockspan.addClass('ui-icon'); |
|
78 | 78 | clockspan.addClass('ui-icon-clock'); |
|
79 | 79 | this._clocklink.append(clockspan); |
|
80 | this._clocklink.click(function() { | |
|
80 | this._clocklink.click(function () { | |
|
81 | 81 | that.cancel_stick(); |
|
82 | 82 | }); |
|
83 | 83 | |
@@ -102,33 +102,33 var IPython = (function(IPython) { | |||
|
102 | 102 | this.tooltip.append(this.text); |
|
103 | 103 | |
|
104 | 104 | // function that will be called if you press tab 1, 2, 3... times in a row |
|
105 | this.tabs_functions = [function(cell, text) { | |
|
105 | this.tabs_functions = [function (cell, text) { | |
|
106 | 106 | that._request_tooltip(cell, text); |
|
107 | 107 | IPython.notification_widget.set_message('tab again to expand pager', 2500); |
|
108 | }, function() { | |
|
108 | }, function () { | |
|
109 | 109 | that.expand(); |
|
110 | 110 | IPython.notification_widget.set_message('tab again to make pager sticky for 10s', 2500); |
|
111 | }, function() { | |
|
111 | }, function () { | |
|
112 | 112 | that.stick(); |
|
113 | 113 | IPython.notification_widget.set_message('tab again to open help in pager', 2500); |
|
114 | }, function(cell) { | |
|
114 | }, function (cell) { | |
|
115 | 115 | that.cancel_stick(); |
|
116 | 116 | that.showInPager(cell); |
|
117 | 117 | that._cmfocus(); |
|
118 | 118 | }]; |
|
119 | 119 | // call after all the tabs function above have bee call to clean their effects |
|
120 | 120 | // if necessary |
|
121 | this.reset_tabs_function = function(cell, text) { | |
|
121 | this.reset_tabs_function = function (cell, text) { | |
|
122 | 122 | this._old_cell = (cell) ? cell : null; |
|
123 | 123 | this._old_request = (text) ? text : null; |
|
124 | 124 | this._consecutive_counter = 0; |
|
125 | 125 | } |
|
126 | 126 | }; |
|
127 | 127 | |
|
128 | Tooltip.prototype.showInPager = function(cell) { | |
|
128 | Tooltip.prototype.showInPager = function (cell) { | |
|
129 | 129 | // reexecute last call in pager by appending ? to show back in pager |
|
130 | 130 | var that = this; |
|
131 | var empty = function() {}; | |
|
131 | var empty = function () {}; | |
|
132 | 132 | IPython.notebook.kernel.execute( |
|
133 | 133 | that.name + '?', { |
|
134 | 134 | 'execute_reply': empty, |
@@ -143,7 +143,7 var IPython = (function(IPython) { | |||
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | // grow the tooltip verticaly |
|
146 | Tooltip.prototype.expand = function() { | |
|
146 | Tooltip.prototype.expand = function () { | |
|
147 | 147 | this.text.removeClass('smalltooltip'); |
|
148 | 148 | this.text.addClass('bigtooltip'); |
|
149 | 149 | $('#expanbutton').hide('slow'); |
@@ -152,7 +152,7 var IPython = (function(IPython) { | |||
|
152 | 152 | |
|
153 | 153 | // deal with all the logic of hiding the tooltip |
|
154 | 154 | // and reset it's status |
|
155 | Tooltip.prototype.hide = function() { | |
|
155 | Tooltip.prototype.hide = function () { | |
|
156 | 156 | this.tooltip.addClass('hide'); |
|
157 | 157 | $('#expanbutton').show('slow'); |
|
158 | 158 | this.text.removeClass('bigtooltip'); |
@@ -162,7 +162,7 var IPython = (function(IPython) { | |||
|
162 | 162 | this._hidden = true; |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | Tooltip.prototype.remove_and_cancel_tooltip = function(force) { | |
|
165 | Tooltip.prototype.remove_and_cancel_tooltip = function (force) { | |
|
166 | 166 | // note that we don't handle closing directly inside the calltip |
|
167 | 167 | // as in the completer, because it is not focusable, so won't |
|
168 | 168 | // get the event. |
@@ -170,11 +170,11 var IPython = (function(IPython) { | |||
|
170 | 170 | this.hide(); |
|
171 | 171 | } |
|
172 | 172 | this.cancel_pending(); |
|
173 | this.reset_tabs_function(); | |
|
173 | this.reset_tabs_function (); | |
|
174 | 174 | } |
|
175 | 175 | |
|
176 | 176 | // cancel autocall done after '(' for example. |
|
177 | Tooltip.prototype.cancel_pending = function() { | |
|
177 | Tooltip.prototype.cancel_pending = function () { | |
|
178 | 178 | if (this._tooltip_timeout != null) { |
|
179 | 179 | clearTimeout(this._tooltip_timeout); |
|
180 | 180 | this._tooltip_timeout = null; |
@@ -182,14 +182,14 var IPython = (function(IPython) { | |||
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | // will trigger tooltip after timeout |
|
185 | Tooltip.prototype.pending = function(cell) { | |
|
185 | Tooltip.prototype.pending = function (cell) { | |
|
186 | 186 | var that = this; |
|
187 | this._tooltip_timeout = setTimeout(function() { | |
|
187 | this._tooltip_timeout = setTimeout(function () { | |
|
188 | 188 | that.request(cell) |
|
189 | 189 | }, that.time_before_tooltip); |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | Tooltip.prototype._request_tooltip = function(cell, func) { | |
|
192 | Tooltip.prototype._request_tooltip = function (cell, func) { | |
|
193 | 193 | // use internally just to make the request to the kernel |
|
194 | 194 | // Feel free to shorten this logic if you are better |
|
195 | 195 | // than me in regEx |
@@ -216,7 +216,7 var IPython = (function(IPython) { | |||
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | // make an imediate completion request |
|
219 | Tooltip.prototype.request = function(cell) { | |
|
219 | Tooltip.prototype.request = function (cell) { | |
|
220 | 220 | // request(codecell) |
|
221 | 221 | // Deal with extracting the text from the cell and counting |
|
222 | 222 | // call in a row |
@@ -238,7 +238,7 var IPython = (function(IPython) { | |||
|
238 | 238 | } else { |
|
239 | 239 | // else reset |
|
240 | 240 | this.cancel_stick(); |
|
241 | this.reset_tabs_function(cell, text); | |
|
241 | this.reset_tabs_function (cell, text); | |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | // don't do anything if line beggin with '(' or is empty |
@@ -249,13 +249,13 var IPython = (function(IPython) { | |||
|
249 | 249 | this.tabs_functions[this._consecutive_counter](cell, text); |
|
250 | 250 | |
|
251 | 251 | // then if we are at the end of list function, reset |
|
252 | if (this._consecutive_counter == this.tabs_functions.length) this.reset_tabs_function(cell, text); | |
|
252 | if (this._consecutive_counter == this.tabs_functions.length) this.reset_tabs_function (cell, text); | |
|
253 | 253 | |
|
254 | 254 | return; |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | // cancel the option of having the tooltip to stick |
|
258 | Tooltip.prototype.cancel_stick = function() { | |
|
258 | Tooltip.prototype.cancel_stick = function () { | |
|
259 | 259 | clearTimeout(this._stick_timeout); |
|
260 | 260 | this._stick_timeout = null; |
|
261 | 261 | this._clocklink.hide('slow'); |
@@ -266,19 +266,19 var IPython = (function(IPython) { | |||
|
266 | 266 | // it won't be removed by remove_and_cancell() unless you called with |
|
267 | 267 | // the first parameter set to true. |
|
268 | 268 | // remove_and_cancell_tooltip(true) |
|
269 | Tooltip.prototype.stick = function(time) { | |
|
269 | Tooltip.prototype.stick = function (time) { | |
|
270 | 270 | time = (time != undefined) ? time : 10; |
|
271 | 271 | var that = this; |
|
272 | 272 | this._sticky = true; |
|
273 | 273 | this._clocklink.show('slow'); |
|
274 | this._stick_timeout = setTimeout(function() { | |
|
274 | this._stick_timeout = setTimeout(function () { | |
|
275 | 275 | that._sticky = false; |
|
276 | 276 | that._clocklink.hide('slow'); |
|
277 | 277 | }, time * 1000); |
|
278 | 278 | } |
|
279 | 279 | |
|
280 | 280 | // should be called with the kernel reply to actually show the tooltip |
|
281 | Tooltip.prototype.show = function(reply) { | |
|
281 | Tooltip.prototype.show = function (reply) { | |
|
282 | 282 | // move the bubble if it is not hidden |
|
283 | 283 | // otherwise fade it |
|
284 | 284 | this.name = reply.name; |
@@ -347,9 +347,9 var IPython = (function(IPython) { | |||
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | // convenient funciton to have the correct codemirror back into focus |
|
350 | Tooltip.prototype._cmfocus = function() { | |
|
350 | Tooltip.prototype._cmfocus = function () { | |
|
351 | 351 | var cm = this.code_mirror; |
|
352 | setTimeout(function() { | |
|
352 | setTimeout(function () { | |
|
353 | 353 | cm.focus(); |
|
354 | 354 | }, 50); |
|
355 | 355 | } |
General Comments 0
You need to be logged in to leave comments.
Login now