src/js/widgets/tooltipWidget.js
changeset 944 8a6c9e3d0158
parent 907 27b248a13355
parent 943 a882cc0c936f
child 945 7d9f6fd6f904
equal deleted inserted replaced
907:27b248a13355 944:8a6c9e3d0158
     1 /* this widget displays a small tooltip */
       
     2 IriSP.TooltipWidget = function(Popcorn, config, Serializer) {
       
     3   IriSP.Widget.call(this, Popcorn, config, Serializer);
       
     4   this._shown = false;
       
     5   this._displayedText = "";
       
     6   this._hideTimeout = -1;
       
     7 };
       
     8 
       
     9 
       
    10 IriSP.TooltipWidget.prototype = new IriSP.Widget();
       
    11 
       
    12 IriSP.TooltipWidget.prototype.draw = function() {
       
    13   var templ = Mustache.to_html(IriSP.tooltipWidget_template);
       
    14   // position the widget absolutely relative to document. --- NOOOO !!!!
       
    15   this.selector.css({
       
    16       "position": "absolute",
       
    17       "top": 0,
       
    18       "left": 0
       
    19   });
       
    20   this.selector.parent().css({
       
    21       "position": "relative"
       
    22   });
       
    23   this.selector.append(templ);
       
    24   var _this = this;
       
    25   this.selector.mouseover(function() {
       
    26       _this.hide();
       
    27   });
       
    28   this.hide();
       
    29 
       
    30 };
       
    31 
       
    32 IriSP.TooltipWidget.prototype.clear = function() {
       
    33 	this.selector.find(".tiptext").html("");
       
    34 };
       
    35 
       
    36 IriSP.TooltipWidget.prototype.show = function(text, color, x, y) {
       
    37 
       
    38   if (this._displayedText == text && this._shown)
       
    39     return;
       
    40 
       
    41   this.selector.find(".tipcolor").css("background-color", color);
       
    42   this._displayedText = text;
       
    43   this.selector.find(".tiptext").html(text);
       
    44   
       
    45   var _tip = this.selector.find(".tip");
       
    46   _tip.show();
       
    47   _tip.css({
       
    48       "left": Math.floor(x - _tip.outerWidth() / 2)+"px",
       
    49       "top": Math.floor(y - _tip.outerHeight())+"px"
       
    50   });
       
    51   this._shown = true;
       
    52 };
       
    53 
       
    54 IriSP.TooltipWidget.prototype.hide = function() {                                                   
       
    55   this.selector.find(".tip").hide();
       
    56   this._shown = false;  
       
    57 };