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