-
Notifications
You must be signed in to change notification settings - Fork 1
/
tooltip.js
57 lines (57 loc) · 1.7 KB
/
tooltip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(function() {
var $, NRTooltip;
$ = jQuery;
$.fn.extend({
NRTooltip: function(options) {
var settings;
settings = {
delay: false,
elements: false
};
settings = $.extend(settings, options);
return this.each(function() {
return new NRTooltip(this, settings);
});
}
});
NRTooltip = (function() {
function NRTooltip(element, settings) {
var hideTip, showTip;
this.element = element;
this.settings = settings;
if ($('.NRTooltip').length === 0) {
$('body').append('<div class="NRTooltip"><span></span><div class="NRTooltip_tip"></div></div>');
}
if (this.settings.elements) {
this.elements = this.settings.elements;
$(this.element).delegate(this.elements, "mouseover", function(e) {
return showTip(e);
});
$(this.element).delegate(this.elements, "mouseout", function(e) {
return hideTip(e);
});
} else {
$(this.element).mouseover(function(e) {
return showTip(e);
});
$(this.element).mouseout(function(e) {
return hideTip(e);
});
}
showTip = function(e) {
var elem, position;
elem = $(e.target);
position = elem.offset();
$('.NRTooltip span').html($(elem).data('tooltip'));
$('.NRTooltip').addClass('visible');
position.top -= $('.NRTooltip').outerHeight() + 6;
position.left += elem.outerWidth() / 2 - $('.NRTooltip').outerWidth() / 2;
return $('.NRTooltip').offset(position);
};
hideTip = function(e) {
return $('.NRTooltip').removeClass('visible');
};
}
return NRTooltip;
})();
}).call(this);