« Blog Home

§ TinyHint (jQuery)

TinyHint

(function($) {
  $.fn.tinyHint = function (options) {
    var o = $.extend({
      topOffset: null,
      leftOffset: 20,
      fadeSpeed: '',
      hintClass: '',
      hideDelay: null,
      theHint: null
    }, options);
    var hideTimer;
    var hinter;
    var theHint = o.theHint || $('<div></div>');
    theHint = $(theHint);
    theHint.css({'display': 'none', 'position': 'absolute', 'z-index': 9999}).addClass(o.hintClass).appendTo('body');
    o.topOffset = o.topOffset || -theHint.html(' ').outerHeight();
    return this.each(function() {
      var it = $(this);
      if(it.data('hint') === undefined) {
        if(this.title && this.title.length) {
          it.data('hint', this.title);
        }
      }
      if(it.data('hint') && it.data('hint').length) {
        it.removeAttr('title');
      }
      else {
        return;
      }
      it.hover(startHint, stopHint);
    });
    function positionHint(e) {
      theHint.css({top:0,left:0}).position({
        my:'left+' + o.leftOffset + ' top+' + o.topOffset,
        of: e,
        collision:'flipfit'
      })
    }
    function startHint(e) {
      e.stopPropagation();
      clearTimeout(hideTimer);
      hinter = $(this);
      theHint.stop(true).hide().html(hinter.data('hint')).fadeIn(o.fadeSpeed);
      positionHint(e);
      hinter.on('mousemove', null, positionHint);
      hinter.on('blur', null, stopHint);
      if(o.hideDelay) {
        hideTimer = setTimeout(stopHint, o.hideDelay);
      }
    }
    function stopHint() {
      clearTimeout(hideTimer);
      hinter = $(this);
      theHint.stop(true).fadeOut(o.fadeSpeed);
      hinter.off('mousemove', null, positionHint);
      hinter.off('blur', null, stopHint);
    }
  };
}(jQuery)); //$.fn.tinyHint
$(function() {
  $('[data-edittitle]').each(function(){
    this.title = this.title || $(this).data('edittitle');
  });
  $('td').each(function(){
    if(isEllipsisActive(this)) {
      this.title = this.textContent;
    }
  })
  $('[title]').tinyHint({hintClass: 'ui-tooltip ui-widget ui-corner-all ui-widget-content', hideDelay: 3000});
})

last edited on January 11th, 2016 at 3:44 PM

Comments

No Comments Here. Add yours below!

Add your comment

Name:
Email: (Will not be displayed - Privacy policy)
Website:
Comments:
  random image I can't read it!
Give me a different one!
Verify Post: Input the text from the image above to verify this post (helps prevent spam)
 

« Blog Home


Oppuk gazed down at the creature in disgust.  Not only had it forced its barbaric name upon him, it smelled of floral aromatics, which the denizens of this world often applied to themselves in the mistaken belief that the natural scents of their bodies were noisome, while blatant artificial odors were somehow more acceptable.
Oppuk, The Course of Empire, Eric Flint & K.D. Wentworth