/*
jQuery Version: jQuery 1.3.2+
Plugin Name: aToolTip V 1.5
Plugin by: Ara Abcarians: http://ara-abcarians.com
License: aToolTip is licensed under a Creative Commons Attribution 3.0 Unported License
Read more about this license at --> http://creativecommons.org/licenses/by/3.0/
*/
(function ($) {
$.fn.aToolTip = function (options) {
/**
setup default settings
*/
var defaults = {
// no need to change/override
closeTipBtn: 'aToolTipCloseBtn',
toolTipId: 'aToolTip',
// ok to override
fixed: false,
clickIt: false,
inSpeed: 200,
outSpeed: 100,
tipContent: '',
toolTipClass: 'defaultTheme',
xOffset: 0,
yOffset: 0,
onShow: null,
onHide: null,
tmpHeight: 0,
tmpLeft: 0
},
// This makes it so the users custom options overrides the default ones
settings = $.extend({}, defaults, options);
return this.each(function () {
var obj = $(this);
debugger;
/**
Decide weather to use a title attr as the tooltip content
*/
if (obj.attr('title')) {
// set the tooltip content/text to be the obj title attribute
var tipContent = obj.attr('title');
} else {
// if no title attribute set it to the tipContent option in settings
var tipContent = settings.tipContent;
}
/**
Build the markup for aToolTip
*/
var buildaToolTip = function () {
var matchedWidth = 300;
$('body').append("
");
if (tipContent && settings.clickIt) {
$('#' + settings.toolTipId + ' p.aToolTipContent')
.append("close");
}
},
/**
Position aToolTip
*/
positionaToolTip = function () {
var tmp = obj.offset().top;
if (settings.tmpHeight > 0) {
tmp = settings.tmpHeight;
}
if (tmp - document.documentElement.scrollTop < $('#' + settings.toolTipId).outerHeight()) {
settings.yOffset = tmp - $('#' + settings.toolTipId).outerHeight() - document.documentElement.scrollTop - 5;
}
if (settings.tmpLeft > 0) {
$('#' + settings.toolTipId).css({
top: (tmp - $('#' + settings.toolTipId).outerHeight() - settings.yOffset) + 'px',
left: settings.tmpLeft + 'px'
})
.stop().fadeIn(settings.inSpeed, function () {
if ($.isFunction(settings.onShow)) {
settings.onShow(obj);
}
});
}
else {
$('#' + settings.toolTipId).css({
top: (tmp - $('#' + settings.toolTipId).outerHeight() - settings.yOffset) + 'px',
//top: (200) + 'px',
//left: (obj.offset().left + obj.outerWidth() + settings.xOffset) + 'px'
left: obj.offset().left + 'px'
})
.stop().fadeIn(settings.inSpeed, function () {
if ($.isFunction(settings.onShow)) {
settings.onShow(obj);
}
});
}
},
/**
Remove aToolTip
*/
removeaToolTip = function () {
// Fade out
$('#' + settings.toolTipId).stop().fadeOut(settings.outSpeed, function () {
$(this).remove();
if ($.isFunction(settings.onHide)) {
settings.onHide(obj);
}
});
};
debugger;
// Click activated aToolTip
if (tipContent && settings.clickIt) {
obj.bind('custom', function () {
$('#' + settings.toolTipId).remove();
obj.attr({ title: '' });
buildaToolTip();
positionaToolTip();
// Click to close tooltip
$('#' + settings.closeTipBtn).click(function () {
removeaToolTip();
return false;
});
return false;
});
obj.trigger('custom');
// Activate on click
/*
obj.click(function (event) {
debugger;
// remove already existing tooltip
$('#' + settings.toolTipId).remove();
obj.attr({ title: '' });
buildaToolTip();
positionaToolTip();
// Click to close tooltip
$('#' + settings.closeTipBtn).click(function () {
removeaToolTip();
return false;
});
//obj.unbind('click');
return false;
});
*/
}
}); // END: return this
};
})(jQuery);