tooltip.js
168 lines
| 5.6 KiB
| application/javascript
|
JavascriptLexer
Matthias Bussonnier
|
r7145 | //---------------------------------------------------------------------------- | ||
// Copyright (C) 2008-2011 The IPython Development Team | ||||
// | ||||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
//============================================================================ | ||||
// Tooltip | ||||
//============================================================================ | ||||
Matthias BUSSONNIER
|
r7148 | // Todo : | ||
// use codemirror highlight example to | ||||
// highlight the introspection request and introspect on mouse hove ... | ||||
Matthias Bussonnier
|
r7151 | // | ||
// | ||||
Matthias Bussonnier
|
r7145 | var IPython = (function (IPython) { | ||
var utils = IPython.utils; | ||||
var Tooltip = function (notebook) { | ||||
this.tooltip = $('#tooltip'); | ||||
Matthias Bussonnier
|
r7151 | var that = this; | ||
Matthias Bussonnier
|
r7149 | |||
// contain the button in the upper right corner | ||||
Matthias BUSSONNIER
|
r7148 | this.buttons = $('<div/>') | ||
.addClass('tooltipbuttons'); | ||||
Matthias Bussonnier
|
r7149 | |||
// will contain the docstring | ||||
Matthias BUSSONNIER
|
r7147 | this.text = $('<div/>') | ||
Matthias BUSSONNIER
|
r7148 | .addClass('tooltiptext') | ||
Matthias BUSSONNIER
|
r7147 | .addClass('smalltooltip'); | ||
var tooltip = this.tooltip; | ||||
var text = this.text; | ||||
Matthias Bussonnier
|
r7149 | // build the buttons menu on the upper right | ||
// expand the tooltip to see more | ||||
Matthias BUSSONNIER
|
r7147 | var expandlink=$('<a/>').attr('href',"#") | ||
.addClass("ui-corner-all") //rounded corner | ||||
.attr('role',"button") | ||||
.attr('id','expanbutton') | ||||
.click(function(){ | ||||
text.removeClass('smalltooltip'); | ||||
text.addClass('bigtooltip'); | ||||
Matthias Bussonnier
|
r7151 | $('#expanbutton').addClass('hidden'); | ||
Matthias BUSSONNIER
|
r7147 | //setTimeout(function(){that.code_mirror.focus();}, 50); | ||
Matthias Bussonnier
|
r7150 | }) | ||
.append( | ||||
$('<span/>').text('Expand') | ||||
.addClass('ui-icon') | ||||
.addClass('ui-icon-plus') | ||||
); | ||||
Matthias BUSSONNIER
|
r7147 | |||
Matthias Bussonnier
|
r7149 | // open in pager | ||
Matthias Bussonnier
|
r7150 | var morelink=$('<a/>').attr('href',"#") | ||
.attr('role',"button") | ||||
.addClass('ui-button'); | ||||
var morespan=$('<span/>').text('Open in Pager') | ||||
.addClass('ui-icon') | ||||
.addClass('ui-icon-arrowstop-l-n'); | ||||
Matthias BUSSONNIER
|
r7147 | morelink.append(morespan); | ||
morelink.click(function(){ | ||||
var msg_id = IPython.notebook.kernel.execute(name+"?"); | ||||
IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id; | ||||
that.remove_and_cancel_tooltip(); | ||||
setTimeout(function(){that.code_mirror.focus();}, 50); | ||||
}); | ||||
Matthias Bussonnier
|
r7149 | // close the tooltip | ||
Matthias BUSSONNIER
|
r7147 | var closelink=$('<a/>').attr('href',"#"); | ||
closelink.attr('role',"button"); | ||||
closelink.addClass('ui-button'); | ||||
var closespan=$('<span/>').text('Close'); | ||||
closespan.addClass('ui-icon'); | ||||
closespan.addClass('ui-icon-close'); | ||||
closelink.append(closespan); | ||||
closelink.click(function(){ | ||||
Matthias Bussonnier
|
r7151 | that.hide(); | ||
Matthias BUSSONNIER
|
r7147 | }); | ||
Matthias Bussonnier
|
r7149 | |||
//construct the tooltip | ||||
// add in the reverse order you want them to appear | ||||
Matthias BUSSONNIER
|
r7148 | this.buttons.append(closelink); | ||
this.buttons.append(expandlink); | ||||
this.buttons.append(morelink); | ||||
Matthias Bussonnier
|
r7149 | |||
// we need a phony element to make the small arrow | ||||
// of the tooltip in css | ||||
// we could try to move the arrow later | ||||
Matthias BUSSONNIER
|
r7148 | arrow = $('<div/>').addClass('pretooltiparrow'); | ||
this.tooltip.append(arrow); | ||||
this.tooltip.append(this.buttons); | ||||
this.tooltip.append(this.text); | ||||
Matthias Bussonnier
|
r7145 | }; | ||
Matthias Bussonnier
|
r7151 | // deal with all the logic of hiding the tooltip | ||
// and reset it's status | ||||
Tooltip.prototype.hide = function() | ||||
{ | ||||
this.tooltip.addClass('hide'); | ||||
$('#expanbutton').removeClass('hidden'); | ||||
this.text.removeClass('bigtooltip'); | ||||
this.text.addClass('smalltooltip'); | ||||
// keep scroll top to be sure to always see the first line | ||||
this.text.scrollTop(0); | ||||
} | ||||
Matthias Bussonnier
|
r7145 | |||
//TODO, try to diminish the number of parameters. | ||||
Tooltip.prototype.request_tooltip_after_time = function (pre_cursor,time){ | ||||
}; | ||||
Tooltip.prototype.remove_and_cancel_tooltip = function() { | ||||
// note that we don't handle closing directly inside the calltip | ||||
// as in the completer, because it is not focusable, so won't | ||||
// get the event. | ||||
Matthias Bussonnier
|
r7151 | this.hide(); | ||
Matthias Bussonnier
|
r7145 | if (this.tooltip_timeout != null){ | ||
clearTimeout(this.tooltip_timeout); | ||||
this.tooltip_timeout = null; | ||||
} | ||||
} | ||||
Matthias Bussonnier
|
r7151 | |||
Matthias BUSSONNIER
|
r7147 | Tooltip.prototype.show = function(reply,pos) | ||
Matthias Bussonnier
|
r7145 | { | ||
Matthias Bussonnier
|
r7152 | this.tooltip.animate({'left' : pos.x-30+'px'}); | ||
this.tooltip.animate({'top' :(pos.yBot+10)+'px'}); | ||||
Matthias BUSSONNIER
|
r7148 | this.tooltip.removeClass('hidden') | ||
this.tooltip.removeClass('hide'); | ||||
Matthias BUSSONNIER
|
r7147 | |||
// build docstring | ||||
defstring = reply.call_def; | ||||
if (defstring == null) { defstring = reply.init_definition; } | ||||
if (defstring == null) { defstring = reply.definition; } | ||||
docstring = reply.call_docstring; | ||||
if (docstring == null) { docstring = reply.init_docstring; } | ||||
if (docstring == null) { docstring = reply.docstring; } | ||||
if (docstring == null) { docstring = "<empty docstring>"; } | ||||
this.text.children().remove(); | ||||
var pre=$('<pre/>').html(utils.fixConsole(docstring)); | ||||
if(defstring){ | ||||
var defstring_html = $('<pre/>').html(utils.fixConsole(defstring)); | ||||
this.text.append(defstring_html); | ||||
} | ||||
Matthias Bussonnier
|
r7151 | this.text.append(pre); | ||
// keep scroll top to be sure to always see the first line | ||||
this.text.scrollTop(0); | ||||
Matthias BUSSONNIER
|
r7147 | |||
Matthias Bussonnier
|
r7145 | } | ||
Tooltip.prototype.showInPager = function(){ | ||||
var msg_id = IPython.notebook.kernel.execute(name+"?"); | ||||
IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id; | ||||
that.remove_and_cancel_tooltip(); | ||||
setTimeout(function(){that.code_mirror.focus();}, 50); | ||||
} | ||||
IPython.Tooltip = Tooltip; | ||||
return IPython; | ||||
}(IPython)); | ||||