##// END OF EJS Templates
clean and comment tooltip file
Matthias BUSSONNIER -
Show More
@@ -8,19 +8,20 b''
8 8 //============================================================================
9 9 // Tooltip
10 10 //============================================================================
11
12 // Todo :
13 // use codemirror highlight example to
14 // highlight the introspection request and introspect on mouse hove ...
15 //
16 11 //
12 // you can set the autocall time by setting `IPython.notebook.time_before_tooltip` in ms
13
17 14 var IPython = (function (IPython) {
18 15
19 16 var utils = IPython.utils;
20 17
18 // tooltip constructor
21 19 var Tooltip = function (notebook) {
22 this.tooltip = $('#tooltip');
23 20 var that = this;
21
22 // handle to html
23 this.tooltip = $('#tooltip');
24 var tooltip = this.tooltip;
24 25 this._hidden = true;
25 26
26 27 // variable for consecutive call
@@ -35,16 +36,14 b' var IPython = (function (IPython) {'
35 36 this.buttons = $('<div/>')
36 37 .addClass('tooltipbuttons');
37 38
38 // will contain the docstring
39 // will contain the docstring
39 40 this.text = $('<div/>')
40 41 .addClass('tooltiptext')
41 42 .addClass('smalltooltip');
42
43 var tooltip = this.tooltip;
44 43
45 // build the buttons menu on the upper right
46
47 // expand the tooltip to see more
44 // build the buttons menu on the upper right
45
46 // expand the tooltip to see more
48 47 var expandlink=$('<a/>').attr('href',"#")
49 48 .addClass("ui-corner-all") //rounded corner
50 49 .attr('role',"button")
@@ -79,7 +78,7 b' var IPython = (function (IPython) {'
79 78 closelink.click(function(){
80 79 that.remove_and_cancel_tooltip(true);
81 80 });
82
81
83 82 //construct the tooltip
84 83 // add in the reverse order you want them to appear
85 84 this.buttons.append(closelink);
@@ -88,13 +87,16 b' var IPython = (function (IPython) {'
88 87
89 88 // we need a phony element to make the small arrow
90 89 // of the tooltip in css
91 // we could try to move the arrow later
90 // we will move the arrow later
92 91 this.arrow = $('<div/>').addClass('pretooltiparrow');
93 92 this.tooltip.append(this.buttons);
94 93 this.tooltip.append(this.arrow);
95 94 this.tooltip.append(this.text);
96 95 };
97 96
97 // will resend the request on behalf on the cell which invoked the tooltip
98 // to show in it in pager. This is done so to be sure of having the same
99 // result as invoking `something?`
98 100 Tooltip.prototype.showInPager = function()
99 101 {
100 102 var msg_id = IPython.notebook.kernel.execute(that.name+"?");
@@ -103,7 +105,7 b' var IPython = (function (IPython) {'
103 105 this._cmfocus();
104 106 }
105 107
106
108 // grow the tooltip verticaly
107 109 Tooltip.prototype.expand = function(){
108 110 this.text.removeClass('smalltooltip');
109 111 this.text.addClass('bigtooltip');
@@ -124,11 +126,6 b' var IPython = (function (IPython) {'
124 126 this._hidden = true;
125 127 }
126 128
127 //TODO, try to diminish the number of parameters.
128 Tooltip.prototype.request_tooltip_after_time = function (pre_cursor,time){
129 };
130
131
132 129 Tooltip.prototype.remove_and_cancel_tooltip = function(force) {
133 130 // note that we don't handle closing directly inside the calltip
134 131 // as in the completer, because it is not focusable, so won't
@@ -143,18 +140,22 b' var IPython = (function (IPython) {'
143 140 this._consecutive_conter = 0;
144 141 }
145 142
143 // cancel autocall done after '(' for example.
146 144 Tooltip.prototype.cancel_pending = function(){
147 145 if (this.tooltip_timeout != null){
148 146 clearTimeout(this.tooltip_timeout);
149 147 this.tooltip_timeout = null;
150 148 }
151 149 }
152
150
151 // will trigger tooltip after timeout
153 152 Tooltip.prototype.pending = function(cell,text)
154 153 {
155 154 var that = this;
156 155 this.tooltip_timeout = setTimeout(function(){that.request(cell)} , IPython.notebook.time_before_tooltip);
157 156 }
157
158 // make an imediate completion request
158 159 Tooltip.prototype.request = function(cell)
159 160 {
160 161 this.cancel_pending();
@@ -187,7 +188,7 b' var IPython = (function (IPython) {'
187 188 {
188 189 console.log('should open in pager');
189 190 this._old_cell = null ;
190 this._cancel_stick
191 this._cancel_stick();
191 192 this._old_request = null ;
192 193 this._consecutive_conter = 0;
193 194 this.showInPager();
@@ -205,26 +206,31 b' var IPython = (function (IPython) {'
205 206 }
206 207 IPython.notebook.request_tool_tip(cell, text);
207 208 }
209
210 // cancel the option of having the tooltip to stick
208 211 Tooltip.prototype.cancel_stick = function()
209 212 {
210 213 clearTimeout(this._stick_timeout);
211 214 this._sticky = false;
212 215 }
213 216
214 Tooltip.prototype.stick = function()
217 // put the tooltip in a sicky state for 10 seconds
218 // it won't be removed by remove_and_cancell() unless you called with
219 // the first parameter set to true.
220 // remove_and_cancell_tooltip(true)
221 Tooltip.prototype.stick = function()
215 222 {
216 223 console.log('tooltip will stick for at least 10 sec');
217 var that = this;
224 var that = this;
218 225 this._sticky = true;
219 226 this._stick_timeout = setTimeout( function(){
220 227 that._sticky = false;
221 228 console.log('tooltip will not stick anymore');
222 229 }, 10*1000
223 230 );
224
225
226 231 }
227 232
233 // should be called with the kernel reply to actually show the tooltip
228 234 Tooltip.prototype.show = function(reply, codecell)
229 235 {
230 236 // move the bubble if it is not hidden
@@ -242,12 +248,12 b' var IPython = (function (IPython) {'
242 248 var xinit = pos.x;
243 249 var xinter = o.left + (xinit-o.left)/w*(w-450);
244 250 var posarrowleft = xinit - xinter;
245
251
246 252
247 253 if( this._hidden == false)
248 254 {
249 255 this.tooltip.animate({'left' : xinter-30+'px','top' :(pos.yBot+10)+'px'});
250 } else
256 } else
251 257 {
252 258 this.tooltip.css({'left' : xinter-30+'px'});
253 259 this.tooltip.css({'top' :(pos.yBot+10)+'px'});
@@ -277,25 +283,15 b' var IPython = (function (IPython) {'
277 283 this.text.append(pre);
278 284 // keep scroll top to be sure to always see the first line
279 285 this.text.scrollTop(0);
280
281
282 }
283
284 Tooltip.prototype.showInPager = function(text){
285 var msg_id = IPython.notebook.kernel.execute(this.name+"?");
286 IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id;
287 this.remove_and_cancel_tooltip(true);
288 this._cmfocus();
289 286 }
290 287
288 // convenient funciton to have the correct codemirror back into focus
291 289 Tooltip.prototype._cmfocus = function()
292 290 {
293 291 var cm = this.code_mirror;
294 292 setTimeout(function(){cm.focus();}, 50);
295 293 }
296 294
297
298 295 IPython.Tooltip = Tooltip;
299
300 296 return IPython;
301 297 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now