##// END OF EJS Templates
comment a little
Matthias Bussonnier -
Show More
@@ -1,198 +1,205 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // Tooltip
9 // Tooltip
10 //============================================================================
10 //============================================================================
11
11
12 // Todo :
12 // Todo :
13 // use codemirror highlight example to
13 // use codemirror highlight example to
14 // highlight the introspection request and introspect on mouse hove ...
14 // highlight the introspection request and introspect on mouse hove ...
15 var IPython = (function (IPython) {
15 var IPython = (function (IPython) {
16
16
17 var utils = IPython.utils;
17 var utils = IPython.utils;
18
18
19 var Tooltip = function (notebook) {
19 var Tooltip = function (notebook) {
20 this.tooltip = $('#tooltip');
20 this.tooltip = $('#tooltip');
21
22 // contain the button in the upper right corner
21 this.buttons = $('<div/>')
23 this.buttons = $('<div/>')
22 .addClass('tooltipbuttons');
24 .addClass('tooltipbuttons');
25
26 // will contain the docstring
23 this.text = $('<div/>')
27 this.text = $('<div/>')
24 .addClass('tooltiptext')
28 .addClass('tooltiptext')
25 .addClass('smalltooltip');
29 .addClass('smalltooltip');
26 this.tooltip.css('left',50+'px');
27 this.tooltip.css('top',50+'px');
28
30
29 var tooltip = this.tooltip;
31 var tooltip = this.tooltip;
30 var text = this.text;
32 var text = this.text;
31
33
32 var expandspan=$('<span/>').text('Expand')
34 // build the buttons menu on the upper right
35
36 // expand the tooltip to see more
37 var expandspan=$('<span/>').text('Expand')
33 .addClass('ui-icon')
38 .addClass('ui-icon')
34 .addClass('ui-icon-plus');
39 .addClass('ui-icon-plus');
35 var expandlink=$('<a/>').attr('href',"#")
40 var expandlink=$('<a/>').attr('href',"#")
36 .addClass("ui-corner-all") //rounded corner
41 .addClass("ui-corner-all") //rounded corner
37 .attr('role',"button")
42 .attr('role',"button")
38 .attr('id','expanbutton')
43 .attr('id','expanbutton')
39 .append(expandspan)
44 .append(expandspan)
40 .click(function(){
45 .click(function(){
41 text.removeClass('smalltooltip');
46 text.removeClass('smalltooltip');
42 text.addClass('bigtooltip');
47 text.addClass('bigtooltip');
43 $('#expanbutton').remove();
48 $('#expanbutton').remove();
44 //setTimeout(function(){that.code_mirror.focus();}, 50);
49 //setTimeout(function(){that.code_mirror.focus();}, 50);
45 });
50 });
46
51
52 // open in pager
47 var morelink=$('<a/>').attr('href',"#");
53 var morelink=$('<a/>').attr('href',"#");
48 morelink.attr('role',"button");
54 morelink.attr('role',"button");
49 morelink.addClass('ui-button');
55 morelink.addClass('ui-button');
50 //morelink.addClass("ui-corner-all"); //rounded corner
51 //morelink.addClass('ui-state-default');
52 var morespan=$('<span/>').text('Open in Pager');
56 var morespan=$('<span/>').text('Open in Pager');
53 morespan.addClass('ui-icon');
57 morespan.addClass('ui-icon');
54 morespan.addClass('ui-icon-arrowstop-l-n');
58 morespan.addClass('ui-icon-arrowstop-l-n');
55 morelink.append(morespan);
59 morelink.append(morespan);
56 morelink.click(function(){
60 morelink.click(function(){
57 var msg_id = IPython.notebook.kernel.execute(name+"?");
61 var msg_id = IPython.notebook.kernel.execute(name+"?");
58 IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id;
62 IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id;
59 that.remove_and_cancel_tooltip();
63 that.remove_and_cancel_tooltip();
60 setTimeout(function(){that.code_mirror.focus();}, 50);
64 setTimeout(function(){that.code_mirror.focus();}, 50);
61 });
65 });
62
66
67 // close the tooltip
63 var closelink=$('<a/>').attr('href',"#");
68 var closelink=$('<a/>').attr('href',"#");
64 closelink.attr('role',"button");
69 closelink.attr('role',"button");
65 closelink.addClass('ui-button');
70 closelink.addClass('ui-button');
66 //closelink.addClass("ui-corner-all"); //rounded corner
67 //closelink.adClass('ui-state-default'); // grey background and blue cross
68 var closespan=$('<span/>').text('Close');
71 var closespan=$('<span/>').text('Close');
69 closespan.addClass('ui-icon');
72 closespan.addClass('ui-icon');
70 closespan.addClass('ui-icon-close');
73 closespan.addClass('ui-icon-close');
71 closelink.append(closespan);
74 closelink.append(closespan);
72 closelink.click(function(){
75 closelink.click(function(){
73 tooltip.addClass('hide');
76 tooltip.addClass('hide');
74 });
77 });
75 //construct the tooltip
78
79 //construct the tooltip
80 // add in the reverse order you want them to appear
76 this.buttons.append(closelink);
81 this.buttons.append(closelink);
77 this.buttons.append(expandlink);
82 this.buttons.append(expandlink);
78 this.buttons.append(morelink);
83 this.buttons.append(morelink);
79
84
85 // we need a phony element to make the small arrow
86 // of the tooltip in css
87 // we could try to move the arrow later
80 arrow = $('<div/>').addClass('pretooltiparrow');
88 arrow = $('<div/>').addClass('pretooltiparrow');
81 this.tooltip.append(arrow);
89 this.tooltip.append(arrow);
82 this.tooltip.append(this.buttons);
90 this.tooltip.append(this.buttons);
83 this.tooltip.append(this.buttons);
84 this.tooltip.append(this.text);
91 this.tooltip.append(this.text);
85 };
92 };
86
93
87
94
88
95
89 //TODO, try to diminish the number of parameters.
96 //TODO, try to diminish the number of parameters.
90 Tooltip.prototype.request_tooltip_after_time = function (pre_cursor,time){
97 Tooltip.prototype.request_tooltip_after_time = function (pre_cursor,time){
91 };
98 };
92
99
93
100
94 Tooltip.prototype.remove_and_cancel_tooltip = function() {
101 Tooltip.prototype.remove_and_cancel_tooltip = function() {
95 // note that we don't handle closing directly inside the calltip
102 // note that we don't handle closing directly inside the calltip
96 // as in the completer, because it is not focusable, so won't
103 // as in the completer, because it is not focusable, so won't
97 // get the event.
104 // get the event.
98 if (this.tooltip_timeout != null){
105 if (this.tooltip_timeout != null){
99 clearTimeout(this.tooltip_timeout);
106 clearTimeout(this.tooltip_timeout);
100 $('#tooltip').remove();
107 $('#tooltip').remove();
101 this.tooltip_timeout = null;
108 this.tooltip_timeout = null;
102 }
109 }
103 }
110 }
104 Tooltip.prototype.show = function(reply,pos)
111 Tooltip.prototype.show = function(reply,pos)
105 {
112 {
106 this.tooltip.css('left',pos.x-30+'px');
113 this.tooltip.css('left',pos.x-30+'px');
107 this.tooltip.css('top',(pos.yBot+10)+'px');
114 this.tooltip.css('top',(pos.yBot+10)+'px');
108 this.tooltip.removeClass('hidden')
115 this.tooltip.removeClass('hidden')
109 this.tooltip.removeClass('hide');
116 this.tooltip.removeClass('hide');
110
117
111 // build docstring
118 // build docstring
112 defstring = reply.call_def;
119 defstring = reply.call_def;
113 if (defstring == null) { defstring = reply.init_definition; }
120 if (defstring == null) { defstring = reply.init_definition; }
114 if (defstring == null) { defstring = reply.definition; }
121 if (defstring == null) { defstring = reply.definition; }
115
122
116 docstring = reply.call_docstring;
123 docstring = reply.call_docstring;
117 if (docstring == null) { docstring = reply.init_docstring; }
124 if (docstring == null) { docstring = reply.init_docstring; }
118 if (docstring == null) { docstring = reply.docstring; }
125 if (docstring == null) { docstring = reply.docstring; }
119 if (docstring == null) { docstring = "<empty docstring>"; }
126 if (docstring == null) { docstring = "<empty docstring>"; }
120
127
121 this.text.children().remove();
128 this.text.children().remove();
122
129
123 var pre=$('<pre/>').html(utils.fixConsole(docstring));
130 var pre=$('<pre/>').html(utils.fixConsole(docstring));
124 if(defstring){
131 if(defstring){
125 var defstring_html = $('<pre/>').html(utils.fixConsole(defstring));
132 var defstring_html = $('<pre/>').html(utils.fixConsole(defstring));
126 this.text.append(defstring_html);
133 this.text.append(defstring_html);
127 }
134 }
128 this.text.append(pre)
135 this.text.append(pre)
129
136
130
137
131 }
138 }
132
139
133 Tooltip.prototype.showInPager = function(){
140 Tooltip.prototype.showInPager = function(){
134 var msg_id = IPython.notebook.kernel.execute(name+"?");
141 var msg_id = IPython.notebook.kernel.execute(name+"?");
135 IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id;
142 IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id;
136 that.remove_and_cancel_tooltip();
143 that.remove_and_cancel_tooltip();
137 setTimeout(function(){that.code_mirror.focus();}, 50);
144 setTimeout(function(){that.code_mirror.focus();}, 50);
138 }
145 }
139
146
140 Tooltip.prototype.finish_tooltip = function (reply) {
147 Tooltip.prototype.finish_tooltip = function (reply) {
141
148
142 var expandlink=$('<a/>').attr('href',"#");
149 var expandlink=$('<a/>').attr('href',"#");
143 expandlink.addClass("ui-corner-all"); //rounded corner
150 expandlink.addClass("ui-corner-all"); //rounded corner
144 expandlink.attr('role',"button");
151 expandlink.attr('role',"button");
145
152
146 var expandspan=$('<span/>').text('Expand');
153 var expandspan=$('<span/>').text('Expand');
147 expandspan.addClass('ui-icon');
154 expandspan.addClass('ui-icon');
148 expandspan.addClass('ui-icon-plus');
155 expandspan.addClass('ui-icon-plus');
149
156
150 expandlink.append(expandspan);
157 expandlink.append(expandspan);
151 expandlink.attr('id','expanbutton');
158 expandlink.attr('id','expanbutton');
152 expandlink.click(function(){
159 expandlink.click(function(){
153 tooltip.removeClass('smalltooltip');
160 tooltip.removeClass('smalltooltip');
154 tooltip.addClass('bigtooltip');
161 tooltip.addClass('bigtooltip');
155 $('#expanbutton').remove();
162 $('#expanbutton').remove();
156 setTimeout(function(){that.code_mirror.focus();}, 50);
163 setTimeout(function(){that.code_mirror.focus();}, 50);
157 });
164 });
158
165
159 var morelink=$('<a/>').attr('href',"#");
166 var morelink=$('<a/>').attr('href',"#");
160 morelink.attr('role',"button");
167 morelink.attr('role',"button");
161 morelink.addClass('ui-button');
168 morelink.addClass('ui-button');
162 var morespan=$('<span/>').text('Open in Pager');
169 var morespan=$('<span/>').text('Open in Pager');
163 morespan.addClass('ui-icon');
170 morespan.addClass('ui-icon');
164 morespan.addClass('ui-icon-arrowstop-l-n');
171 morespan.addClass('ui-icon-arrowstop-l-n');
165 morelink.append(morespan);
172 morelink.append(morespan);
166 morelink.click(function(){
173 morelink.click(function(){
167 this.showInPager();
174 this.showInPager();
168 });
175 });
169
176
170
177
171 var closelink=$('<a/>').attr('href',"#");
178 var closelink=$('<a/>').attr('href',"#");
172 closelink.attr('role',"button");
179 closelink.attr('role',"button");
173 closelink.addClass('ui-button');
180 closelink.addClass('ui-button');
174
181
175 var closespan=$('<span/>').text('Close');
182 var closespan=$('<span/>').text('Close');
176 closespan.addClass('ui-icon');
183 closespan.addClass('ui-icon');
177 closespan.addClass('ui-icon-close');
184 closespan.addClass('ui-icon-close');
178 closelink.append(closespan);
185 closelink.append(closespan);
179 closelink.click(function(){
186 closelink.click(function(){
180 that.remove_and_cancel_tooltip();
187 that.remove_and_cancel_tooltip();
181 setTimeout(function(){that.code_mirror.focus();}, 50);
188 setTimeout(function(){that.code_mirror.focus();}, 50);
182 });
189 });
183 //construct the tooltip
190 //construct the tooltip
184 tooltip.append(closelink);
191 tooltip.append(closelink);
185 tooltip.append(expandlink);
192 tooltip.append(expandlink);
186 tooltip.append(morelink);
193 tooltip.append(morelink);
187
194
188 var pos = this.code_mirror.cursorCoords();
195 var pos = this.code_mirror.cursorCoords();
189 tooltip.css('left',pos.x+'px');
196 tooltip.css('left',pos.x+'px');
190 tooltip.css('top',pos.yBot+'px');
197 tooltip.css('top',pos.yBot+'px');
191
198
192 };
199 };
193
200
194
201
195 IPython.Tooltip = Tooltip;
202 IPython.Tooltip = Tooltip;
196
203
197 return IPython;
204 return IPython;
198 }(IPython));
205 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now