src/js/widgets/tooltipWidget.js
author hamidouk
Mon, 19 Dec 2011 10:53:34 +0100
branchpopcorn-port
changeset 477 1e51d638e7ea
parent 474 c1998d5d552e
child 478 1422ba0fc333
permissions -rw-r--r--
fixes in a rush.

/* this widget displays a small tooltip */
IriSP.TooltipWidget = function(Popcorn, config, Serializer) {
  IriSP.Widget.call(this, Popcorn, config, Serializer);
  this._shown = false;
  this._displayedText = "";
  this._hideTimeout = -1;
};


IriSP.TooltipWidget.prototype = new IriSP.Widget();

IriSP.TooltipWidget.prototype.draw = function() {
  var templ = Mustache.to_html(IriSP.tooltipWidget_template);

  this.selector.append(templ);
  this.hide();

};

IriSP.TooltipWidget.prototype.clear = function() {
	this.selector.find(".tiptext").text("");
};

IriSP.TooltipWidget.prototype.show = function(text, color, x, y) {
  if (this._shown === true || this._displayedText == text)
    return;
    
  // cancel the timeout for the previously displayed element.
  if (this._hideTimeout != -1) {
    window.clearTimeout(this._hideTimeout);
    this._hideTimeout = -1;
    console.log(text === this._displayedText);
  }
  debugger;
  
  this.selector.find(".tipcolor").css("background-color", color);
  this._displayedText = text;
	this.selector.find(".tiptext").text(text);
  //this.selector.find(".tip").css("left", x).css("top", y);  
  this.selector.find(".tip").css("left", x).css("top", "-160px");
  this.selector.find(".tip").show();
  this._shown = true;
};

IriSP.TooltipWidget.prototype.hide = function() {  
  this._hideTimeout = window.setTimeout(IriSP.wrap(this, function() {                                                  
                                                  this.selector.find(".tip").hide();
                                                  this._shown = false; }), 1000);
  
};