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