Skip to content

Instantly share code, notes, and snippets.

@xfenix
Created June 1, 2012 09:04
Show Gist options
  • Save xfenix/2850559 to your computer and use it in GitHub Desktop.
Save xfenix/2850559 to your computer and use it in GitHub Desktop.
Shitty jquery tooltip, aTooltip based, update soon (never?)
(function($) {
$.fn.myTooltip = function(options) {
/**
setup default settings
*/
var defaults = {
closeTipBtn: 'aToolTipClose',
closeTipBtnClass: 'tooltip-close',
toolTipId: 'aToolTip',
toolTipClass: 'tooltip',
toolTipClassIn: 'tooltip-in',
fixed: false,
clickIt: true,
inSpeed: 200,
outSpeed: 100,
tipContent: '',
xOffset: 5,
yOffset: 5,
onShow: null,
onHide: null
},
// This makes it so the users custom options overrides the default ones
settings = $.extend({}, defaults, options),
createTip = function(el) {
id = $('#' + id);
if(id.length != 0) {
id.show();
return false;
}
var cnt = el.attr('title'),
time = new Date().getTime(),
off = el.offset(),
offn = null,
id = 'd' + time + Math.round(Math.random()*1000),
div = $('<div>').addClass(settings.toolTipClass).attr('id', id)
.append( $('<a>').addClass(settings.closeTipBtnClass) )
.append( $('<div>').addClass(settings.toolTipClassIn).html(cnt) ),
divIn = div.find('.in'),
left = 0,
top = 0;
divIn.html(cnt);
$('body').prepend(div);
div = $('#' + id);
div.css({
top: off.top - div.outerHeight(true) + settings.yOffset + 'px',
left: off.left - (div.outerWidth(true)/2) + (el.outerWidth(true)/2) + 'px'
}).fadeIn();
el.attr('rel', '');
return div;
};
this.each(function() {
var obj = $(this);
obj.click(function() {
var div = createTip($(this));
//div.remove();
return false;
});
});
$('.' + settings.closeTipBtnClass).live('click', function() {
$(this).parent().fadeOut();
});
$(window).resize(function() {
$('.' + settings.toolTipClass).hide();
});
return createTip;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment